Commit 756a69fa authored by Jack Jansen's avatar Jack Jansen

- Added classes to support class/property generation by gensuitemodule

- Fixed Property class: selector is a 'type', not an 'enum'
parent a8441ded
...@@ -117,6 +117,7 @@ def unpack(desc): ...@@ -117,6 +117,7 @@ def unpack(desc):
if unpacker_coercions.has_key(t): if unpacker_coercions.has_key(t):
desc = desc.AECoerceDesc(unpacker_coercions[t]) desc = desc.AECoerceDesc(unpacker_coercions[t])
t = desc.type # This is a guess by Jack....
if t == typeAEList: if t == typeAEList:
l = [] l = []
......
...@@ -107,14 +107,17 @@ def enumsubst(arguments, key, edict): ...@@ -107,14 +107,17 @@ def enumsubst(arguments, key, edict):
def decodeerror(arguments): def decodeerror(arguments):
"""Create the 'best' argument for a raise MacOS.Error""" """Create the 'best' argument for a raise MacOS.Error"""
errn = arguments['errn'] errn = arguments['errn']
errarg = (errn, ) err_a1 = errn
if arguments.has_key('errs'): if arguments.has_key('errs'):
errarg = errarg + (arguments['errs'],) err_a2 = arguments['errs']
else:
err_a2 = MacOS.GetErrorString(errn)
if arguments.has_key('erob'): if arguments.has_key('erob'):
errarg = errarg + (arguments['erob'],) err_a3 = arguments['erob']
if len(errarg) == 1: else:
errarg = errarg + ('Server returned error code %d'%errn, ) err_a3 = None
return errarg
return (err_a1, err_a2, err_a3)
class TalkTo: class TalkTo:
"""An AE connection to an application""" """An AE connection to an application"""
...@@ -178,8 +181,8 @@ class TalkTo: ...@@ -178,8 +181,8 @@ class TalkTo:
"""Send 'activate' command""" """Send 'activate' command"""
self.send('misc', 'actv') self.send('misc', 'actv')
def get(self, _object, _attributes={}): def _get(self, _object, as=None, _attributes={}):
"""get: get data from an object """_get: get data from an object
Required argument: the object Required argument: the object
Keyword argument _attributes: AppleEvent attribute dictionary Keyword argument _attributes: AppleEvent attribute dictionary
Returns: the data Returns: the data
...@@ -188,7 +191,8 @@ class TalkTo: ...@@ -188,7 +191,8 @@ class TalkTo:
_subcode = 'getd' _subcode = 'getd'
_arguments = {'----':_object} _arguments = {'----':_object}
if as:
_arguments['rtyp'] = mktype(as)
_reply, _arguments, _attributes = self.send(_code, _subcode, _reply, _arguments, _attributes = self.send(_code, _subcode,
_arguments, _attributes) _arguments, _attributes)
......
...@@ -71,6 +71,31 @@ def mkenum(enum): ...@@ -71,6 +71,31 @@ def mkenum(enum):
if IsEnum(enum): return enum if IsEnum(enum): return enum
return Enum(enum) return Enum(enum)
class Boolean:
"""An AE boolean value"""
def __init__(self, bool):
self.bool = (not not bool)
def __repr__(self):
return "Boolean(%s)" % `self.bool`
def __str__(self):
if self.bool:
return "True"
else:
return "False"
def __aepack__(self):
return pack(struct.pack('b', self.bool), 'bool')
def IsBoolean(x):
return IsInstance(x, Boolean)
def mkboolean(bool):
if IsBoolean(bool): return bool
return Boolean(bool)
class Type: class Type:
"""An AE 4-char typename object""" """An AE 4-char typename object"""
...@@ -153,6 +178,12 @@ class Comparison: ...@@ -153,6 +178,12 @@ class Comparison:
def IsComparison(x): def IsComparison(x):
return IsInstance(x, Comparison) return IsInstance(x, Comparison)
class NComparison(Comparison):
# The class attribute 'relo' must be set in a subclass
def __init__(self, obj1, obj2):
Comparison.__init__(obj1, self.relo, obj2)
class Logical: class Logical:
"""An AE logical expression object""" """An AE logical expression object"""
...@@ -332,10 +363,10 @@ class ObjectSpecifier: ...@@ -332,10 +363,10 @@ class ObjectSpecifier:
key type description key type description
--- ---- ----------- --- ---- -----------
'want' type what kind of thing we want, 'want' type 4-char class code of thing we want,
e.g. word, paragraph or property e.g. word, paragraph or property
'form' enum how we specify the thing(s) we want, 'form' enum how we specify which 'want' thing(s) we want,
e.g. by index, by range, by name, or by property specifier e.g. by index, by range, by name, or by property specifier
'seld' any which thing(s) we want, 'seld' any which thing(s) we want,
...@@ -369,21 +400,50 @@ class ObjectSpecifier: ...@@ -369,21 +400,50 @@ class ObjectSpecifier:
'from': self.fr}, 'from': self.fr},
'obj ') 'obj ')
def IsObjectSpecifier(x): def IsObjectSpecifier(x):
return IsInstance(x, ObjectSpecifier) return IsInstance(x, ObjectSpecifier)
# Backwards compatability, sigh...
class Property(ObjectSpecifier): class Property(ObjectSpecifier):
def __init__(self, which, fr = None): def __init__(self, which, fr = None, want='prop'):
ObjectSpecifier.__init__(self, 'prop', 'prop', mkenum(which), fr) ObjectSpecifier.__init__(self, want, 'prop', mktype(which), fr)
def __repr__(self): def __repr__(self):
if self.fr: if self.fr:
return "Property(%s, %s)" % (`self.seld.enum`, `self.fr`) return "Property(%s, %s)" % (`self.seld.type`, `self.fr`)
else: else:
return "Property(%s)" % `self.seld.enum` return "Property(%s)" % `self.seld.type`
def __str__(self):
if self.fr:
return "Property %s of %s" % (str(self.seld), str(self.fr))
else:
return "Property %s" % str(self.seld)
class NProperty(ObjectSpecifier):
# Subclasses *must* self baseclass attributes:
# want is the type of this property
# which is the property name of this property
def __init__(self, fr = None):
#try:
# dummy = self.want
#except:
# self.want = 'prop'
self.want = 'prop'
ObjectSpecifier.__init__(self, self.want, 'prop',
mktype(self.which), fr)
def __repr__(self):
rv = "Property(%s"%`self.seld.type`
if self.fr:
rv = rv + ", fr=%s" % `self.fr`
if self.want != 'prop':
rv = rv + ", want=%s" % `self.want`
return rv + ")"
def __str__(self): def __str__(self):
if self.fr: if self.fr:
...@@ -402,6 +462,10 @@ class SelectableItem(ObjectSpecifier): ...@@ -402,6 +462,10 @@ class SelectableItem(ObjectSpecifier):
form = 'rang' form = 'rang'
elif IsComparison(seld) or IsLogical(seld): elif IsComparison(seld) or IsLogical(seld):
form = 'test' form = 'test'
elif t == TupleType:
# Breakout: specify both form and seld in a tuple
# (if you want ID or rele or somesuch)
form, seld = seld
else: else:
form = 'indx' form = 'indx'
ObjectSpecifier.__init__(self, want, form, seld, fr) ObjectSpecifier.__init__(self, want, form, seld, fr)
...@@ -409,6 +473,8 @@ class SelectableItem(ObjectSpecifier): ...@@ -409,6 +473,8 @@ class SelectableItem(ObjectSpecifier):
class ComponentItem(SelectableItem): class ComponentItem(SelectableItem):
# Derived classes *must* set the *class attribute* 'want' to some constant # Derived classes *must* set the *class attribute* 'want' to some constant
# Also, dictionaries _propdict and _elemdict must be set to map property
# and element names to the correct classes
def __init__(self, which, fr = None): def __init__(self, which, fr = None):
SelectableItem.__init__(self, self.want, which, fr) SelectableItem.__init__(self, self.want, which, fr)
...@@ -434,7 +500,30 @@ class ComponentItem(SelectableItem): ...@@ -434,7 +500,30 @@ class ComponentItem(SelectableItem):
s = "%s %s" % (self.__class__.__name__, ss) s = "%s %s" % (self.__class__.__name__, ss)
if self.fr: s = s + " of %s" % str(self.fr) if self.fr: s = s + " of %s" % str(self.fr)
return s return s
def __getattr__(self, name):
if self._elemdict.has_key(name):
cls = self._elemdict[name]
return DelayedComponentItem(cls, self)
if self._propdict.has_key(name):
cls = self._propdict[name]
return cls(self)
raise AttributeError, name
class DelayedComponentItem:
def __init__(self, compclass, fr):
self.compclass = compclass
self.fr = fr
def __call__(self, which):
return self.compclass(which, self.fr)
def __repr__(self):
return "%s(???, %s)" % (self.__class__.__name__, `self.fr`)
def __str__(self):
return "selector for element %s of %s"%(self.__class__.__name__, str(self.fr))
template = """ template = """
class %s(ComponentItem): want = '%s' class %s(ComponentItem): want = '%s'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment