from base import rObject, rList, rPString, rTextForLETextBox2 import struct from rect import * from colors import * from utils import * __all__ = [ "rControlTemplate", "rControlList", "rSimpleButton", "rCheckControl", "rRadioControl", "rThermometerControl", "rRectangleControl", "rStatTextControl" ] # /*-------------------------------------------------------*/ # /* Control List Descriptors # /*-------------------------------------------------------*/ # #define singlePtr $0000 # #define singleHandle $0001 # #define singleResource $0002 # #define ptrToPtr $0003 # #define ptrToHandle $0004 # #define ptrToResource $0005 # #define handleToPtr $0006 # #define handleToHandle $0007 # #define handleToResource $0008 # #define ResourceToResource $0009 # # /*-------------------------------------------------------*/ # /* Common Flag equates. # /*-------------------------------------------------------*/ # #define ctlInvis $0080 # #define ctlVisible $0000 # #Define CtlInactive $FF00 # # # /*-------------------------------------------------------*/ # /* Common MoreFlags equates. # /*-------------------------------------------------------*/ # #define FctlTarget $8000 # #define FctlCanBeTarget $4000 # #define FctlWantsEvents $2000 # #define FCtlWantEvents $2000 /* spelling variant */ # #define FctlProcNotPtr $1000 # #define FctlTellAboutSize $0800 # #define FctlIsMultiPart $0400 class rControlTemplate(rObject): rName = "rControlTemplate" rType = 0x8004 procRef = None # TODO - Colors # # color table (TB V1 Ch 4-87): # word outline # word background when not selected # word background when selected # word title when selected # word title when not selected class rSimpleButton(rControlTemplate): rName = "rControlTemplate" rType = 0x8004 procRef = 0x80000000 # /*-------------------------------------------------------*/ # /* Flag equates for simple buttons. # /*-------------------------------------------------------*/ # #Define NormalButton $0000 # #Define DefaultButton $0001 # #Define SquareButton $0002 # #Define SquareShadowButton $0003 def __init__(self, rect, title, *, flags = 0x0000, moreFlags = 0x0000, refCon = 0x00000000, controlID=None, **kwargs): super().__init__(**kwargs) if kwargs.get("invisible"): flags |= 0x0080 if kwargs.get("inactive"): flags |= 0xff00 if kwargs.get("default"): flags |= 0x0001 if kwargs.get("square"): flags |= 0x0002 if kwargs.get("keys"): moreFlags |= 0x2000 # fCtlWantEvents moreFlags |= 0x1000 # fCtlProcNotPtr # if color: # moreFlags |= 0x08 # color table is resource id if title: moreFlags |= 0x02 # title is resource id self.title = rPString.make_string(title) self.flags = flags self.moreFlags = moreFlags self.rect = rect self.refCon = refCon self.controlID = controlID def __bytes__(self): # pcount, id:4, rect, procref:4, flags, moreFlags, refcon, title, color table, keys controlID = self.controlID if controlID == None: controlID = self.get_id() bb = struct.pack("