[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/common/src GRootObj.py GTrigger.py GFormul...
From: |
Jason Cater |
Subject: |
gnue/common/src GRootObj.py GTrigger.py GFormul... |
Date: |
Mon, 10 Feb 2003 01:01:03 -0500 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Jason Cater <address@hidden> 03/02/10 01:00:58
Modified files:
common/src : GRootObj.py GTrigger.py
Added files:
common/src : GFormula.py NamespaceCore.py
Log message:
* Separation of namespace-logic from trigger-specific code
* Start of formula support
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/GFormula.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/NamespaceCore.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/GRootObj.py.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/GTrigger.py.diff?tr1=1.29&tr2=1.30&r1=text&r2=text
Patches:
Index: gnue/common/src/GRootObj.py
diff -c gnue/common/src/GRootObj.py:1.10 gnue/common/src/GRootObj.py:1.11
*** gnue/common/src/GRootObj.py:1.10 Wed Feb 5 21:36:57 2003
--- gnue/common/src/GRootObj.py Mon Feb 10 01:00:58 2003
***************
*** 30,36 ****
#
! from gnue.common.GTrigger import GTriggerNamespace
from gnue.common.GObjects import GObj
#
# GRootObj
--- 30,36 ----
#
! from gnue.common.NamespaceCore import GObjNamespace
from gnue.common.GObjects import GObj
#
# GRootObj
***************
*** 50,56 ****
self._globalRuntimeNamespace = {}
def initTriggerSystem(self):
! self._triggerNamespaceTree = GTriggerNamespace(self,rootName=self._rname)
def dumpXML(self, treeDump=1, gap=" "):
return GObj.dumpXML(self, self.__xmlElementCallback(),
--- 50,56 ----
self._globalRuntimeNamespace = {}
def initTriggerSystem(self):
! self._triggerNamespaceTree = GObjNamespace(self,rootName=self._rname)
def dumpXML(self, treeDump=1, gap=" "):
return GObj.dumpXML(self, self.__xmlElementCallback(),
Index: gnue/common/src/GTrigger.py
diff -c gnue/common/src/GTrigger.py:1.29 gnue/common/src/GTrigger.py:1.30
*** gnue/common/src/GTrigger.py:1.29 Wed Jan 1 19:45:41 2003
--- gnue/common/src/GTrigger.py Mon Feb 10 01:00:58 2003
***************
*** 52,335 ****
-
- #######################################################################
- #
- # Trigger namespace classes
- #
- # Classes used in implementing the trigger namespace
- #
- #
- # GTriggerNamespace
- #
- # Manager class for a namespace. Passed a GObj based
- # tree at __init__ which it uses to construct a new
- # GTriggerNSObject based tree
- #
- class GTriggerNamespace(GObj):
- def __init__(self,objectTree = None, rootName="root"):
- self._globalNamespace = {'True' : 1,
- 'False': 0,
- }
-
- self._rname = rootName
-
- if objectTree:
- self._globalNamespace[self._rname] =
self.constructTriggerObject(objectTree)
- else:
- GDebug.printMesg(0,'GTriggerNamespace was passed an empty object tree')
-
-
- #
- # constructTriggerObject
- #
- # Travels down thru a GObj based tree and builds a set
- # of GTriggerNSObjects that will implement the namespace
- # inside triggers.
- #
- def constructTriggerObject(self, gobjObject, triggerParent=None):
- triggerObject = None
-
- # Some items in a GObj tree may not be GObj based (GContent for instance)
-
- if isinstance(gobjObject,GObj) and hasattr(gobjObject,'name'):
- triggerObject = GTriggerNSObject(triggerParent)
- triggerObject._object = gobjObject
-
- # Add this triggerObject to global namespace if the GObj requests it
- if gobjObject._triggerGlobal:
- self._globalNamespace[gobjObject.name] = triggerObject
-
- # setup get and set functions when they exist in the GObj
- triggerObject._triggerSet = gobjObject._triggerSet
- triggerObject._triggerGet = gobjObject._triggerGet
-
- # Add any trigger methods defined by GObj
- if len(gobjObject._triggerFunctions):
- for item in gobjObject._triggerFunctions.keys():
-
- if type(gobjObject._triggerFunctions[item]['function']) ==
types.MethodType:
- object =
GTriggerNSFunction(item,gobjObject._triggerFunctions[item]['function'])
- triggerObject.__dict__[item] = object
- # Add this function to global namespace if the GObj requests it
- if gobjObject._triggerFunctions[item].has_key('global') and \
- gobjObject._triggerFunctions[item]['global'] != 0:
- self._globalNamespace[item] = object
-
- else:
- GDebug.printMesg(0,'Only functions are supported in an objects
_triggerFunctions %s %s' % (gobjObject,item))
-
- sys.exit()
-
- # Load the defined __properties__ into this object's
- # GTriggerNSObjectProperties instance
- if len(gobjObject._triggerProperties):
- for item in gobjObject._triggerProperties.keys():
- if gobjObject._triggerProperties[item].has_key('set'):
- setFunc = gobjObject._triggerProperties[item]['set']
- else:
- setFunc = None
-
triggerObject._triggerProperties.addProperty(item,gobjObject._triggerProperties[item]['get'],
setFunc)
-
- # Process the children of this Gobj
- if len(gobjObject._children):
- for child in gobjObject._children:
- object = self.constructTriggerObject(child, triggerObject)
-
- # Add this objects children to it's namespace by their name
- if object:
- triggerObject.__dict__[child.name] = object
-
- #
- # populate the GObj's _localTriggerNamespace
- localNamespace = {'self':triggerObject}
- localNamespace.update(triggerObject.__dict__)
- gobjObject._localTriggerNamespace = localNamespace
-
- return triggerObject
-
- #
- # GTriggerNSObject
- #
- # Inherits GObj to gain it's parent/child system
- #
- class GTriggerNSObject(GObj):
- def __init__(self, parent):
- GObj.__init__(self,parent)
- self._triggerProperties = GTriggerNSObjectProperties()
- self._triggerSet = None
- self._triggerGet = None
- self._object = None
-
- #
- # showTree
- #
- # Handy function to dump a rough look at the namespace
- # doesn't show things nested properly though
- def showTree(self, indent=0):
- print ' ' * indent + `self._type` + `self`
- for item in self.__dict__.keys():
- if item[:1] != '_':
- print ' ' * indent + ' :' + item
- for child in self._children:
- child.showTree(indent + 2)
-
- #
- # __setattr__
- #
- # This is called when trying to write something inside a trigger object
- # namespace. It checks to see if the var name is already linked to a
- # GTriggerNSObject based object and calls that objects _triggerSet if it
- # exists.
- #
- # Example: form.block1.entry1 = "foo"
- #
- # The __setattr__ will execute at the block1 and call the functions that
- # are part of the entry1 object to set it's value
- #
- def __setattr__(self, name, value):
- if self.__dict__.has_key(name) and \
- isinstance(self.__dict__[name], GTriggerNSObject):
- if isinstance(self.__dict__[name], GTriggerNSObject):
- if self.__dict__[name]._triggerSet:
- self.__dict__[name]._triggerSet(value)
- else:
- GDebug.printMesg(0,'Trigger attempting to reset a form object')
- else:
- self.__dict__[name] = value
-
- #
- # __getattr__
- #
- # Only needed to return the GTriggerNSObjectProperties
- # object
- #
- def __getattr__(self,name):
- if name == '__properties__':
- return self._triggerProperties
- else:
- # GDebug.printMesg(1,"AttributeError: %s" % name)
- # print self.__dict__
- raise AttributeError, '%s' % (name)
-
- #
- # __str__
- #
- # This executes at a different level than the __setattr__
- # While __setattr__ is executed in the parent object to protect
- # it's namespace object links, this routine is called by the
- # object referenced
- #
- # Example: foo = form.block1.entry1
- #
- # This __str__ would execute against the entry1 object
- #
- def __str__(self):
- if self._triggerGet:
- return str(self._triggerGet())
- else:
- return ""
-
- #
- # __cmp__
- #
- # Forces the system to compare the string values of
- # GTriggerNSObject objects and not their instances
- #
- def __cmp__(self,other):
- selfvalue = "%s" % self
- othervalue = "%s" % other
-
- if selfvalue == othervalue:
- return 0
- elif selfvalue < othervalue:
- return -1
- else:
- return 1
-
-
- #
- # __nonzero__
- #
- # Needed to make __len__ function below play nice
- #
- def __nonzero__(self):
- return 1
-
- #
- # __len__
- #
- # Implements len() support
- #
- def __len__(self):
- string = "%s" % self
- return len(string)
-
- #
- # __getitem__
- #
- # implements support for sub selections of strings
- #
- # example: block1.fieldname[0:4]
- #
- def __getitem__(self, key) :
- string = self.__str__()
- return string[key.start:key.stop]
-
- #
- # GTriggerNSFunction
- #
- # Accessor class for functions that are made available in the trigger
- # namespace
- #
- class GTriggerNSFunction:
- def __init__(self, name, functionLink):
- self._name = name
- self._objectFunction = functionLink
-
- def __call__(self, *args):
- return self._objectFunction(*args)
-
- #
- # GTriggerNSObjectProperties
- #
- # Accessor class for properties that are made available in this an
- # object's __properties__ namespace
- #
- class GTriggerNSObjectProperties:
- def __init__(self):
- self._properties = {}
-
- def addProperty(self,name, getFunc, setFunc):
- self._properties[name] = {'get':getFunc,
- 'set':setFunc,
- }
-
- def __setattr__(self, name, value):
- # Hack to ensure that self._properties exists
- if not self.__dict__.has_key('_properties'):
- self.__dict__['_properties'] = {}
-
- if self._properties.has_key(name):
- # If none the it's readonly
- if self._properties[name]['set']:
- self._properties[name]['set'](value)
- else:
- GDebug.printMesg(0,'Attempt to set readonly property :%s' %(name))
- else:
- self.__dict__[name] = value
-
- def __getattr__(self,name):
- if self.__dict__['_properties'].has_key(name):
- return self._properties[name]['get']()
- else:
- raise AttributeError
-
-
-
-
-
-
#######################################################################
#
# Trigger instance classes
--- 52,57 ----
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/common/src GRootObj.py GTrigger.py GFormul...,
Jason Cater <=