commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue common/src/GRootObj.py common/src/GTrigger...


From: Jason Cater
Subject: gnue common/src/GRootObj.py common/src/GTrigger...
Date: Sun, 20 Oct 2002 14:55:50 -0400

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/10/20 14:55:49

Modified files:
        common/src     : GRootObj.py GTrigger.py 
        forms/src      : GFForm.py GFInstance.py GFTrigger.py 

Log message:
        * Added an On-Exit trigger to the form
        object (complementary to On-Startup)
        
        * Added support for global namespace objects
        in trigger code.  For example, in On-Startup:
        
        global math, myfunc, DEBUG
        import math
        def myfunc(n1,n2):
        return n1+n2
        DEBUG = 1
        
        Then other triggers can access math, myfunc,
        and DEBUG as if they had imported or defined
        them.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/GRootObj.py.diff?cvsroot=OldCVS&tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/GTrigger.py.diff?cvsroot=OldCVS&tr1=1.21&tr2=1.22&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/forms/src/GFForm.py.diff?cvsroot=OldCVS&tr1=1.182&tr2=1.183&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/forms/src/GFInstance.py.diff?cvsroot=OldCVS&tr1=1.57&tr2=1.58&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/forms/src/GFTrigger.py.diff?cvsroot=OldCVS&tr1=1.60&tr2=1.61&r1=text&r2=text

Patches:
Index: gnue/common/src/GRootObj.py
diff -c gnue/common/src/GRootObj.py:1.3 gnue/common/src/GRootObj.py:1.4
*** gnue/common/src/GRootObj.py:1.3     Mon Sep 23 11:52:37 2002
--- gnue/common/src/GRootObj.py Sun Oct 20 14:55:49 2002
***************
*** 12,19 ****
  # PURPOSE. See the GNU General Public License for more details.
  #
  # You should have received a copy of the GNU General Public 
! # License along with program; see the file COPYING. If not, 
! # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
  # Copyright 2000-2002 Free Software Foundation
--- 12,19 ----
  # PURPOSE. See the GNU General Public License for more details.
  #
  # You should have received a copy of the GNU General Public 
! # License along with program; see the file COPYING. If not,
! # write to the Free Software Foundation, Inc., 59 Temple Place
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
  # Copyright 2000-2002 Free Software Foundation
***************
*** 36,46 ****
  #
  #
  class GRootObj:
!   def __init__(self):
      self._triggerNamespaceTree = None
      
    def initTriggerSystem(self):
!     self._triggerNamespaceTree = GTriggerNamespace(self)
  
  
  
--- 36,50 ----
  #
  #
  class GRootObj:
!   def __init__(self, rootName="root"):
      self._triggerNamespaceTree = None
+     self._rname = rootName
      
+     # This will store any "global myVar" that the triggers execute.
+     self._globalRuntimeNamespace = {}
+ 
    def initTriggerSystem(self):
!     self._triggerNamespaceTree = GTriggerNamespace(self,rootName=self._rname)
  
  
  
Index: gnue/common/src/GTrigger.py
diff -c gnue/common/src/GTrigger.py:1.21 gnue/common/src/GTrigger.py:1.22
*** gnue/common/src/GTrigger.py:1.21    Sat Sep 28 00:41:45 2002
--- gnue/common/src/GTrigger.py Sun Oct 20 14:55:49 2002
***************
*** 1,19 ****
  #
  # This file is part of GNU Enterprise.
  #
! # GNU Enterprise is free software; you can redistribute it 
  # and/or modify it under the terms of the GNU General Public
! # License as published by the Free Software Foundation; either 
  # version 2, or (at your option) any later version.
  #
  # GNU Enterprise is distributed in the hope that it will be
! # useful, but WITHOUT ANY WARRANTY; without even the implied 
! # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  # PURPOSE. See the GNU General Public License for more details.
  #
! # You should have received a copy of the GNU General Public 
! # License along with program; see the file COPYING. If not, 
! # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
  # Copyright 2000-2002 Free Software Foundation
--- 1,19 ----
  #
  # This file is part of GNU Enterprise.
  #
! # GNU Enterprise is free software; you can redistribute it
  # and/or modify it under the terms of the GNU General Public
! # License as published by the Free Software Foundation; either
  # version 2, or (at your option) any later version.
  #
  # GNU Enterprise is distributed in the hope that it will be
! # useful, but WITHOUT ANY WARRANTY; without even the implied
! # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  # PURPOSE. See the GNU General Public License for more details.
  #
! # You should have received a copy of the GNU General Public
! # License along with program; see the file COPYING. If not,
! # write to the Free Software Foundation, Inc., 59 Temple Place
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
  # Copyright 2000-2002 Free Software Foundation
***************
*** 30,35 ****
--- 30,36 ----
  import sys
  import types
  import string
+ import copy
  from gnue.common.GObjects import GObj
  from gnue.common import GDebug
  
