Example #1
0
 def Attr(self, table, buffer):
     ''' An attribute of a node or script '''
     (tag, start, stop, (name, value)) = table
     name = getString ( name, buffer )
     clientNode = self.nodeStack[-1]
     try:
         field = getField( clientNode, name )
     except AttributeError:
         raise AttributeError(
             """Unknown field name %s for node type %s on line %s"""%(
                 name,
                 protoName(clientNode),
                 lines( end=start, buffer=buffer),
             )
         )
     if value[0] == 'IS':
         mapName = dispatch( self, value, buffer )
         set = node.ismaps( self.prototypeStack[-1] )
         set.setdefault( mapName, []).append( (clientNode,name) )
     else:
         self.fieldTypeStack.append(
             field.typeName()
         )
         try:
             value = dispatch( self, value, buffer )
             if isinstance( clientNode, node.PrototypedNode):
                 # prototyped nodes get IS-value updates
                 field.fset( clientNode, value, notify=1 )
             else:
                 field.fset( clientNode, value, notify=0 )
         finally:
             self.fieldTypeStack.pop()
Example #2
0
 def _attrDict(self, object ):
     """Write out the attribute dictionary for an object"""
     buffer = self.buffer
     linvalues = self.linvalues
     if self.curproto:
         set = node.ismaps( self.curproto[-1] )
         isMaps = {}
         for fieldName, fieldList in set.items():
             for (n,field) in fieldList:
                 if n is object:
                     isMaps[ field ] = fieldName
     else:
         isMaps = {}
     if protoName( object) == "Script":
         #print 'Script attributes'
         items = [
             field for field in getFields(object)
             if field.name in ('url','mustEvaluate','directOutput')
         ]
     else:
         items = [
             field for field in getFields(object)
             if field.name and field.name[0] != ' '
         ]
     items.sort()
     for field in items:
         # following slows us down, but prevents the chaff from showing up...
         val = field.fget( object )
         default = field.getDefault()
         if field.name in isMaps:
             buffer.write(
                 '%(full_element_separator)s%(curindent)s%(indent)s%%s IS %%s\t'%linvalues%(field.name, isMaps.get(field.name) )
             )
         elif (
             (
                 default is not None and 
                 not arrays.safeCompare( default, val)
             ) or 
             default is None
         ):
             buffer.write(
                 '%(full_element_separator)s%(curindent)s%(indent)s%%s\t'%linvalues%(field.name, )
             )
             self._sffield( val, field )
Example #3
0
 def Script( self, table, buffer):
     ''' A script node (can be a root node)'''
     (tag, start, stop, sublist) = table
     # what's the DEF name...
     if sublist and sublist[0][0] == 'name':
         name = getString ( sublist [0], buffer)
         rest = sublist [1:]
     else:
         name = ""
         rest = sublist
     # build the node, with dummy fields
     newNode = self.basePrototypes.get('Script')(
         (),
     )
     vProto = newNode.__class__
     # register it
     root( newNode, self.sceneGraphStack [0])
     if name:
         self.sceneGraphStack [-1].regDefName( name, newNode )
     self.nodeStack.append (newNode)
     # now get the field-declarations...
     fields, attributes,isMaps = [], [], []
     for item in rest:
         if item[0] in ("ScriptEventDecl", "ScriptFieldDecl"):
             f,mapName = dispatch( self, item, buffer)
             setattr( vProto, f.name, f )
             if mapName is not None:
                 isMaps.append( (mapName,f.name) )
         elif item[0] == 'Attr':
             attributes.append( item )
         else:
             dispatch( self, item, buffer)
     if isMaps:
         set = node.ismaps( self.prototypeStack[-1] )
         for (name, field) in isMaps:
             set.setdefault( name, []).append( (newNode,field) )
     dispatchList(self, attributes, buffer)
     self.nodeStack.pop ()
     return newNode