mirror of
https://github.com/ksherlock/prez.git
synced 2025-02-22 05:29:05 +00:00
adjust rObject constructor parameters
This commit is contained in:
parent
8721ce4141
commit
b9bc4a32e5
101
base.py
101
base.py
@ -3,6 +3,8 @@ from bisect import bisect_left
|
|||||||
from rect import *
|
from rect import *
|
||||||
from utils import *
|
from utils import *
|
||||||
|
|
||||||
|
from constants import *
|
||||||
|
|
||||||
__all__ = ["rObject", "rText", "rTextBlock", "rTextForLETextBox2",
|
__all__ = ["rObject", "rText", "rTextBlock", "rTextForLETextBox2",
|
||||||
"rAlertString", "rErrorString", "rComment", "rPString",
|
"rAlertString", "rErrorString", "rComment", "rPString",
|
||||||
"rCString", "rWString", "rC1InputString", "rStringList",
|
"rCString", "rWString", "rC1InputString", "rStringList",
|
||||||
@ -21,17 +23,42 @@ class rObject:
|
|||||||
_resources = {}
|
_resources = {}
|
||||||
_rnames = {}
|
_rnames = {}
|
||||||
|
|
||||||
# also a define=property to trigger export in equ file?
|
def __init__(self, id=None, attr=0, **kwargs):
|
||||||
def __init__(self, id=None, attr=None):
|
|
||||||
rType = self.rType
|
rType = self.rType
|
||||||
self.id = id
|
|
||||||
self.attr = attr
|
|
||||||
|
if kwargs.get("attrPage", False): attr |= attrPage
|
||||||
|
if kwargs.get("attrNoSpec", False): attr |= attrNoSpec
|
||||||
|
if kwargs.get("attrNoCross", False): attr |= attrNoCross
|
||||||
|
if kwargs.get("resPreLoad", False): attr |= resPreLoad
|
||||||
|
if kwargs.get("resProtected", False): attr |= resProtected
|
||||||
|
if kwargs.get("attrPurge1", False): attr |= attrPurge1
|
||||||
|
if kwargs.get("attrPurge2", False): attr |= attrPurge2
|
||||||
|
if kwargs.get("attrPurge3", False): attr |= attrPurge3
|
||||||
|
if kwargs.get("resAbsLoad", False): attr |= resAbsLoad
|
||||||
|
if kwargs.get("resConverter", False): attr |= resConverter
|
||||||
|
if kwargs.get("attrFixed", False): attr |= attrFixed
|
||||||
|
if kwargs.get("attrLocked", False): attr |= attrLocked
|
||||||
|
|
||||||
|
if kwargs.get("attrPurge", False): attr |= attrPurge
|
||||||
|
|
||||||
|
self._id = id
|
||||||
|
self._attr = attr
|
||||||
|
|
||||||
self._export = None
|
self._export = None
|
||||||
self._name = None
|
self._name = None
|
||||||
|
|
||||||
self._check_id(rType, id)
|
self._check_id()
|
||||||
|
|
||||||
def _check_id(self, rType, rID):
|
if "export" in kwargs: self._export = kwargs["export"]
|
||||||
|
if "name" in kwargs:
|
||||||
|
self.name(kwargs["name"])
|
||||||
|
|
||||||
|
|
||||||
|
def _check_id(self):
|
||||||
|
|
||||||
|
rType = self.rType
|
||||||
|
rID = self._id
|
||||||
|
|
||||||
if rType in self._resources:
|
if rType in self._resources:
|
||||||
xx = self._resources[rType]
|
xx = self._resources[rType]
|
||||||
@ -71,8 +98,15 @@ class rObject:
|
|||||||
self._export = name
|
self._export = name
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
# .attr(attrNoSpec, attrLocked, attrFixed)
|
||||||
|
# .attr(attrNoSpec + attrLocked + attrFixed)
|
||||||
|
def attr(self, *attrs):
|
||||||
|
for x in attrs:
|
||||||
|
self._attr |= x
|
||||||
|
return self
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
rID = self.id
|
rID = self._id
|
||||||
rType = self.rType
|
rType = self.rType
|
||||||
if type(rID) == int: return rID
|
if type(rID) == int: return rID
|
||||||
|
|
||||||
@ -128,6 +162,24 @@ class rObject:
|
|||||||
if r._export:
|
if r._export:
|
||||||
print(fmt.format(r._export, r.get_id()))
|
print(fmt.format(r._export, r.get_id()))
|
||||||
|
|
||||||
|
def _format_attr(self):
|
||||||
|
attr = self._attr
|
||||||
|
if not attr: return ""
|
||||||
|
opts = [""]
|
||||||
|
if attr & attrPage: opts.append("attrPage")
|
||||||
|
if attr & attrNoSpec: opts.append("attrNoSpec")
|
||||||
|
if attr & attrNoCross: opts.append("attrNoCross")
|
||||||
|
if attr & resPreLoad: opts.append("resPreLoad")
|
||||||
|
if attr & resProtected: opts.append("resProtected")
|
||||||
|
if attr & attrPurge1: opts.append("attrPurge1")
|
||||||
|
if attr & attrPurge2: opts.append("attrPurge2")
|
||||||
|
if attr & attrPurge3: opts.append("attrPurge3")
|
||||||
|
if attr & resAbsLoad: opts.append("resAbsLoad")
|
||||||
|
if attr & resConverter: opts.append("resConverter")
|
||||||
|
if attr & attrFixed: opts.append("attrFixed")
|
||||||
|
if attr & attrLocked: opts.append("attrLocked")
|
||||||
|
return ", ".join(opts)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def dump():
|
def dump():
|
||||||
for rType,rList in rObject._resources.items():
|
for rType,rList in rObject._resources.items():
|
||||||
@ -143,7 +195,9 @@ class rObject:
|
|||||||
|
|
||||||
data = [bb[x*16:x*16+16] for x in range(0, len(bb)+15>>4)]
|
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("{}(${:08x}{}) {{".format(
|
||||||
|
r.rName, r.get_id(), r._format_attr()
|
||||||
|
))
|
||||||
for x in data:
|
for x in data:
|
||||||
print("\t$\"" + x.hex() + "\"")
|
print("\t$\"" + x.hex() + "\"")
|
||||||
print("}\n")
|
print("}\n")
|
||||||
@ -154,15 +208,17 @@ class rObject:
|
|||||||
for r in rList:
|
for r in rList:
|
||||||
content = r._rez_string()
|
content = r._rez_string()
|
||||||
|
|
||||||
print("{}(${:08x}) {{".format(r.rName, r.get_id()))
|
print("{}(${:08x}{}) {{".format(
|
||||||
|
r.rName, r.get_id(), r._format_attr()
|
||||||
|
))
|
||||||
print(content)
|
print(content)
|
||||||
print("}\n")
|
print("}\n")
|
||||||
|
|
||||||
# container for a 0-terminated list of resource ids.
|
# container for a 0-terminated list of resource ids.
|
||||||
# NOT EXPORTED BY DEFAULT
|
# NOT EXPORTED BY DEFAULT
|
||||||
class rList(rObject):
|
class rList(rObject):
|
||||||
def __init__(self, *children, id=None, attr=None):
|
def __init__(self, *children, **kwargs):
|
||||||
super().__init__(id=id, attr=attr)
|
super().__init__(**kwargs)
|
||||||
self.children = children
|
self.children = children
|
||||||
tt = self.rChildType
|
tt = self.rChildType
|
||||||
for x in self.children:
|
for x in self.children:
|
||||||
@ -195,7 +251,7 @@ class rResName(rObject):
|
|||||||
rName = "rResName"
|
rName = "rResName"
|
||||||
rType = 0x8014
|
rType = 0x8014
|
||||||
|
|
||||||
def __init__(self, id=None, attr=None):
|
def __init__(self, id, attr=None):
|
||||||
super().__init__(id=id, attr=attr)
|
super().__init__(id=id, attr=attr)
|
||||||
self.children = []
|
self.children = []
|
||||||
|
|
||||||
@ -230,7 +286,8 @@ class rResName(rObject):
|
|||||||
rv += "\n\t}"
|
rv += "\n\t}"
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
# NOT EXPORTED BY DEFAULT
|
||||||
|
# abstract parent for text objects.
|
||||||
class rTextObject(rObject):
|
class rTextObject(rObject):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -243,10 +300,8 @@ class rTextObject(rObject):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, text, **kwargs): # id=None, attr=None):
|
||||||
|
super().__init__(**kwargs) # id=id, attr=attr
|
||||||
def __init__(self, text, *, id=None, attr=None):
|
|
||||||
super().__init__(id=id, attr=attr)
|
|
||||||
# text is a string or bytes.
|
# text is a string or bytes.
|
||||||
# bytes is assumed to be macroman
|
# bytes is assumed to be macroman
|
||||||
self.text = str_to_bytes(text)
|
self.text = str_to_bytes(text)
|
||||||
@ -326,8 +381,8 @@ class rStringList(rObject):
|
|||||||
rName = "rStringList"
|
rName = "rStringList"
|
||||||
rType = 0x8007
|
rType = 0x8007
|
||||||
|
|
||||||
def __init__(self, strings, *, id=None, attr=None):
|
def __init__(self, strings, **kwargs):
|
||||||
super().__init__(id, attr)
|
super().__init__(**kwargs)
|
||||||
self.children = [str_to_bytes(x) for x in strings]
|
self.children = [str_to_bytes(x) for x in strings]
|
||||||
|
|
||||||
def __bytes__(self):
|
def __bytes__(self):
|
||||||
@ -350,8 +405,8 @@ class rTwoRects(rObject):
|
|||||||
rName = "rTwoRects"
|
rName = "rTwoRects"
|
||||||
rType = 0x801a
|
rType = 0x801a
|
||||||
|
|
||||||
def __init__(self, r1, r2, *, id=None, attr=None):
|
def __init__(self, r1, r2, **kwargs):
|
||||||
super().__init__(id=id, attr=attr)
|
super().__init__(**kwargs)
|
||||||
self.r1 = r1
|
self.r1 = r1
|
||||||
self.r2 = r2
|
self.r2 = r2
|
||||||
|
|
||||||
@ -368,8 +423,8 @@ class rRectList(rObject):
|
|||||||
rName = "rRectList"
|
rName = "rRectList"
|
||||||
rType = 0xc001
|
rType = 0xc001
|
||||||
|
|
||||||
def __init__(self, *rects, id=None, attr=None):
|
def __init__(self, *rects, **kwargs):
|
||||||
super().__init__(id=id, attr=attr)
|
super().__init__(**kwargs)
|
||||||
self.rects = rects
|
self.rects = rects
|
||||||
|
|
||||||
def __bytes__(self):
|
def __bytes__(self):
|
||||||
|
28
control.py
28
control.py
@ -72,11 +72,10 @@ class rSimpleButton(rControlTemplate):
|
|||||||
# #Define SquareButton $0002
|
# #Define SquareButton $0002
|
||||||
# #Define SquareShadowButton $0003
|
# #Define SquareShadowButton $0003
|
||||||
def __init__(self, rect, title, *,
|
def __init__(self, rect, title, *,
|
||||||
id=None, attr=None,
|
|
||||||
flags = 0x0000, moreFlags = 0x0000,
|
flags = 0x0000, moreFlags = 0x0000,
|
||||||
refCon = 0x00000000, controlID=None,
|
refCon = 0x00000000, controlID=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
super().__init__(id, attr)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
if kwargs.get("invisible"): flags |= 0x0080
|
if kwargs.get("invisible"): flags |= 0x0080
|
||||||
if kwargs.get("inactive"): flags |= 0xff00
|
if kwargs.get("inactive"): flags |= 0xff00
|
||||||
@ -159,14 +158,14 @@ class rCheckControl(rControlTemplate):
|
|||||||
procRef = 0x82000000
|
procRef = 0x82000000
|
||||||
|
|
||||||
def __init__(self, rect, title, *,
|
def __init__(self, rect, title, *,
|
||||||
id=None, attr=None,
|
|
||||||
flags = 0x0000, moreFlags = 0x0000,
|
flags = 0x0000, moreFlags = 0x0000,
|
||||||
refCon = 0x00000000, controlID=None,
|
refCon = 0x00000000, controlID=None,
|
||||||
checked=False,
|
checked=False,
|
||||||
invisible=False, inactive=False,
|
invisible=False, inactive=False,
|
||||||
keys=None
|
keys=None,
|
||||||
|
**kwargs
|
||||||
):
|
):
|
||||||
super().__init__(id, attr)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
if invisible: flags |= 0x0080
|
if invisible: flags |= 0x0080
|
||||||
if inactive: flags |= 0xff00
|
if inactive: flags |= 0xff00
|
||||||
@ -250,7 +249,6 @@ class rRadioControl(rControlTemplate):
|
|||||||
procRef = 0x84000000
|
procRef = 0x84000000
|
||||||
|
|
||||||
def __init__(self, rect, title, *,
|
def __init__(self, rect, title, *,
|
||||||
id=None, attr=None,
|
|
||||||
flags = 0x0000, moreFlags = 0x0000,
|
flags = 0x0000, moreFlags = 0x0000,
|
||||||
refCon = 0x00000000, controlID=None,
|
refCon = 0x00000000, controlID=None,
|
||||||
checked=False,
|
checked=False,
|
||||||
@ -258,7 +256,7 @@ class rRadioControl(rControlTemplate):
|
|||||||
keys=None,
|
keys=None,
|
||||||
family=0
|
family=0
|
||||||
):
|
):
|
||||||
super().__init__(id, attr)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
if invisible: flags |= 0x0080
|
if invisible: flags |= 0x0080
|
||||||
if inactive: flags |= 0xff00
|
if inactive: flags |= 0xff00
|
||||||
@ -356,15 +354,15 @@ class rThermometerControl(rControlTemplate):
|
|||||||
procRef = 0x87FF0002
|
procRef = 0x87FF0002
|
||||||
|
|
||||||
def __init__(self, rect, *,
|
def __init__(self, rect, *,
|
||||||
id=None, attr=None,
|
|
||||||
flags = 0x0000, moreFlags = 0x0000,
|
flags = 0x0000, moreFlags = 0x0000,
|
||||||
refCon = 0x00000000, controlID=None,
|
refCon = 0x00000000, controlID=None,
|
||||||
value=0,
|
value=0,
|
||||||
scale=0,
|
scale=0,
|
||||||
horizontal=False,
|
horizontal=False,
|
||||||
invisible=False, inactive=False
|
invisible=False, inactive=False,
|
||||||
|
**kwargs
|
||||||
):
|
):
|
||||||
super().__init__(id, attr)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
if invisible: flags |= 0x0080 # ?
|
if invisible: flags |= 0x0080 # ?
|
||||||
if inactive: flags |= 0xff00 # ?
|
if inactive: flags |= 0xff00 # ?
|
||||||
@ -453,15 +451,15 @@ class rRectangleControl(rControlTemplate):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, rect, *,
|
def __init__(self, rect, *,
|
||||||
id=None, attr=None,
|
|
||||||
flags = 0x0000, moreFlags = 0x0000,
|
flags = 0x0000, moreFlags = 0x0000,
|
||||||
refCon = 0x00000000, controlID=None,
|
refCon = 0x00000000, controlID=None,
|
||||||
penHeight=1,
|
penHeight=1,
|
||||||
penWidth=2,
|
penWidth=2,
|
||||||
invisible=False, inactive=False,
|
invisible=False, inactive=False,
|
||||||
color = Black
|
color = Black,
|
||||||
|
**kwargs
|
||||||
):
|
):
|
||||||
super().__init__(id, attr)
|
super().__init__(kwargs)
|
||||||
|
|
||||||
if invisible: flags |= 0x0080
|
if invisible: flags |= 0x0080
|
||||||
if inactive: flags |= 0xff00
|
if inactive: flags |= 0xff00
|
||||||
@ -546,7 +544,6 @@ class rStatTextControl(rControlTemplate):
|
|||||||
|
|
||||||
|
|
||||||
def __init__(self, rect, text, *,
|
def __init__(self, rect, text, *,
|
||||||
id=None, attr=None,
|
|
||||||
flags = 0x0000, moreFlags = 0x0000,
|
flags = 0x0000, moreFlags = 0x0000,
|
||||||
refCon = 0x00000000, controlID=None,
|
refCon = 0x00000000, controlID=None,
|
||||||
invisible=False, inactive=False,
|
invisible=False, inactive=False,
|
||||||
@ -561,8 +558,9 @@ class rStatTextControl(rControlTemplate):
|
|||||||
centerJust = False,
|
centerJust = False,
|
||||||
rightJust = False,
|
rightJust = False,
|
||||||
fullJust = False,
|
fullJust = False,
|
||||||
|
**kwargs
|
||||||
):
|
):
|
||||||
super().__init__(id, attr)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
if invisible: flags |= 0x0080
|
if invisible: flags |= 0x0080
|
||||||
if inactive: flags |= 0xff00
|
if inactive: flags |= 0xff00
|
||||||
|
13
menu.py
13
menu.py
@ -45,8 +45,8 @@ class rMenuBar(rObject):
|
|||||||
rName = "rMenuBar"
|
rName = "rMenuBar"
|
||||||
rType = 0x8008
|
rType = 0x8008
|
||||||
|
|
||||||
def __init__(self, *children, id=None, attr=None):
|
def __init__(self, *children, **kwargs):
|
||||||
super().__init__(id, attr)
|
super().__init__(**kwargs)
|
||||||
self.children = children[:]
|
self.children = children[:]
|
||||||
for x in children:
|
for x in children:
|
||||||
if not isinstance(x, rMenu):
|
if not isinstance(x, rMenu):
|
||||||
@ -73,6 +73,7 @@ class rMenuBar(rObject):
|
|||||||
class rMenu(rObject):
|
class rMenu(rObject):
|
||||||
rName = "rMenu"
|
rName = "rMenu"
|
||||||
rType = 0x8009
|
rType = 0x8009
|
||||||
|
# rChildType = rMenuItem
|
||||||
rRange = range(0x0001,0xffff)
|
rRange = range(0x0001,0xffff)
|
||||||
|
|
||||||
# /*-------------------------------------------------------*/
|
# /*-------------------------------------------------------*/
|
||||||
@ -85,11 +86,11 @@ class rMenu(rObject):
|
|||||||
|
|
||||||
#flags = all off = a080 (disabled)
|
#flags = all off = a080 (disabled)
|
||||||
|
|
||||||
def __init__(self, title, *children, id=None, attr=None,
|
def __init__(self, title, *children,
|
||||||
flags=0x0000, menuID=None,
|
flags=0x0000, menuID=None,
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
super().__init__(id, attr)
|
super().__init__(**kwargs)
|
||||||
self.title = rPString.make_string(title)
|
self.title = rPString.make_string(title)
|
||||||
self.children = children[:]
|
self.children = children[:]
|
||||||
self.menuID = menuID
|
self.menuID = menuID
|
||||||
@ -167,10 +168,10 @@ class rMenuItem(rObject):
|
|||||||
# #Define ItemTitleRefShift $4000
|
# #Define ItemTitleRefShift $4000
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, title, keys="", *, id=None, attr=None,
|
def __init__(self, title, keys="", *,
|
||||||
checkMark=None, itemID=None, flags=0x0000,
|
checkMark=None, itemID=None, flags=0x0000,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
super().__init__(id, attr)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
self.title = rPString.make_string(title)
|
self.title = rPString.make_string(title)
|
||||||
|
|
||||||
|
4
sound.py
4
sound.py
@ -84,9 +84,9 @@ class rSoundSample(rObject):
|
|||||||
rName = "rSoundSample"
|
rName = "rSoundSample"
|
||||||
rType = 0x8024
|
rType = 0x8024
|
||||||
|
|
||||||
def __init__(filename, pitch=None, rate=None, channel=0, id=None, attr=None):
|
def __init__(filename, pitch=None, rate=None, channel=0, **kwargs):
|
||||||
|
|
||||||
super().__init__(id=id, attr=attr)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
new_rate = rate
|
new_rate = rate
|
||||||
freq = pitch_to_hz(pitch)
|
freq = pitch_to_hz(pitch)
|
||||||
|
@ -51,11 +51,9 @@ class rWindParam1(rObject):
|
|||||||
infoHeight = 0,
|
infoHeight = 0,
|
||||||
plane = -1, # inFront
|
plane = -1, # inFront
|
||||||
# inFront = True,
|
# inFront = True,
|
||||||
id = None,
|
|
||||||
attr = None,
|
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
|
||||||
super().__init__(id=id, attr=attr)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
self.frameBits = frameBits
|
self.frameBits = frameBits
|
||||||
if title: self.title = rPString.make_string(title)
|
if title: self.title = rPString.make_string(title)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user