***************
*** 66,80 ****
  # GTriggerNSObject based tree
  #
  class GTriggerNamespace(GObj):
!   def __init__(self,objectTree = None):
      self._globalNamespace = {'True' : 1,
                               'False': 0,
                               }
      if objectTree:
!       self._globalNamespace['form'] = self.constructTriggerObject(objectTree)
      else:
        GDebug.printMesg(0,'GTriggerNamespace was passed an empty object tree')
  
    #
    # constructTriggerObject
    #
--- 67,85 ----
  # 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
    #
***************
*** 104,110 ****
          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 \
--- 109,115 ----
          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 \
***************
*** 113,119 ****
  
            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
--- 118,124 ----
  
            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
***************
*** 130,136 ****
        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
--- 135,141 ----
        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
***************
*** 146,152 ****
  #
  # GTriggerNSObject
  #
! # Inherrits GObj to gain it's parent/child system
  #
  class GTriggerNSObject(GObj):
    def __init__(self, parent):
--- 151,157 ----
  #
  # GTriggerNSObject
  #
! # Inherits GObj to gain it's parent/child system
  #
  class GTriggerNSObject(GObj):
    def __init__(self, parent):
***************
*** 197,203 ****
    # __getattr__
    #
    # Only needed to return the GTriggerNSObjectProperties
!   # object 
    #
    def __getattr__(self,name):
      if name == '__properties__':
--- 202,208 ----
    # __getattr__
    #
    # Only needed to return the GTriggerNSObjectProperties
!   # object
    #
    def __getattr__(self,name):
      if name == '__properties__':
***************
*** 304,313 ****
      # 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))
--- 309,318 ----
      # 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))
***************
*** 356,364 ****
                    'PRE-MODIFY':     'Pre-Modify',
                    'POST-COMMIT':    'Post-Commit'}
  
- 
- 
- 
  #
  # GTrigger
  #
--- 361,366 ----
***************
*** 394,399 ****
--- 396,402 ----
    # TODO: fired the trigger.
    def initialize(self):
      self._triggerns.update( self._root._triggerns )
+     self._globalns = self._root._globalRuntimeNamespace
      self.__call__ = self.dummyFunction
  
      if self.type != "NAMED":
***************
*** 459,471 ****
        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:
--- 462,485 ----
        sys.exit()
  
      def thisTrigger(myself, code = self._code,
!                     triggerns = self._triggerns,
!                     globalns = self._globalns):
  #      triggerns['self'] = myself
  #      triggerns['runform'] = 
myself.findParentOfType('GFForm')._app.getManager().runFormFromTrigger
  #      triggerns.update(
+ 
+       # Merge the trigger's namespace with the runtime global namespace
+       # (Which can be set via the "global myvar" construct)
+       try:
+         del globalns['__builtins__']
+       except KeyError:
+         pass
        try:
!         localns = copy.copy(triggerns)
!         localns.update(globalns)
! 
!         # And execute our code
!         exec code in globalns, localns
        except TriggerError:
          raise
        except:
***************
*** 519,525 ****
           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:
--- 533,539 ----
           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:
***************
*** 527,570 ****
            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
  
  
  
  
!           
  #######################################################################
  #
  # Trigger processor classes
--- 541,584 ----
            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
  
  
  
  
! 
  #######################################################################
  #
  # Trigger processor classes
Index: gnue/forms/src/GFForm.py
diff -c gnue/forms/src/GFForm.py:1.182 gnue/forms/src/GFForm.py:1.183
*** gnue/forms/src/GFForm.py:1.182      Mon Sep 30 02:21:46 2002
--- gnue/forms/src/GFForm.py    Sun Oct 20 14:55:49 2002
***************
*** 36,42 ****
  from gnue.common.FileUtils import openResource
  from GFObjects import *
  from GFEvent import *
! from gnue.common.GDataObjects import ConnectionError as DBError
  from gnue.common.GRootObj import GRootObj
  #from GFTriggerError import *
  from gnue.common.GTrigger import TriggerError
--- 36,42 ----
  from gnue.common.FileUtils import openResource
  from GFObjects import *
  from GFEvent import *
! from gnue.common.       GDataObjects import ConnectionError as DBError
  from gnue.common.GRootObj import GRootObj
  #from GFTriggerError import *
  from gnue.common.GTrigger import TriggerError
***************
*** 50,56 ****
  
  class GFForm(GFObj, GRootObj, GFEventAware):
    def __init__(self, parent=None, app=None):
!     GRootObj.__init__(self)
      GFObj.__init__(self, parent)
      self._type = "GFForm"
      self._currentObject = [self]
--- 50,56 ----
  
  class GFForm(GFObj, GRootObj, GFEventAware):
    def __init__(self, parent=None, app=None):
