[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue common/src/GRootObj.py common/src/GTrigger...
From: |
James Thompson |
Subject: |
gnue common/src/GRootObj.py common/src/GTrigger... |
Date: |
Thu, 31 Jan 2002 21:25:52 -0500 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: James Thompson <address@hidden> 02/01/31 21:25:51
Modified files:
common/src : GRootObj.py GTrigger.py GTriggerCore.py
forms/samples : helloworld2.gfd
forms/samples/intro: intro.gfd
forms/samples/trigger: trigger.gfd
forms/src : GFForm.py GFTrigger.py
forms/src/GFObjects: GFEntry.py
Log message:
New trigger namespace code patched into forms for testing
Still messy
Will break old triggers
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/GRootObj.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/GTrigger.py.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/GTriggerCore.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/samples/helloworld2.gfd.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/samples/intro/intro.gfd.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/samples/trigger/trigger.gfd.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/GFForm.py.diff?tr1=1.142&tr2=1.143&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/GFTrigger.py.diff?tr1=1.52&tr2=1.53&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/GFObjects/GFEntry.py.diff?tr1=1.35&tr2=1.36&r1=text&r2=text
Patches:
Index: gnue/common/src/GRootObj.py
diff -c gnue/common/src/GRootObj.py:1.1 gnue/common/src/GRootObj.py:1.2
*** gnue/common/src/GRootObj.py:1.1 Wed Jan 30 14:04:13 2002
--- gnue/common/src/GRootObj.py Thu Jan 31 21:25:51 2002
***************
*** 36,44 ****
#
#
class GRootObj:
def initTriggerSystem(self):
self._triggerNamespaceTree = GTriggerNamespace(self)
-
--- 36,46 ----
#
#
class GRootObj:
+ def __init__(self):
+ self._triggerNamespaceTree = None
+
def initTriggerSystem(self):
self._triggerNamespaceTree = GTriggerNamespace(self)
Index: gnue/common/src/GTrigger.py
diff -c gnue/common/src/GTrigger.py:1.6 gnue/common/src/GTrigger.py:1.7
*** gnue/common/src/GTrigger.py:1.6 Wed Jan 30 21:08:21 2002
--- gnue/common/src/GTrigger.py Thu Jan 31 21:25:51 2002
***************
*** 33,39 ****
from gnue.common.GObjects import GObj
from gnue.common import GDebug
! #
#
# Trigger namespace classes
#
--- 33,49 ----
from gnue.common.GObjects import GObj
from gnue.common import GDebug
! from gnue.common import GConfig, GTypecast
! from xml.sax import saxutils
! from gnue.common.GParser import GContent
!
! class TriggerError:
! def __init__(self, msg):
! self.msg = msg
!
!
!
! #######################################################################
#
# Trigger namespace classes
#
***************
*** 44,50 ****
#
# Manager class for a namespace. Passed a GObj based
# tree at __init__ which it uses to construct a new
! # GTriggerObject based tree
#
class GTriggerNamespace(GObj):
def __init__(self,objectTree = None):
--- 54,60 ----
#
# 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):
***************
*** 56,87 ****
else:
GDebug.printMesg(0,'GTriggerNamespace was passed an empty object tree')
- if 0:
- print "Function test"
- print self._globalNamespace['SampleBlock'].NameEntry.testFunc()
- print "Attribute test with get defined"
- foo = self._globalNamespace['SampleBlock'].NameEntry
- print foo
- print "Attribute test without get defined"
- foo = self._globalNamespace['SampleBlock']
- print foo
- print "Setting value"
- self._globalNamespace['SampleBlock'].YearEntry = 1952
- print "Showing value"
- print self._globalNamespace['SampleBlock'].YearEntry
- print "Showing property"
- print self._globalNamespace['SampleBlock'].YearEntry.gobjProperties.rows
- print "Setting property"
- self._globalNamespace['SampleBlock'].YearEntry.gobjProperties.rows = 23
- print "Showing property"
- print self._globalNamespace['SampleBlock'].YearEntry.gobjProperties.x
-
-
#
# constructTriggerObject
#
# Travels down thru a GObj based tree and builds a set
! # of GTriggerObjects that will implement the namespace
# inside triggers.
#
def constructTriggerObject(self, gobjObject, triggerParent=None):
--- 66,76 ----
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):
***************
*** 89,96 ****
# Some items in a GObj tree may not be GObj based (GContent for instance)
! if isinstance(gobjObject,GObj):
! triggerObject = GTriggerObject(triggerParent)
# Add this triggerObject to global namespace if the GObj requests it
if gobjObject._triggerGlobal:
--- 78,85 ----
# 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)
# Add this triggerObject to global namespace if the GObj requests it
if gobjObject._triggerGlobal:
***************
*** 105,119 ****
for item in gobjObject._triggerNamespace.keys():
if type(gobjObject._triggerNamespace[item]) == types.MethodType:
! object =
GTriggerFunction(item,gobjObject._triggerNamespace[item])
triggerObject.__dict__[item] = object
else:
GDebug.printMesg(0,'Only functions are supported in an objects
_triggerNamespace %s %s' % (gobjObject,item))
sys.exit()
! # Load the defined gobjProperties into this object's
! # GTriggerObjectProperties instance
if len(gobjObject._triggerProperties):
for item in gobjObject._triggerProperties.keys():
triggerObject._triggerProperties.addProperty(item,gobjObject._triggerProperties[item]['get'],\
--- 94,108 ----
for item in gobjObject._triggerNamespace.keys():
if type(gobjObject._triggerNamespace[item]) == types.MethodType:
! object =
GTriggerNSFunction(item,gobjObject._triggerNamespace[item])
triggerObject.__dict__[item] = object
else:
GDebug.printMesg(0,'Only functions are supported in an objects
_triggerNamespace %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():
triggerObject._triggerProperties.addProperty(item,gobjObject._triggerProperties[item]['get'],\
***************
*** 128,153 ****
if object:
triggerObject.__dict__[child.name] = object
return triggerObject
#
! # GTriggerObject
#
# Inherrits GObj to gain it's parent/child system
#
! class GTriggerObject(GObj):
def __init__(self, parent):
GObj.__init__(self,parent)
! self._triggerProperties = GTriggerObjectProperties()
self._triggerSet = None
self._triggerGet = None
#
# __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
! # GTriggerObject based object and calls that objects _triggerSet if it
# exists.
#
# Example: form.block1.entry1 = "foo"
--- 117,161 ----
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
#
# Inherrits 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
#
+ # 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"
***************
*** 157,164 ****
#
def __setattr__(self, name, value):
if self.__dict__.has_key(name) and \
! isinstance(self.__dict__[name], GTriggerObject):
!
if self.__dict__[name]._triggerSet:
self.__dict__[name]._triggerSet(value)
else:
--- 165,171 ----
#
def __setattr__(self, name, value):
if self.__dict__.has_key(name) and \
! isinstance(self.__dict__[name], GTriggerNSObject):
if self.__dict__[name]._triggerSet:
self.__dict__[name]._triggerSet(value)
else:
***************
*** 169,182 ****
#
# __getattr__
#
! # Only needed to return the GTriggerObjectProperties
# object
#
def __getattr__(self,name):
! if name == 'gobjProperties':
return self._triggerProperties
else:
! return self.__dict__[name]
#
# __str__
#
--- 176,192 ----
#
# __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
!
#
# __str__
#
***************
*** 191,221 ****
#
def __str__(self):
if self._triggerGet:
! return self._triggerGet()
else:
return ""
#
! # 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)
#
! # GTriggerFunction
#
# Accessor class for functions that are made available in the trigger
# namespace
#
! class GTriggerFunction:
def __init__(self, name, functionLink):
self._name = name
self._objectFunction = functionLink
--- 201,251 ----
#
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
! #
! # Needed but causing issues (local namespace setup bad?)
! #
! # 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
***************
*** 224,235 ****
return self._objectFunction(*args)
#
! # GTriggerObjectProperties
#
# Accessor class for properties that are made available in this an
! # object's gobjProperties namespace
#
! class GTriggerObjectProperties:
def __init__(self):
self._properties = {}
--- 254,265 ----
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 = {}
***************
*** 256,268 ****
if self.__dict__['_properties'].has_key(name):
return self._properties[name]['get']()
else:
! return None
--- 286,527 ----
if self.__dict__['_properties'].has_key(name):
return self._properties[name]['get']()
else:
! raise AttributeError
+ #######################################################################
+ #
+ # Trigger instance classes
+ #
+ # Classes in here are used to represent the triggers defined in
+ # <trigger> tags in an xml file
+ #
+
+
+ #
+ # A list of all valid triggers, and their "pretty" names
+ #
+ VALIDTRIGGERS = { 'PRE-FOCUSOUT': 'Pre-FocusOut',
+ 'POST-FOCUSOUT': 'Post-FocusOut',
+ 'PRE-FOCUSIN': 'Pre-FocusIn',
+ 'POST-FOCUSIN': 'Post-FocusIn',
+ 'PRE-COMMIT': 'Pre-Commit',
+ 'POST-COMMIT': 'Post-Commit',
+ 'POST-QUERY': 'Post-Query',
+ 'ON-SWITCH': 'On-Switch',
+ 'PRE-CHANGE': 'Pre-Change',
+ 'POST-CHANGE': 'Post-Change',
+ 'ON-NEWRECORD': 'On-NewRecord' }
+
+
+
+
+ #
+ # GTrigger
+ #
+ # Class used to implement triggers
+ #
+ class GTrigger(GObj):
+ def __init__(self, parent=None, type=None, name=None, src=None, text=None,
language='python'):
+ GObj.__init__(self, parent, 'GTrigger')
+
+ self._text=''
+ self._triggerns={}
+ self._inits = [None,self.initialize]
+
+ self.language=language
+ self.src = src
+ self.type = type and string.upper(type) or None
+ self.name = name
+ if text != None:
+ GContent(self, text)
+ if self.type != None:
+ self._buildObject()
+
+ #
+ # Must be at least a phase 2 init
+ #
+ # TODO: this function merges the local namespace
+ # TODO: not sure if this is doing the right thing
+ # TODO: with regard to NAMED triggers. It should
+ # TODO: merge the local namespace of the object that
+ # TODO: fired the trigger.
+ def initialize(self):
+ self._form = self.findParentOfType('GFForm')
+ self._triggerns.update( self._form._triggerns )
+ self.__call__ = self.dummyFunction
+
+ if self.type != "NAMED":
+ if self._parent:
+ self._parent.addTrigger( self.type, self )
+ self._triggerns.update(self._parent._localTriggerNamespace)
+ else:
+ form = self.findParentOfType('GFForm')
+ form._triggerDictionary[self.name] = self
+ self._triggerns.update(form._localTriggerNamespace)
+
+ if self.src == None:
+ self.setFunction( self.getChildrenAsContent(), self.language )
+ else:
+ self.setFunctionFrom(self._form._triggerDictionary[self.src])
+
+
+ def setFunctionFrom(self, object):
+ self.__call__=object.__call__
+
+ def setFunction(self, text, language):
+ self._text = text
+ self.language = language
+ if self.language != 'python':
+ GDebug.printMesg(0, "Language %s not implemented" % self.language)
+ sys.exit()
+
+
+ # TODO: this isn't working?????
+ # Verify that the trigger contains no tabs
+ if string.find('\t', self._text) >= 0:
+ GDebug.printMesg(0, "The trigger named %s contains a tab character
which is not allowed at pos %s"
+ % ( self.name, string.find('\t', self._text) ))
+ sys.exit()
+
+ # Remove whitespace from last line
+ self._text = string.rstrip(self._text)
+
+ # First compile the trigger:
+ # Compilation at this stage has the useful side effect that
+ # syntax errors are spotted during XML parsing rather than
+ # during execution.
+
+ # Get the indentation level of the first line of code so
+ # we can indent our imports to the same level
+ indentLevel = 0
+ for line in string.split(string.replace(self._text,'\r',''),'\n'):
+ if len(string.strip(line)) and string.lstrip(line)[0] != '#':
+ indentLevel = len(line) - len(string.lstrip(line))
+ break
+
+ revisedTriggerCode = \
+ "from gnue.forms.GFTriggerError import *\n"
+ for line in string.split(string.replace(self._text,'\r',''),'\n'):
+ revisedTriggerCode = revisedTriggerCode + line[indentLevel:] + '\n'
+ revisedTriggerCode = revisedTriggerCode + \
+ "pass\n"
+
+ try:
+ self._code = compile(revisedTriggerCode, '<string>', 'exec')
+ except SyntaxError, err:
+ GDebug.printMesg(0, "Syntax error in line %s of trigger in element ??" \
+ % ( err.lineno ))
+ sys.exit()
+
+ def thisTrigger(myself, code = self._code,
+ triggerns = self._triggerns):
+ # triggerns['self'] = myself
+ # triggerns['runform'] =
myself.findParentOfType('GFForm')._app.getManager().runFormFromTrigger
+ # triggerns.update(
+ try:
+ locals = {}
+ exec code in triggerns, locals
+ except TriggerError:
+ raise
+ except:
+ # May be better to deal with this in GFTriggerAware
+ raise
+ import sys
+ GDebug.printMesg(0, "%s in trigger code, value: %s" % (sys.exc_type,
sys.exc_value))
+
+ self.__call__ = thisTrigger
+
+ def dummyFunction(self, myself):
+ GDebug.printMesg(0, "Trigger not implemented")
+
+ #
+ # getDescription
+ #
+ # Return a useful description of this object
+ # for use by designer
+ #
+ def getDescription(self):
+ if self.type == 'NAMED':
+ return self.name
+ else:
+ return VALIDTRIGGERS[self.type]
+
+ #
+ # dumpXML
+ #
+ # Dumps an XML representation of the object
+ # used in saving
+ #
+ def dumpXML(self, lookupDict, treeDump=None, gap=None):
+ escape = not int(GConfig.get('StoreTriggersAsCDATA','0'))
+ xmlEntity = "trigger"
+ xmlString = "%s<%s" % (gap[:-2],xmlEntity)
+
+ indent = len(xmlString)
+ pos = indent
+ for attribute in self.__dict__.keys():
+
+ # variables beginning with _ are never saved out to file
+ # they are internal to the program
+ if attribute[0] == "_":
+ continue
+
+ val = self.__dict__[attribute]
+ if lookupDict[xmlEntity].has_key('Attributes') and \
+ lookupDict[xmlEntity]['Attributes'].has_key(attribute):
+ if val != None and \
+ (not
lookupDict[xmlEntity]['Attributes'][attribute].has_key('Default') or \
+ (lookupDict[xmlEntity]['Attributes'][attribute]['Default']) !=
(val)):
+ typecast =
lookupDict[xmlEntity]['Attributes'][attribute]['Typecast']
+ if typecast == GTypecast.boolean \
+ and val == 1:
+ addl = ' %s=""' % (attribute)
+ elif typecast == GTypecast.names:
+ addl = ' %s="%s"' % \
+ (attribute, string.join(val,','))
+ else:
+ addl = ' %s="%s"' % (attribute, saxutils.escape('%s' % val))
+ if len(addl) + pos > 78:
+ xmlString += "\n" + " " * indent + addl
+ pos = indent
+ else:
+ xmlString = xmlString + addl
+ pos += len(addl)
+
+ if len(self._children):
+ hasContent = 0
+ for child in self._children:
+ hasContent = hasContent or isinstance(child,GContent)
+ if hasContent:
+ xmlString += ">"
+ else:
+ xmlString += ">\n"
+
+ if treeDump:
+ if hasContent and not escape:
+ xmlString += "<![CDATA["
+ for child in self._children:
+ xmlString += child.dumpXML(lookupDict, 1,gap+" ",escape=escape)
+ if hasContent and not escape:
+ xmlString += "]]!>"
+
+ if hasContent:
+ xmlString += "</%s>\n" % (xmlEntity)
+ else:
+ xmlString += "%s</%s>\n" % (gap[:-2], xmlEntity)
+ else:
+ xmlString += "/>\n"
+ return xmlString
+
+
+
+
+
***************
*** 277,282 ****
--- 536,544 ----
+ #######################################################################
+ #
+ # Trigger processor classes
#
# GTriggerExtension
#
***************
*** 318,510 ****
print "Invalid trigger ",key
- # Things below this point are from the GFTrigger.py file in forms
- # Most if not all will require replacement but are in here so I
- # can easily grab existing code if it'll work.
-
- ## #
- ## # GFTrigger
- ## #
- ## # Class used to implement triggers
- ## #
- ## class GFTrigger(GFEventAware, GObj):
- ## def __init__(self, parent=None, type=None, name=None, src=None,
text=None, language='python'):
- ## GFEventAware.__init__(self)
-
- ## GObj.__init__(self, parent)
- ## self._type = "GFTrigger"
-
- ## self._text=''
- ## self.language=language
- ## self._triggerns={}
- ## self.src = src
- ## self.type = type
- ## self.name = name
- ## self._inits = [None,self.initialize]
- ## if text != None:
- ## GContent(self, text)
- ## if self.type != None:
- ## self._buildObject()
-
- ## def _buildObject (self):
- ## self.type=string.upper(self.type)
-
- ## # This is a hack for old forms that use "id" attr instead of "name"
- ## if hasattr(self, 'id'):
- ## if self.name == None:
- ## self.name = self.id
- ## del self.__dict__['id']
- ## return GObj._buildObject(self)
-
- ## #
- ## # Must be at least a phase 2 init
- ## #
- ## def initialize(self):
- ## self._form = self.findParentOfType('GFForm')
- ## self._triggerns.update( self._form._triggerns )
- ## self.__call__ = self.dummyFunction
-
- ## if self.type != "NAMED":
- ## if self._parent:
- ## self._parent.addTrigger( self.type, self )
- ## else:
- ## self.findParentOfType('GFForm')._triggerDictionary[self.name] = self
-
- ## if self.src == None:
- ## self.setFunction( self.getChildrenAsContent(), self.language )
- ## else:
- ## self.setFunctionFrom(self._form._triggerDictionary[self.src])
-
-
- ## def setFunctionFrom(self, object):
- ## self.__call__=object.__call__
-
- ## def setFunction(self, text, language):
- ## self._text = text
- ## self.language = language
- ## if self.language != 'python':
- ## print "Language %s not implemented" % self.language
- ## sys.exit()
-
-
- ## # Verify that the trigger contains no tabs
- ## if string.find('\t', self._text) >= 0:
- ## print "The trigger named %s contains a tab character which is not
allowed at pos %s" % ( self.name, string.find('\t', self._text) )
- ## sys.exit()
-
- ## # Remove whitespace from last line
- ## self._text = string.rstrip(self._text)
! ## # First compile the trigger:
! ## # Compilation at this stage has the useful side effect that
! ## # syntax errors are spotted during XML parsing rather than
! ## # during execution.
!
! ## # Get the indentation level of the first line of code so
! ## # we can indent our imports to the same level
! ## indentLevel = 0
! ## for line in string.split(string.replace(self._text,'\r',''),'\n'):
! ## if len(string.strip(line)) and string.lstrip(line)[0] != '#':
! ## indentLevel = len(line) - len(string.lstrip(line))
! ## break
!
! ## revisedTriggerCode = \
! ## "from gnue.forms.GFTriggerError import *\n"
! ## for line in string.split(string.replace(self._text,'\r',''),'\n'):
! ## revisedTriggerCode = revisedTriggerCode + line[indentLevel:] + '\n'
! ## revisedTriggerCode = revisedTriggerCode + \
! ## "pass\n"
!
! ## try:
! ## self._code = compile(revisedTriggerCode, '<string>', 'exec')
! ## except SyntaxError, err:
! ## print revisedTriggerCode
! ## print "Syntax error in line %s of trigger in element ??" \
! ## % ( err.lineno )
! ## sys.exit()
!
! ## def thisTrigger(myself, code = self._code,
! ## triggerns = self._triggerns):
! ## triggerns['self'] = myself
! ## triggerns['runform'] =
myself.findParentOfType('GFForm')._app.getManager().runFormFromTrigger
! ## try:
! ## locals = {}
! ## exec code in triggerns, locals
! ## except TriggerError:
! ## raise
! ## except:
! ## # May be better to deal with this in GFTriggerAware
! ## raise
! ## import sys
! ## print "%s in trigger code, value: %s" % (sys.exc_type,
sys.exc_value)
!
! ## self.__call__ = thisTrigger
!
! ## def dummyFunction(self, myself):
! ## print "Trigger not implemented"
!
! ## def getDescription(self):
! ## if self.type == 'NAMED':
! ## return self.name
! ## else:
! ## return VALIDTRIGGERS[self.type]
!
! ## def dumpXML(self, lookupDict, treeDump=None, gap=None):
! ## escape = not int(GConfig.get('StoreTriggersAsCDATA','0'))
! ## xmlEntity = "trigger"
! ## xmlString = "%s<%s" % (gap[:-2],xmlEntity)
!
! ## indent = len(xmlString)
! ## pos = indent
! ## for attribute in self.__dict__.keys():
! ## # skip keys beginning with _
! ## if attribute[0] == "_":
! ## continue
! ## val = self.__dict__[attribute]
! ## if lookupDict[xmlEntity].has_key('Attributes') and \
! ## lookupDict[xmlEntity]['Attributes'].has_key(attribute):
! ## if val != None and \
! ## (not
lookupDict[xmlEntity]['Attributes'][attribute].has_key('Default') or \
! ## (lookupDict[xmlEntity]['Attributes'][attribute]['Default']) !=
(val)):
! ## typecast =
lookupDict[xmlEntity]['Attributes'][attribute]['Typecast']
! ## if typecast == GTypecast.boolean \
! ## and val == 1:
! ## addl = ' %s=""' % (attribute)
! ## elif typecast == GTypecast.names:
! ## addl = ' %s="%s"' % \
! ## (attribute, string.join(val,','))
! ## else:
! ## addl = ' %s="%s"' % (attribute, saxutils.escape('%s' % val))
! ## if len(addl) + pos > 78:
! ## xmlString = xmlString + "\n" + " " * indent + addl
! ## pos = indent
! ## else:
! ## xmlString = xmlString + addl
! ## pos = pos + len(addl)
!
! ## if len(self._children):
! ## hasContent = 0
! ## for child in self._children:
! ## hasContent = hasContent or isinstance(child,GContent)
! ## if hasContent:
! ## xmlString = xmlString + ">"
! ## else:
! ## xmlString = xmlString + ">\n"
!
! ## if treeDump:
! ## if hasContent and not escape:
! ## xmlString = xmlString + "<![CDATA["
! ## for child in self._children:
! ## xmlString = xmlString + child.dumpXML(lookupDict, 1,gap+"
",escape=escape)
! ## if hasContent and not escape:
! ## xmlString = xmlString + "]]!>"
!
! ## if hasContent:
! ## xmlString = xmlString + "</%s>\n" % (xmlEntity)
! ## else:
! ## xmlString = xmlString + "%s</%s>\n" % (gap[:-2], xmlEntity)
! ## else:
! ## xmlString = xmlString + "/>\n"
! ## return xmlString
--- 580,586 ----
print "Invalid trigger ",key
!
Index: gnue/common/src/GTriggerCore.py
diff -c gnue/common/src/GTriggerCore.py:1.2 gnue/common/src/GTriggerCore.py:1.3
*** gnue/common/src/GTriggerCore.py:1.2 Wed Jan 30 19:28:49 2002
--- gnue/common/src/GTriggerCore.py Thu Jan 31 21:25:51 2002
***************
*** 42,50 ****
--- 42,58 ----
self._triggerProperties = {}
#
+ # Dictionary representing this object's
+ # local namespace. Populated as part of
+ # GTriggerNamespace.constructTriggerObject
+ #
+ self._localTriggerNamespace = {}
+
+ #
# Links to functions to be used when
# trigger attempts to directly set or get
# the objects by name
#
self._triggerSet = None
self._triggerGet = None
+
Index: gnue/forms/samples/helloworld2.gfd
diff -c gnue/forms/samples/helloworld2.gfd:1.8
gnue/forms/samples/helloworld2.gfd:1.9
*** gnue/forms/samples/helloworld2.gfd:1.8 Sun Nov 4 22:21:11 2001
--- gnue/forms/samples/helloworld2.gfd Thu Jan 31 21:25:51 2002
***************
*** 13,22 ****
#Populate User Name from Name
#
from string import *
! print "User", login.fields.user
! print "Address", address.fields.name
! print "self", self._value
! print "log block", login
#login.fields.user = address.fields.name
</trigger>
--- 13,24 ----
#Populate User Name from Name
#
from string import *
! print "User", login.user
!
! #print "User", login.fields.user
! #print "Address", address.fields.name
! #print "self", self._value
! #print "log block", login
#login.fields.user = address.fields.name
</trigger>
***************
*** 35,52 ****
<label x="1" y="7" name="Label_3" text="User Name"/>
<entry x="1" y="8" value="Type Here" field="user" name="user"
width="30">
<trigger type="PRE-FOCUSOUT" name="Trigger_2">
! #
! #User name validation trigger
! #
! from string import *
! #print login.fields.__class__
! #print lower(login.fields.user)
! #print login.fields.user[:3]
! if lower(login.fields.user)[:3] != lower(address.fields.name)[:3]:
! print "ERROR! First 3 letters of user name MUST"
! print " match first three letters of full name."
! login.fields.user=""
! print "User name updated to \"%s\"" % login.fields.user</trigger>
</entry>
<entry x="1" y="9" value="Type Here" field="pass" name="password"
width="30"/>
--- 37,60 ----
<label x="1" y="7" name="Label_3" text="User Name"/>
<entry x="1" y="8" value="Type Here" field="user" name="user"
width="30">
<trigger type="PRE-FOCUSOUT" name="Trigger_2">
! from string import lower
!
! print lower
! print login.user[:1]
! print lower("FOOOOO")
!
!
! foo = login.user
! bar = address.name
!
! print type(foo)
! print type(bar)
!
! if foo != bar:
! print "ERROR! First 3 letters of user name MUST"
! print " match first three letters of full name."
! login.user="Foo"
! print "User name updated to \"%s\"" % login.user</trigger>
</entry>
<entry x="1" y="9" value="Type Here" field="pass" name="password"
width="30"/>
Index: gnue/forms/samples/intro/intro.gfd
diff -c gnue/forms/samples/intro/intro.gfd:1.3
gnue/forms/samples/intro/intro.gfd:1.4
*** gnue/forms/samples/intro/intro.gfd:1.3 Wed Jan 30 19:28:49 2002
--- gnue/forms/samples/intro/intro.gfd Thu Jan 31 21:25:51 2002
***************
*** 16,24 ****
import string
! s = SampleBlock.fields.NameEntry
out = ''
for word in string.splitfields(s,' '):
if word:
# check for punctuation
p = 0
--- 16,28 ----
import string
! print "1"
! s = SampleBlock.NameEntry
out = ''
+ print "2"
+
for word in string.splitfields(s,' '):
+ print "2a"
if word:
# check for punctuation
p = 0
***************
*** 57,64 ****
word = prepunc + word + punc
out = out + ' ' + word
! SampleBlock.fields.CodeNameEntry = string.strip(out)
</trigger>
<trigger type="NAMED" name="MyFortune">
Fortunes = ['You will have a long and fruitful life with GNUe.',
--- 61,69 ----
word = prepunc + word + punc
out = out + ' ' + word
+ print "3"
! SampleBlock.CodeNameEntry = string.strip(out)
</trigger>
<trigger type="NAMED" name="MyFortune">
Fortunes = ['You will have a long and fruitful life with GNUe.',
***************
*** 72,88 ****
'You have a magnetic personality with GNUe forms.',
'Use GNUe and you will notice the extraordinary in the ordinary.']
! if len(SampleBlock.fields.YearEntry):
try:
! val = 'Confucius say,
"%s"'%Fortunes[int(SampleBlock.fields.YearEntry[-1:])]
except ValueError:
val = "Please enter a valid birth year first."
else:
val = "Please enter a valid birth year first."
! SampleBlock.fields.FortuneEntry = val
</trigger>
<page name="Welcome">
<block name="Block_1">
--- 77,93 ----
'You have a magnetic personality with GNUe forms.',
'Use GNUe and you will notice the extraordinary in the ordinary.']
! if len(SampleBlock.YearEntry):
try:
! val = 'Confucius say, "%s"'%Fortunes[int(SampleBlock.YearEntry[-1:])]
except ValueError:
val = "Please enter a valid birth year first."
else:
val = "Please enter a valid birth year first."
! SampleBlock.FortuneEntry = val
</trigger>
<page name="Welcome">
<block name="Block_1">
Index: gnue/forms/samples/trigger/trigger.gfd
diff -c gnue/forms/samples/trigger/trigger.gfd:1.12
gnue/forms/samples/trigger/trigger.gfd:1.13
*** gnue/forms/samples/trigger/trigger.gfd:1.12 Sun Nov 4 22:21:11 2001
--- gnue/forms/samples/trigger/trigger.gfd Thu Jan 31 21:25:51 2002
***************
*** 1,43 ****
<?xml version="1.0"?>
! <!-- GNUe Designer (0.1.0)
! Form saved on: 2001-11-04 22:05:23 -->
! <form width="50" title="Trigger Sample" height="8">
<options>
<option value="0.0.3" name="version"/>
<option value="GNUE Enterprise Developers" name="author"/>
</options>
<page name="Page_1">
<block name="block1">
! <label x="1" y="1" width="48" name="Label_1" alignment="center"
text="Field One"/>
! <entry name="one" x="1" y="2" width="48"/>
<label x="1" y="3" name="Label_2" text="Field Two"/>
! <entry name="two" x="1" y="4" width="48"/>
</block>
<block name="block2">
! <label x="1" y="5" name="Label_3" text="Block Two (Page Down to
enter)"/>
! <label x="1" y="6" name="Label_4"
text="Alteration Field (Press tab to fire trigger)"/>
! <entry x="1" y="7" field="newValue" name="alter" width="48">
<options>
! <option name="tip" value="Type Field One's Replacement"/>
</options>
! <trigger type="PRE-FOCUSOUT" name="Trigger_1">
! #print block1.fields.two
! #block1.fields.one =
! import sys
! print "Value is ",self.getValue()
! if (block1.fields.one == "") or (block1.fields.two == ""):
! messageValue = "Both Fields One and Two Must Have Data!"
! else:
! messageValue = "Contragulations. You get your own error.\n" +
block2.fields.alter
!
! print messageValue
! block1.fields.one = block2.fields.alter
! #message = GFMsgBox(self, messageValue)
! #message.show()
</trigger>
</entry>
</block>
--- 1,118 ----
<?xml version="1.0"?>
! <!-- GNUe Designer (0.2.0a)
! Saved on: 2002-01-31 10:33:45 -->
! <form width="50" title="Trigger Sample" height="16">
<options>
<option value="0.0.3" name="version"/>
<option value="GNUE Enterprise Developers" name="author"/>
</options>
<page name="Page_1">
<block name="block1">
! <label x="1" y="1" name="Label_1" alignment="center" width="48"
text="Field One"/>
! <entry x="1" y="2" name="one" width="48"/>
<label x="1" y="3" name="Label_2" text="Field Two"/>
! <entry x="1" y="4" name="two" width="48"/>
! <label x="1" y="5" name="Label_1a" text="Field Three"/>
! <entry x="1" y="6" name="three" width="48"/>
! <label x="1" y="7" name="Label_2a" text="Field Four"/>
! <entry x="1" y="8" name="four" width="48"/>
! <label x="1" y="9" name="Label_3a" text="Field Five"/>
! <entry x="1" y="10" name="five" width="48"/>
!
</block>
<block name="block2">
! <label x="1" y="12" name="Label_3" text="Block Two (Page Down to
enter)"/>
! <label x="1" y="13" name="Label_4"
text="Alteration Field (Press tab to fire trigger)"/>
! <entry x="1" y="14" field="newValue" name="alter" width="48">
<options>
! <option value="Type Field One's Replacement" name="tip"/>
</options>
! <trigger name="Trigger_1" type="PRE-FOCUSOUT">
! # basics
! print "Value get test"
! print block2.alter
! # Function test
! print "Function test - global form var test"
! print form.Page_1.block2.alter.testFunc()
!
!
! # Test to make sure assignment doesn't copy the objects only
! # their string values
! print "Setting value"
! block1.five = block2.alter
! block2.alter = "G"
! print block1.five
! print block2.alter
!
! # Properties
! print "Showing property"
! print block2.alter.__properties__.rows
! print "Attempt to set a readonly property"
! block2.alter.__properties__.rows = 23
!
! # Comparison
! if block1.one == block1.two:
! print "block1.one and block1.two match"
! elif block1.one > block1.two:
! print "block1.one greater than block1.two"
! elif block1.one < block1.two:
! print "block1.one less than block1.two"
! else:
! print "Comparison System needs food badly"
!
! # Slices
! print block1.one[:2]
!
! #
! # function call
! #
! from string import lower
! print lower ("FOO")
! print lower (str(block2.alter))
!
!
! #
! # validate local namespace
! #
! print "Showing local namespace access"
! print "Value"
! print self
!
! print "rows"
! print self.__properties__.rows
!
! # Things that don't work but probably should and how to fix it
! #
! # block1.five = block2.alter + block1.one + block1.two
! # (add __add__ support to GTriggerNSObject)
! #
! # print lower (block2.alter)
! # (this fails because block2.alter is a GTriggerNSObject
! # not a string so it fails when the lower function attempts
! # to call a lower() function that GTriggerNSObject doesn't implement
! # No good solution known at this time)
!
!
! #
! # Completely untested
! #
! # #print block1.fields.two
! # #block1.fields.one =
! # import sys
! # print "Value is ",self.getValue()
! # if (block1.fields.one == "") or (block1.fields.two == ""):
! # messageValue = "Both Fields One and Two Must Have Data!"
! # else:
! # messageValue = "Contragulations. You get your own error.\n" +
block2.fields.alter
! #
! # print messageValue
! # block1.fields.one = block2.fields.alter
! # #message = GFMsgBox(self, messageValue)
! # #message.show()
</trigger>
</entry>
</block>
Index: gnue/forms/src/GFForm.py
diff -c gnue/forms/src/GFForm.py:1.142 gnue/forms/src/GFForm.py:1.143
*** gnue/forms/src/GFForm.py:1.142 Wed Jan 30 19:28:49 2002
--- gnue/forms/src/GFForm.py Thu Jan 31 21:25:51 2002
***************
*** 49,54 ****
--- 49,55 ----
class GFForm(GFObj, GRootObj, GFEventAware):
def __init__(self, parent=None, app=None):
+ GRootObj.__init__(self)
GFObj.__init__(self, parent)
GFEventAware.__init__(self)
self._type = "GFForm"
***************
*** 73,86 ****
self._app = app
! self._triggerns={
! 'TRUE': 1,
! 'FALSE': 0,
! 'GFMsgBox' : GFMsgBox
! }
# The "None" init gives datasources time to setup master/detail
! self._inits = [self.primaryInit, None, self.secondaryInit,
self.initTriggerSystem]
#
# New trigger support
--- 74,87 ----
self._app = app
! self._triggerns={}
! # 'TRUE': 1,
! # 'FALSE': 0,
! # 'GFMsgBox' : GFMsgBox
! #}
# The "None" init gives datasources time to setup master/detail
! self._inits = [self.primaryInit, None, self.secondaryInit]
#
# New trigger support
***************
*** 123,137 ****
# analyze the tree
self.walk(self.analyzeTree)
!
def secondaryInit(self):
# create the first records
for key in self._datasourceDictionary.keys():
if not self._datasourceDictionary[key].hasMaster():
self._datasourceDictionary[key].createEmptyResultSet()
-
-
#
# begin routines made for walking
#
--- 124,139 ----
# analyze the tree
self.walk(self.analyzeTree)
!
! self.initTriggerSystem()
! self._triggerns.update(self._triggerNamespaceTree._globalNamespace)
!
def secondaryInit(self):
# create the first records
for key in self._datasourceDictionary.keys():
if not self._datasourceDictionary[key].hasMaster():
self._datasourceDictionary[key].createEmptyResultSet()
#
# begin routines made for walking
#
***************
*** 154,162 ****
if self._currentBlock == None:
self._currentBlock = object
! try:
! self._triggerns[object.name] = GFTrigger.GFTriggerHelper( object )
! except AttributeError: pass
elif object.getObjectType() == 'GFPage':
self._pageList.append(object)
--- 156,164 ----
if self._currentBlock == None:
self._currentBlock = object
! #try:
! # self._triggerns[object.name] = GFTrigger.GFTriggerHelper( object )
! #except AttributeError: pass
elif object.getObjectType() == 'GFPage':
self._pageList.append(object)
***************
*** 167,175 ****
self._currentEntry = object
elif object.getObjectType() =='GFDataSource':
! try:
! self._triggerns[object.name] = GFTrigger.GFTriggerHelper( object )
! except AttributeError: pass
object.name = string.lower(object.name)
self._datasourceDictionary[object.name]=object
--- 169,177 ----
self._currentEntry = object
elif object.getObjectType() =='GFDataSource':
! #try:
! # self._triggerns[object.name] = GFTrigger.GFTriggerHelper( object )
! #except AttributeError: pass
object.name = string.lower(object.name)
self._datasourceDictionary[object.name]=object
Index: gnue/forms/src/GFObjects/GFEntry.py
diff -c gnue/forms/src/GFObjects/GFEntry.py:1.35
gnue/forms/src/GFObjects/GFEntry.py:1.36
*** gnue/forms/src/GFObjects/GFEntry.py:1.35 Wed Jan 30 21:08:21 2002
--- gnue/forms/src/GFObjects/GFEntry.py Thu Jan 31 21:25:51 2002
***************
*** 74,83 ****
#
self._triggerNamespace={'testFunc':self.testFunc,
}
! self._triggerProperties={'x':{'set':self.setX,
! 'get':self.getX,
! },
! 'rows':{'set':None,
'get':self.getRows
},
}
--- 74,80 ----
#
self._triggerNamespace={'testFunc':self.testFunc,
}
! self._triggerProperties={'rows':{'set':None,
'get':self.getRows
},
}
***************
*** 86,98 ****
def testFunc(self):
#return "I have to do something"
! return self._buildObject
!
! def setX(self,value):
! self.x = value
!
! def getX(self):
! return self.x
def getRows(self):
return self._rows
--- 83,89 ----
def testFunc(self):
#return "I have to do something"
! return "Fooooooooooooo!"
def getRows(self):
return self._rows
***************
*** 199,212 ****
# Pulls the proper value from the resultSet
#
def getValue(self):
! if self._block.mode == 'query':
! if self._block._queryValues.has_key(self):
! value = self._block._queryValues[self]
else:
! value = None
else:
! value = self._block._resultSet.current.getField(self.field)
!
if value == None: value = ''
#CheckBox does not work if comment following "if" block (ra3vat)
--- 190,209 ----
# Pulls the proper value from the resultSet
#
def getValue(self):
! # We have to check to see if the _block has been
! # setup yet. The Trigger system calls getValue
! # before it's ready so we fake it
! if hasattr(self,'_block'):
! if self._block.mode == 'query':
! if self._block._queryValues.has_key(self):
! value = self._block._queryValues[self]
! else:
! value = None
else:
! value = self._block._resultSet.current.getField(self.field)
else:
! value = None
!
if value == None: value = ''
#CheckBox does not work if comment following "if" block (ra3vat)
Index: gnue/forms/src/GFTrigger.py
diff -c gnue/forms/src/GFTrigger.py:1.52 gnue/forms/src/GFTrigger.py:1.53
*** gnue/forms/src/GFTrigger.py:1.52 Thu Nov 8 04:11:42 2001
--- gnue/forms/src/GFTrigger.py Thu Jan 31 21:25:51 2002
***************
*** 33,38 ****
--- 33,39 ----
from gnue.common.GParser import GContent
from gnue.common.GObjects import GObj
from gnue.common import GConfig, GTypecast
+ from gnue.common.GTrigger import GTrigger
from xml.sax import saxutils
import string
***************
*** 88,97 ****
#
# Class used to implement triggers
#
! class GFTrigger(GFEventAware, GObj):
! def __init__(self, parent=None, type=None, name=None, src=None, text=None,
language='python'):
! GFEventAware.__init__(self)
GObj.__init__(self, parent)
self._type = "GFTrigger"
--- 89,107 ----
#
# Class used to implement triggers
#
! #class GFTrigger(GFEventAware, GObj):
! class GFTrigger(GTrigger):
! ## def __init__(self, parent=None, type=None, name=None, src=None,
text=None, language='python'):
! ## GTrigger.__init__(self, parent=None, type=None, name=None, src=None,
text=None, language='python')
! ## self._type="GFTrigger"
!
! ## print language
! ## print type
! ## print src
! ## print text
! ## print self._inits
+ def __init__(self, parent=None, type=None, name=None, src=None, text=None,
language='python'):
GObj.__init__(self, parent)
self._type = "GFTrigger"
***************
*** 107,346 ****
if self.type != None:
self._buildObject()
- def _buildObject (self):
- self.type=string.upper(self.type)
-
- # This is a hack for old forms that use "id" attr instead of "name"
- if hasattr(self, 'id'):
- if self.name == None:
- self.name = self.id
- del self.__dict__['id']
- return GObj._buildObject(self)
-
- #
- # Must be at least a phase 2 init
- #
- def initialize(self):
- self._form = self.findParentOfType('GFForm')
- self._triggerns.update( self._form._triggerns )
- self.__call__ = self.dummyFunction
-
- if self.type != "NAMED":
- if self._parent:
- self._parent.addTrigger( self.type, self )
- else:
- self.findParentOfType('GFForm')._triggerDictionary[self.name] = self
-
- if self.src == None:
- self.setFunction( self.getChildrenAsContent(), self.language )
- else:
- self.setFunctionFrom(self._form._triggerDictionary[self.src])
-
-
- def setFunctionFrom(self, object):
- self.__call__=object.__call__
- def setFunction(self, text, language):
- self._text = text
- self.language = language
- if self.language != 'python':
- print "Language %s not implemented" % self.language
- sys.exit()
-
-
- # Verify that the trigger contains no tabs
- if string.find('\t', self._text) >= 0:
- print "The trigger named %s contains a tab character which is not
allowed at pos %s" % ( self.name, string.find('\t', self._text) )
- sys.exit()
-
- # Remove whitespace from last line
- self._text = string.rstrip(self._text)
-
- # First compile the trigger:
- # Compilation at this stage has the useful side effect that
- # syntax errors are spotted during XML parsing rather than
- # during execution.
-
- # Get the indentation level of the first line of code so
- # we can indent our imports to the same level
- indentLevel = 0
- for line in string.split(string.replace(self._text,'\r',''),'\n'):
- if len(string.strip(line)) and string.lstrip(line)[0] != '#':
- indentLevel = len(line) - len(string.lstrip(line))
- break
-
- revisedTriggerCode = \
- "from gnue.forms.GFTriggerError import *\n"
- for line in string.split(string.replace(self._text,'\r',''),'\n'):
- revisedTriggerCode = revisedTriggerCode + line[indentLevel:] + '\n'
- revisedTriggerCode = revisedTriggerCode + \
- "pass\n"
-
- try:
- self._code = compile(revisedTriggerCode, '<string>', 'exec')
- except SyntaxError, err:
- print revisedTriggerCode
- print "Syntax error in line %s of trigger in element ??" \
- % ( err.lineno )
- sys.exit()
-
- def thisTrigger(myself, code = self._code,
- triggerns = self._triggerns):
- triggerns['self'] = myself
- triggerns['runform'] =
myself.findParentOfType('GFForm')._app.getManager().runFormFromTrigger
- try:
- locals = {}
- exec code in triggerns, locals
- except TriggerError:
- raise
- except:
- # May be better to deal with this in GFTriggerAware
- raise
- import sys
- print "%s in trigger code, value: %s" % (sys.exc_type, sys.exc_value)
-
- self.__call__ = thisTrigger
-
- def dummyFunction(self, myself):
- print "Trigger not implemented"
-
- def getDescription(self):
- if self.type == 'NAMED':
- return self.name
- else:
- return VALIDTRIGGERS[self.type]
-
- def dumpXML(self, lookupDict, treeDump=None, gap=None):
- escape = not int(GConfig.get('StoreTriggersAsCDATA','0'))
- xmlEntity = "trigger"
- xmlString = "%s<%s" % (gap[:-2],xmlEntity)
-
- indent = len(xmlString)
- pos = indent
- for attribute in self.__dict__.keys():
- # skip keys beginning with _
- if attribute[0] == "_":
- continue
- val = self.__dict__[attribute]
- if lookupDict[xmlEntity].has_key('Attributes') and \
- lookupDict[xmlEntity]['Attributes'].has_key(attribute):
- if val != None and \
- (not
lookupDict[xmlEntity]['Attributes'][attribute].has_key('Default') or \
- (lookupDict[xmlEntity]['Attributes'][attribute]['Default']) !=
(val)):
- typecast =
lookupDict[xmlEntity]['Attributes'][attribute]['Typecast']
- if typecast == GTypecast.boolean \
- and val == 1:
- addl = ' %s=""' % (attribute)
- elif typecast == GTypecast.names:
- addl = ' %s="%s"' % \
- (attribute, string.join(val,','))
- else:
- addl = ' %s="%s"' % (attribute, saxutils.escape('%s' % val))
- if len(addl) + pos > 78:
- xmlString = xmlString + "\n" + " " * indent + addl
- pos = indent
- else:
- xmlString = xmlString + addl
- pos = pos + len(addl)
-
- if len(self._children):
- hasContent = 0
- for child in self._children:
- hasContent = hasContent or isinstance(child,GContent)
- if hasContent:
- xmlString = xmlString + ">"
- else:
- xmlString = xmlString + ">\n"
-
- if treeDump:
- if hasContent and not escape:
- xmlString = xmlString + "<![CDATA["
- for child in self._children:
- xmlString = xmlString + child.dumpXML(lookupDict, 1,gap+"
",escape=escape)
- if hasContent and not escape:
- xmlString = xmlString + "]]!>"
-
- if hasContent:
- xmlString = xmlString + "</%s>\n" % (xmlEntity)
- else:
- xmlString = xmlString + "%s</%s>\n" % (gap[:-2], xmlEntity)
- else:
- xmlString = xmlString + "/>\n"
- return xmlString
- #
- # Helper class for building the namespace for python triggers. All access
- # to GFObjects from triggers are through this class. Its function is to
- # instantiate a subclass of GFTriggerHelperBase and pass information through
- # this.
- #
- class GFTriggerHelper:
- def __init__(self,object, helper=None):
- baseClassDict = { 'GFBlock': GFTriggerBlock,
- 'GFDataSource': GFTriggerDatasource}
- if helper == None:
- self.__dict__['helper'] = baseClassDict[ object._type ](object)
- else:
- self.__dict__['helper'] = helper( object )
-
- def __getattr__(self,name):
- return self.__dict__['helper'].getattribute(name)
-
- def __setattr__(self,name,value):
- self.__dict__['helper'].setattribute(name, value)
-
- class GFTriggerHelperBase:
- def __init__( self, object ):
- self.object = object
-
- def getattribute( self, name ):
- return getattr( self.object, name )
-
- def setattribute( self, name, value ):
- setattr( self.object, name, value )
-
- class GFTriggerBlock( GFTriggerHelperBase ):
- def __init__(self, object):
- GFTriggerHelperBase.__init__(self, object)
- self.fields=GFTriggerHelper( object, helper=GFTriggerFields )
-
- def getattribute( self, name ):
- # Here I've implemented the syntax blockname.fields.fieldname
- # we could use things like this to implent e.g.
- # blockname.functions.nextField or blockname.properties.dataSource
- # while protecting internal variables from malicious trigger code.
- if name == 'fields':
- return self.fields
- elif name == '__getitem__':
- return self.__dict__['object'].__getitem__
- else:
- raise AttributeError
-
- def setattributes( self, name, value ):
- raise AttributeError
- class GFTriggerDatasource(GFTriggerHelperBase ):
- def __init__(self, object):
- GFTriggerHelperBase.__init__(self, object)
-
- class GFTriggerFields( GFTriggerHelperBase ):
- def getattribute( self, name ):
- for item in self.object._entryList:
- if item.name == name:
- return item.getValue()
- return None
-
- def setattribute( self, name, value ):
- try:
- for item in self.object._entryList:
- if item.name == name:
- item._cursorPosition = len(value)
- item.setValue(value)
- return
- except KeyError:
- self.name = value
- return
--- 117,126 ----
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue common/src/GRootObj.py common/src/GTrigger...,
James Thompson <=