@@ -71,6 +71,31 @@ def mkenum(enum):
7171 if IsEnum (enum ): return enum
7272 return Enum (enum )
7373
74+ class Boolean :
75+ """An AE boolean value"""
76+
77+ def __init__ (self , bool ):
78+ self .bool = (not not bool )
79+
80+ def __repr__ (self ):
81+ return "Boolean(%s)" % `self.bool`
82+
83+ def __str__ (self ):
84+ if self .bool :
85+ return "True"
86+ else :
87+ return "False"
88+
89+ def __aepack__ (self ):
90+ return pack (struct .pack ('b' , self .bool ), 'bool' )
91+
92+ def IsBoolean (x ):
93+ return IsInstance (x , Boolean )
94+
95+ def mkboolean (bool ):
96+ if IsBoolean (bool ): return bool
97+ return Boolean (bool )
98+
7499class Type :
75100 """An AE 4-char typename object"""
76101
@@ -153,6 +178,12 @@ def __aepack__(self):
153178
154179def IsComparison (x ):
155180 return IsInstance (x , Comparison )
181+
182+ class NComparison (Comparison ):
183+ # The class attribute 'relo' must be set in a subclass
184+
185+ def __init__ (self , obj1 , obj2 ):
186+ Comparison .__init__ (obj1 , self .relo , obj2 )
156187
157188class Logical :
158189 """An AE logical expression object"""
@@ -332,10 +363,10 @@ class ObjectSpecifier:
332363 key type description
333364 --- ---- -----------
334365
335- 'want' type what kind of thing we want,
366+ 'want' type 4-char class code of thing we want,
336367 e.g. word, paragraph or property
337368
338- 'form' enum how we specify the thing(s) we want,
369+ 'form' enum how we specify which 'want' thing(s) we want,
339370 e.g. by index, by range, by name, or by property specifier
340371
341372 'seld' any which thing(s) we want,
@@ -369,21 +400,50 @@ def __aepack__(self):
369400 'from' : self .fr },
370401 'obj ' )
371402
372-
373403def IsObjectSpecifier (x ):
374404 return IsInstance (x , ObjectSpecifier )
375405
376406
407+ # Backwards compatability, sigh...
377408class Property (ObjectSpecifier ):
378409
379- def __init__ (self , which , fr = None ):
380- ObjectSpecifier .__init__ (self , 'prop' , 'prop' , mkenum (which ), fr )
410+ def __init__ (self , which , fr = None , want = 'prop' ):
411+ ObjectSpecifier .__init__ (self , want , 'prop' , mktype (which ), fr )
381412
382413 def __repr__ (self ):
383414 if self .fr :
384- return "Property(%s, %s)" % (`self.seld.enum ` , `self.fr` )
415+ return "Property(%s, %s)" % (`self.seld.type ` , `self.fr` )
385416 else :
386- return "Property(%s)" % `self.seld.enum`
417+ return "Property(%s)" % `self.seld.type`
418+
419+ def __str__ (self ):
420+ if self .fr :
421+ return "Property %s of %s" % (str (self .seld ), str (self .fr ))
422+ else :
423+ return "Property %s" % str (self .seld )
424+
425+
426+ class NProperty (ObjectSpecifier ):
427+ # Subclasses *must* self baseclass attributes:
428+ # want is the type of this property
429+ # which is the property name of this property
430+
431+ def __init__ (self , fr = None ):
432+ #try:
433+ # dummy = self.want
434+ #except:
435+ # self.want = 'prop'
436+ self .want = 'prop'
437+ ObjectSpecifier .__init__ (self , self .want , 'prop' ,
438+ mktype (self .which ), fr )
439+
440+ def __repr__ (self ):
441+ rv = "Property(%s" % `self.seld.type`
442+ if self .fr :
443+ rv = rv + ", fr=%s" % `self.fr`
444+ if self .want != 'prop' :
445+ rv = rv + ", want=%s" % `self.want`
446+ return rv + ")"
387447
388448 def __str__ (self ):
389449 if self .fr :
@@ -402,13 +462,19 @@ def __init__(self, want, seld, fr = None):
402462 form = 'rang'
403463 elif IsComparison (seld ) or IsLogical (seld ):
404464 form = 'test'
465+ elif t == TupleType :
466+ # Breakout: specify both form and seld in a tuple
467+ # (if you want ID or rele or somesuch)
468+ form , seld = seld
405469 else :
406470 form = 'indx'
407471 ObjectSpecifier .__init__ (self , want , form , seld , fr )
408472
409473
410474class ComponentItem (SelectableItem ):
411475 # Derived classes *must* set the *class attribute* 'want' to some constant
476+ # Also, dictionaries _propdict and _elemdict must be set to map property
477+ # and element names to the correct classes
412478
413479 def __init__ (self , which , fr = None ):
414480 SelectableItem .__init__ (self , self .want , which , fr )
@@ -434,7 +500,30 @@ def __str__(self):
434500 s = "%s %s" % (self .__class__ .__name__ , ss )
435501 if self .fr : s = s + " of %s" % str (self .fr )
436502 return s
437-
503+
504+ def __getattr__ (self , name ):
505+ if self ._elemdict .has_key (name ):
506+ cls = self ._elemdict [name ]
507+ return DelayedComponentItem (cls , self )
508+ if self ._propdict .has_key (name ):
509+ cls = self ._propdict [name ]
510+ return cls (self )
511+ raise AttributeError , name
512+
513+
514+ class DelayedComponentItem :
515+ def __init__ (self , compclass , fr ):
516+ self .compclass = compclass
517+ self .fr = fr
518+
519+ def __call__ (self , which ):
520+ return self .compclass (which , self .fr )
521+
522+ def __repr__ (self ):
523+ return "%s(???, %s)" % (self .__class__ .__name__ , `self.fr` )
524+
525+ def __str__ (self ):
526+ return "selector for element %s of %s" % (self .__class__ .__name__ , str (self .fr ))
438527
439528template = """
440529class %s(ComponentItem): want = '%s'
0 commit comments