!     GRootObj.__init__(self, 'form')
      GFObj.__init__(self, parent)
      self._type = "GFForm"
      self._currentObject = [self]
***************
*** 100,111 ****
                                            },
                                'commit':{'function':self.commit,
                                            'global': 1,
                                            }
                                }
  
- 
- 
- 
    #
    # Convert some deprecated options to new style
    #
--- 100,111 ----
                                            },
                                'commit':{'function':self.commit,
                                            'global': 1,
+                                           },
+                               'close':{'function':self.close,
+                                           'global': 1,
                                            }
                                }
  
    #
    # Convert some deprecated options to new style
    #
***************
*** 500,511 ****
        block.processRollback(recover)
      self.refreshDisplay(self)
      self._currentBlock.jumpRecord(self._currentBlock._currentRecord)
!     
    #
    # fireTrigger
    #
    def fireTrigger(self, triggerName):
!     self._triggerDictionary[triggerName](self)
  
  #
  # Updated methods for the new gnue-forms code
--- 500,512 ----
        block.processRollback(recover)
      self.refreshDisplay(self)
      self._currentBlock.jumpRecord(self._currentBlock._currentRecord)
! 
    #
    # fireTrigger
    #
    def fireTrigger(self, triggerName):
!     print "[GFForm] firing trigger %s" % triggerName
!     self._triggerDictionary[triggerName](self, globalns = 
self._triggerNamespace.getRuntimeGlobals())
  
  #
  # Updated methods for the new gnue-forms code
***************
*** 692,695 ****
--- 693,702 ----
    def triggerSetStatusText(self,tip=''):
      
self.dispatchEvent(GFEvent('uiUPDATESTATUS',[tip,None,None,None,None,None,None]))
  
+   # Close this form.
+   def close(self):
+     event = GFEvent('requestEXIT')
+     self._app.dispatchEvent(event)
+     if event.__error__:
+       return 1
  
Index: gnue/forms/src/GFInstance.py
diff -c gnue/forms/src/GFInstance.py:1.57 gnue/forms/src/GFInstance.py:1.58
*** gnue/forms/src/GFInstance.py:1.57   Tue Sep 10 11:30:50 2002
--- gnue/forms/src/GFInstance.py        Sun Oct 20 14:55:49 2002
***************
*** 366,372 ****
        message = GFMsgBox(self, _('Data not saved. Save changes or clear the 
form to proceed.'))
        message.show()
      else:
!       # If above loop didn't cause function to return then exit
        self.dispatchEvent(GFEvent('exitApplication',_('Current data is 
saved')))
  
      return
--- 366,372 ----
        message = GFMsgBox(self, _('Data not saved. Save changes or clear the 
form to proceed.'))
        message.show()
      else:
!       self._form.processTrigger('On-Exit')
        self.dispatchEvent(GFEvent('exitApplication',_('Current data is 
saved')))
  
      return
Index: gnue/forms/src/GFTrigger.py
diff -c gnue/forms/src/GFTrigger.py:1.60 gnue/forms/src/GFTrigger.py:1.61
*** gnue/forms/src/GFTrigger.py:1.60    Sat Sep 28 00:26:10 2002
--- gnue/forms/src/GFTrigger.py Sun Oct 20 14:55:49 2002
***************
*** 13,19 ****
  #
  # You should have received a copy of the GNU General Public 
  # License along with program; see the file COPYING. If not,
! # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
  # Copyright 2000-2002 Free Software Foundation
--- 13,19 ----
  #
  # You should have received a copy of the GNU General Public 
  # License along with program; see the file COPYING. If not,
! # write to the Free Software Foundation, Inc., 59 Temple Place
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
  # Copyright 2000-2002 Free Software Foundation
***************
*** 51,57 ****
                    'PRE-DELETE':     'Pre-Delete',
                    'PRE-MODIFY':     'Pre-Modify',
                    'ON-NEWRECORD':   'On-NewRecord',
!                   'ON-STARTUP':     'On-Startup' }
  
  #
  # GFTriggerAware
--- 51,58 ----
                    'PRE-DELETE':     'Pre-Delete',
                    'PRE-MODIFY':     'Pre-Modify',
                    'ON-NEWRECORD':   'On-NewRecord',
!                   'ON-STARTUP':     'On-Startup',
!                   'ON-EXIT':        'On-Exit' }
  
  #
  # GFTriggerAware
***************
*** 108,117 ****
  ##      GContent(self, text)
  ##    if self.type != None:
  ##      self._buildObject()
!       
!   def initialize(self): 
      self._root = self.findParentOfType('GFForm')
!     GTrigger.initialize(self)
  
  
  
--- 109,118 ----
  ##      GContent(self, text)
  ##    if self.type != None:
  ##      self._buildObject()
! 
!   def initialize(self, *args, **parms):
      self._root = self.findParentOfType('GFForm')
!     GTrigger.initialize(self, *args, **parms)
  
  
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]