diff --git a/base.py b/base.py index 59d9066..6d1ce60 100644 --- a/base.py +++ b/base.py @@ -215,7 +215,7 @@ class rObject: r.rName, r.get_id(), r._format_attr() ), file=io) print(content, file=io) - print("}\n", file=io) + print("};\n", file=io) @staticmethod diff --git a/constants.py b/constants.py index c6a33f8..013936d 100644 --- a/constants.py +++ b/constants.py @@ -35,24 +35,6 @@ fAlert = 0x2000 fClose = 0x4000 fTitle = 0x8000 -# menu item flags (duplicate menu flags.) -rMIPlain = 0x0000 -rMIBold = 0x0001 -rMIItalic = 0x0002 -rMIUnderline = 0x0004 -rMIXOr = 0x0020 -rMIDivider = 0x0040 -rMIDisabled = 0x0080 -rMIItemStruct = 0x0400 -rMIOutline = 0x0800 -rMIShadow = 0x1000 - -# menu flags -rmAllowCache = 0x0008 -rmCustom = 0x0010 -rmNo_Xor = 0x0020 -rmDisabled = 0x0080 - # common flags ctlInvis = 0x0080 @@ -139,3 +121,4 @@ TBVenice = b"\x05\x00" TBTimes = b"\x14\x00" TBHelvetica = b"\x15\x00" TBCourier = b"\x16\x00" + diff --git a/control.py b/control.py index b91f856..99841ac 100644 --- a/control.py +++ b/control.py @@ -57,6 +57,51 @@ class rControlTemplate(rObject): # word background when selected # word title when selected # word title when not selected +class rSimpleButtonColors(rObject): + rName = "rCtlColorTbl" + rType = 0x800D + + def __init__(self, *, + outline=Black, + background=White, + backgroundSelected=Black, + # textBackground should usually match the background color. + text=Black, + textBackground=None, + textSelected=White, + textSelectedBackground=None, + **kwargs): + super().__init__(**kwargs) + + data = [0, 0, 0, 0, 0] + + if textBackground == None: textBackground = background + if textSelectedBackground == None: textSelectedBackground = backgroundSelected + + data[0] = outline.value << 4 + data[1] = background.value << 4 + data[2] = backgroundSelected.value << 4 + data[3] = text.value | (textBackground.value << 4) + data[4] = textSelected.value | (textSeletectBackground.value << 4) + + self.data = data + + + + def __bytes__(self): + return struct.pack("<5H", *self.data) + def _rez_string(self): + return( + "\t0x{:04x}, /* outline color */\n" + "\t0x{:04x}, /* interior color */\n" + "\t0x{:04x}, /* interior selected color */\n" + "\t0x{:04x}, /* text color */\n" + "\t0x{:04x} /* text selected color */\n" + ).format(*self.data) + + + + class rSimpleButton(rControlTemplate): rName = "rControlTemplate" @@ -151,7 +196,50 @@ class rSimpleButton(rControlTemplate): # word reserved # word box not selected # word box checked -# word title +# word title + +class rCheckControlColors(rObject): + rName = "rCtlColorTbl" + rType = 0x800D + + def __init__(self, *, + background=White, + foreground=Black, + backgroundSelected=Black, + foregroundSelected=White, + text=Black, + textBackground=White, + **kwargs): + super().__init__(**kwargs) + + data = [0, 0, 0, 0,] + + if textBackground == None: textBackground = background + if textSelectedBackground == None: textSelectedBackground = backgroundSelected + + + data[1] = foreground.value | (background.value << 4) + data[2] = foregroundSelected.value | (backgroundSelected.value << 4) + data[3] = text.value | (textBackground.value << 4) + + self.data = data + + + + def __bytes__(self): + return struct.pack("<4H", *self.data) + def _rez_string(self): + return( + "\t0x{:04x}, /* reserved */\n" + "\t0x{:04x}, /* check box */\n" + "\t0x{:04x}, /* check box (selected) */\n" + "\t0x{:04x}, /* text */\n" + ).format(*self.data) + + +# same format +rRadioControlColors = rCheckControlColors + class rCheckControl(rControlTemplate): rName = "rControlTemplate" rType = 0x8004 @@ -237,6 +325,9 @@ class rCheckControl(rControlTemplate): ) return rv + + + # TODO - colors # color table (TB V1 Ch 4-88): # word reserved diff --git a/icon.py b/icon.py index a096186..66e0817 100644 --- a/icon.py +++ b/icon.py @@ -78,9 +78,9 @@ class rIcon(rObject): "\t{:d}, /* height */\n" "\t{:d}, /* width */\n" ).format(self.type, self.height, self.width) - s += "\n\t/*image */\n" + s += "\n\t/* image */\n" s += rez_hex(self.image, width = self.width // 2, indent = 1, comma = True) - s += "\n\t/*mask */\n" + s += "\n\t/* mask */\n" s += rez_hex(self.mask, width = self.width // 2, indent = 1, comma = False) return s diff --git a/key_equivalent.py b/key_equivalent.py index 3528b89..102429f 100644 --- a/key_equivalent.py +++ b/key_equivalent.py @@ -3,7 +3,7 @@ import enum from utils import * import struct -__all__ = ["KeyEquiv"] +__all__ = ["KeyEquivalent"] def export_enum(cls): global __all__ diff --git a/menu.py b/menu.py index ef442e6..f8350b5 100644 --- a/menu.py +++ b/menu.py @@ -3,6 +3,7 @@ from base import * from utils import * from icon import rIcon import struct +import enum __all__ = [ 'rMenuBar', @@ -19,6 +20,37 @@ __all__ = [ 'DividerMenuItem' ] + +def export_enum(cls): + global __all__ + + members = cls.__members__ + globals().update(members) + if __all__ != None: __all__.extend(list(members)) + return cls + +@export_enum +class MenuFlags(enum.Flag): + # menu item flags (duplicate menu flags.) + mPlain = 0x0000 + mBold = 0x0001 + mItalic = 0x0002 + mUnderline = 0x0004 + mXOR = 0x0020 + mDivider = 0x0040 + mDisabled = 0x0080 + # menuIItemStruct = 0x0400 + mOutline = 0x0800 + mShadow = 0x1000 + + # menu flags + mAllowCache = 0x0008 + mCustom = 0x0010 + # rmNo_Xor = 0x0020 + # rmDisabled = 0x0080 + + + # see: # Programmer's Reference for System 6 (Ch 13 Menu Manager Update, pg 103+) # TB Vol 3 Chapter 37 @@ -73,10 +105,13 @@ class rMenuBar(rObject): def __init__(self, *children, **kwargs): super().__init__(**kwargs) - self.children = children[:] + for x in children: if not isinstance(x, rMenu): - raise TypeError("bad type: {}".format(type(x))) + raise TypeError("rMenuBar: bad type: {}".format(type(x))) + + self.children = children + def __bytes__(self): bb = struct.pack(" 126 } - map[0x0d] = "\\n" # intentionally backwards. - map[0x0a] = "\\r" # intentionally backwards. + map[0x0d] = "\\r" # intentionally backwards. -- no more + map[0x0a] = "\\n" # intentionally backwards. -- no more map[0x09] = "\\t" # \b \f \v \? also supported. map[ord('"')] = '\\"'