mirror of
https://github.com/ksherlock/prez.git
synced 2024-11-29 19:49:17 +00:00
thermometer control
This commit is contained in:
parent
03789d7d51
commit
64417ace4d
36
base.py
36
base.py
@ -28,7 +28,7 @@ class rObject:
|
||||
_rmap = {}
|
||||
_resources = {}
|
||||
|
||||
# also a define=proeprty to trigger export in equ file?
|
||||
# also a define=property to trigger export in equ file?
|
||||
def __init__(self, id=None, attr=None):
|
||||
rType = self.rType
|
||||
self.id = id
|
||||
@ -109,8 +109,12 @@ class rObject:
|
||||
for rType,rList in rObject._resources.items():
|
||||
for r in rList:
|
||||
bb = bytes(r)
|
||||
|
||||
data = [bb[x*16:x*16+16] for x in range(0, len(bb)+15>>4)]
|
||||
|
||||
print("{}(${:08x}) {{".format(r.rName, r.get_id()))
|
||||
print("\t$\"" + bb.hex() + "\"")
|
||||
for x in data:
|
||||
print("\t$\"" + x.hex() + "\"")
|
||||
print("}\n")
|
||||
|
||||
@staticmethod
|
||||
@ -123,7 +127,35 @@ class rObject:
|
||||
print(content)
|
||||
print("}\n")
|
||||
|
||||
# container for a 0-terminated list of resource ids.
|
||||
|
||||
class rList(rObject):
|
||||
def __init__(self, *children, id=None, attr=None):
|
||||
super().__init__(id=id, attr=attr)
|
||||
self.children = children
|
||||
tt = self.rChildType
|
||||
for x in self.children:
|
||||
if not isinstance(x, tt):
|
||||
raise TypeError("bad type: {}".format(type(x)))
|
||||
|
||||
def __bytes__(self):
|
||||
bb = bytearray(4 + len(self.children))
|
||||
offset = 0
|
||||
for x in self.children:
|
||||
struct.pack_into("<I", bb, offset, x.get_id())
|
||||
offset += 4
|
||||
return bytes(bb)
|
||||
|
||||
def _rez_string(self):
|
||||
if not self.children: return "\t{}"
|
||||
rv = "\t{\n"
|
||||
|
||||
ids = [x.get_id() for x in self.children]
|
||||
|
||||
rv += ",\n".join(["\t\t${:08x}".format(x) for x in ids])
|
||||
|
||||
rv += "\n\t}"
|
||||
return rv
|
||||
|
||||
class rTextObject(rObject):
|
||||
def __init__(self, text, *, id=None, attr=None):
|
||||
|
110
control.py
110
control.py
@ -4,23 +4,7 @@ from rect import *
|
||||
|
||||
|
||||
|
||||
class rControlList(rObject):
|
||||
rName = "rControlList"
|
||||
rType = 0x8003
|
||||
|
||||
def __init__(self, children, *, id=None, attr=None):
|
||||
super().__init__(id, attr)
|
||||
self.children = children[:]
|
||||
for x in children:
|
||||
if not isinstance(x, rControlTemplate):
|
||||
raise TypeError("bad type: {}".format(type(x)))
|
||||
|
||||
def __bytes__(self):
|
||||
bb = b""
|
||||
for x in self.children:
|
||||
bb += struct.pack("<I", x.get_id())
|
||||
bb += "\x00\x00\x00\x00" # 0-terminate
|
||||
return bb
|
||||
|
||||
# /*-------------------------------------------------------*/
|
||||
# /* Control List Descriptors
|
||||
@ -124,7 +108,7 @@ class rSimpleButton(rControlTemplate):
|
||||
if controlID == None: controlID = self.get_id()
|
||||
|
||||
rv = (
|
||||
"\t${:04x}, /* control ID */\n"
|
||||
"\t${:08x}, /* control ID */\n"
|
||||
"\t{{ {:d}, {:d}, {:d}, {:d} }}, /* rect */\n"
|
||||
"\tSimpleButtonControl {{\n"
|
||||
"\t\t${:04x}, /* flags */\n"
|
||||
@ -206,7 +190,7 @@ class rCheckControl(rControlTemplate):
|
||||
if controlID == None: controlID = self.get_id()
|
||||
|
||||
rv = (
|
||||
"\t${:04x}, /* control ID */\n"
|
||||
"\t${:08x}, /* control ID */\n"
|
||||
"\t{{ {:d}, {:d}, {:d}, {:d} }}, /* rect */\n"
|
||||
"\tCheckControl {{\n"
|
||||
"\t\t${:04x}, /* flags */\n"
|
||||
@ -293,7 +277,7 @@ class rRadioControl(rControlTemplate):
|
||||
if controlID == None: controlID = self.get_id()
|
||||
|
||||
rv = (
|
||||
"\t${:04x}, /* control ID */\n"
|
||||
"\t${:08x}, /* control ID */\n"
|
||||
"\t{{ {:d}, {:d}, {:d}, {:d} }}, /* rect */\n"
|
||||
"\tRadioControl {{\n"
|
||||
"\t\t${:04x}, /* flags */\n"
|
||||
@ -315,3 +299,91 @@ class rRadioControl(rControlTemplate):
|
||||
0
|
||||
)
|
||||
return rv
|
||||
|
||||
|
||||
class rThermometerControl(rControlTemplate):
|
||||
rName = "rControlTemplate"
|
||||
rType = 0x8004
|
||||
|
||||
def __init__(self, rect, *,
|
||||
id=None, attr=None,
|
||||
flags = 0x0000, moreFlags = 0x0000,
|
||||
refCon = 0x00000000, controlID=None,
|
||||
value=0,
|
||||
scale=0,
|
||||
horizontal=False,
|
||||
invisible=False, inactive=False
|
||||
):
|
||||
super().__init__(id, attr)
|
||||
|
||||
if invisible: flags |= 0x0080 # ?
|
||||
if inactive: flags |= 0xff00 # ?
|
||||
if horizontal: flags |= 0x0001
|
||||
|
||||
moreFlags |= 0x1000 # fCtlProcNotPtr
|
||||
|
||||
# if color:
|
||||
# moreFlags |= 0x08 # color table is resource id
|
||||
|
||||
|
||||
self.flags = flags
|
||||
self.moreFlags = moreFlags
|
||||
self.rect = rect
|
||||
self.refCon = refCon
|
||||
self.controlID = controlID
|
||||
self.value = value
|
||||
self.scale = scale
|
||||
|
||||
|
||||
def __bytes__(self):
|
||||
|
||||
controlID = self.controlID
|
||||
if controlID == None: controlID = self.get_id()
|
||||
bb = struct.pack("<HI4HIHHIHHI",
|
||||
9, # pcount
|
||||
controlID,
|
||||
*self.rect,
|
||||
0x87FF0002, # procref
|
||||
self.flags,
|
||||
self.moreFlags,
|
||||
self.refCon,
|
||||
self.value,
|
||||
self.scale,
|
||||
0, # color table
|
||||
)
|
||||
return bb
|
||||
|
||||
def _rez_string(self):
|
||||
|
||||
controlID = self.controlID
|
||||
if controlID == None: controlID = self.get_id()
|
||||
|
||||
rv = (
|
||||
"\t${:08x}, /* control ID */\n"
|
||||
"\t{{ {:d}, {:d}, {:d}, {:d} }}, /* rect */\n"
|
||||
"\tThermometerControl {{\n"
|
||||
"\t\t${:04x}, /* flags */\n"
|
||||
"\t\t${:04x}, /* more flags */\n"
|
||||
"\t\t${:08x}, /* refcon */\n"
|
||||
"\t\t${:04x}, /* value */\n"
|
||||
"\t\t${:04x}, /* scale */\n"
|
||||
"\t\t${:08x} /* color table ref */\n"
|
||||
# "\t\t${}, /* key equiv */\n"
|
||||
"\t}}"
|
||||
).format(
|
||||
controlID,
|
||||
*self.rect,
|
||||
self.flags,
|
||||
self.moreFlags,
|
||||
self.refCon,
|
||||
self.value,
|
||||
self.scale,
|
||||
0
|
||||
)
|
||||
return rv
|
||||
|
||||
|
||||
class rControlList(rList):
|
||||
rName = "rControlList"
|
||||
rType = 0x8003
|
||||
rChildType = rControlTemplate
|
||||
|
2
menu.py
2
menu.py
@ -188,7 +188,7 @@ class rMenuItem(rObject):
|
||||
"\t{}, {}, /* chars */\n"
|
||||
"\t${:04x}, /* check */\n"
|
||||
"\t${:04x}, /* flags */\n"
|
||||
"\t${:04x} /* title ref */\n"
|
||||
"\t${:04x} /* title ref */"
|
||||
).format(
|
||||
itemID,
|
||||
to_char_string(self.itemChar),
|
||||
|
Loading…
Reference in New Issue
Block a user