strings - join multiple arguments (so bytes and text can be passed in together)

This commit is contained in:
Kelvin Sherlock 2020-08-02 13:40:32 -04:00
parent c4c833c898
commit b6cf8f1a76
2 changed files with 18 additions and 4 deletions

11
base.py
View File

@ -325,11 +325,13 @@ class rTextObject(rObject):
def __init__(self, text, **kwargs): # id=None, attr=None):
def __init__(self, *text, **kwargs): # id=None, attr=None):
super().__init__(**kwargs) # id=id, attr=attr
# text is a string or bytes.
# bytes is assumed to be macroman
self.text = str_to_bytes(text)
# self.text = str_to_bytes(text)
self.text = b"".join([str_to_bytes(x) for x in text])
def __len__(self):
return len(self.text)
@ -356,6 +358,9 @@ class rTextForLETextBox2(rTextObject):
rName = "rTextForLETextBox2"
rType = 0x800b
# TODO - rAlertString and rError string are
# both formatted c-strings used by AlertWindow.
# see TB 3 52-6. size, optional icon, text, buttons.
class rAlertString(rTextObject):
rName = "rAlertString"
rType = 0x8015
@ -411,7 +416,7 @@ class rStringList(rObject):
self.children = [str_to_bytes(x) for x in strings]
def __bytes__(self):
bb = struct.pack("<H", len(self._strings))
bb = struct.pack("<H", len(self.children))
for x in self.children:
bb += bytes( [len(x)] ) # pstring
bb += x

View File

@ -9,7 +9,14 @@
rText("rText")
rTextBlock(b"rTextBlock") # bytes
rTextForLETextBox2("rTextForLETextBox2")
rTextForLETextBox2(
TBStylePlain,
"rTextForLETextBox2",
TBStyleBold, TBCenterJust,
b"rTextForLETextBox2",
)
rAlertString("rAlertString")
rErrorString("rErrorString")
@ -26,3 +33,5 @@ rWString("rWString")
rC1InputString("rC1InputString")
rStringList('rStringList', b"rStringList", r"rStringList")