import struct import enum from . base import * from . utils import * from . icon import rIcon __all__ = [ 'rMenuBar', 'rMenu', 'rMenuItem', 'rItemStruct', 'UndoMenuItem', 'CutMenuItem', 'CopyMenuItem', 'PasteMenuItem', 'ClearMenuItem', 'CloseMenuItem', '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 # TB Vol 1 Chapter 13 # 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 = {} # ref is resource flag for the text is stored in the menu item flags # icon could be null but in that case, why are you using an rItemStruct???? class rItemStruct(rObject): rName = "rItemStruct" rType = 0x8028 def __init__(self, text, icon, **kwargs): super().__init__(**kwargs) self.text = rPString.make_string(text) if type(icon) != rIcon: raise TypeError("rItemStruct: bad icon type: {}".format(type(icon))) self.icon = icon def __bytes__(self): return 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("