from base import * from utils import * import struct __all__ = [ 'rMenuBar', 'rMenu', 'rMenuItem', 'UndoMenuItem', 'CutMenuItem', 'CopyMenuItem', 'PasteMenuItem', 'ClearMenuItem', 'CloseMenuItem', 'DividerMenuItem' ] # see: # Programmer's Reference for System 6 (Ch 13 Menu Manager Update, pg 103+) # TB Vol 3 Chapter 37 # TB Vol 1 Chapter 13 # TODO - menu item icon support (system 6) rItemStruct # A menu ID must be unique for each menu; that is, no two menus # can have the same ID or the system will fall. Similarly, no two # items can have the same Item ID. _menu_ids = {} _menu_item_ids = {} def _to_char_string(x): if not x: return '""' if x == 0x0d: return "\\n" # intentionally backwards if x == 0x0a: return "\\r" # if chr(x) in "\\\\'" : return "\\" + x if x >= 32 and x < 0x7e: return '"' + chr(x) + '"' return "\\${:02x}".format(x) class rMenuBar(rObject): rName = "rMenuBar" rType = 0x8008 def __init__(self, *children, id=None, attr=None): super().__init__(id, attr) self.children = children[:] for x in children: if not isinstance(x, rMenu): raise TypeError("bad type: {}".format(type(x))) def __bytes__(self): bb = struct.pack("= 1: self.itemChar = bb[0] self.altItemChar = bb[0] # upper to lower? if len(bb) >= 2: self.altItemChar = bb[1] if len(bb) > 2: raise ValueError("keys too long: {}".format(keys)) def __bytes__(self): itemID = self.itemID if itemID == None: itemID = self.get_id() bb = struct.pack("