commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8435 - trunk/gnue-common/src/logic


From: reinhard
Subject: [gnue] r8435 - trunk/gnue-common/src/logic
Date: Wed, 19 Apr 2006 08:10:00 -0500 (CDT)

Author: reinhard
Date: 2006-04-19 08:10:00 -0500 (Wed, 19 Apr 2006)
New Revision: 8435

Modified:
   trunk/gnue-common/src/logic/GTrigger.py
Log:
Further cleanup.


Modified: trunk/gnue-common/src/logic/GTrigger.py
===================================================================
--- trunk/gnue-common/src/logic/GTrigger.py     2006-04-19 12:39:24 UTC (rev 
8434)
+++ trunk/gnue-common/src/logic/GTrigger.py     2006-04-19 13:10:00 UTC (rev 
8435)
@@ -71,32 +71,32 @@
 class GTrigger(GObj):
 
     # -------------------------------------------------------------------------
+    # Attributes
+    # -------------------------------------------------------------------------
+
+    name = None
+    type = None
+    language = None
+    file = None
+    src = None
+
+
+    # -------------------------------------------------------------------------
     # Constructor
     # -------------------------------------------------------------------------
 
-    def __init__(self, parent=None, type=None, name=None, src=None, text=None,
-            language='python'):
+    def __init__(self, parent=None):
 
         GObj.__init__(self, parent, 'GCTrigger')
 
         self._xml_content_as_cdata_ = gConfig('StoreTriggersAsCDATA')
 
         self.__root = self.findParentOfType(None)
+        self.__function = None
 
-        self._inits = [None,self.initialize,self.initCall]
+        self._inits = [self.__initialize]
 
-        # FIXME: Is this for manually creating GTrigger instances? Is this used
-        # anywhere?
-        self.language=language
-        self.src = src
-        self.type = type and type.upper() or None
-        self.name = name
-        if text != None:
-            GContent(self, text)
-        if self.type != None:
-            self._buildObject()
 
-
     # -------------------------------------------------------------------------
     # Nice string representation
     # -------------------------------------------------------------------------
@@ -107,11 +107,10 @@
 
 
     # -------------------------------------------------------------------------
-    # Initialize
+    # Phase 1 initialization
     # -------------------------------------------------------------------------
 
-    def initialize(self):
-        self.__call__ = dummyFunction
+    def __initialize(self):
 
         if self.type != "NAMED":
             if self.getParent():
@@ -119,53 +118,42 @@
         else:
             self.__root._triggerDictionary[self.name] = self
 
-        # If the trigger code is given with the trigger, build the 
call-function
-        # right now. This way any referring trigger will find a propery 
function
         if self.src is None:
-            self.__set_function(self.getChildrenAsContent())
+            execution_context = language.create_execution_context(
+                    language = self.language,
+                    name = repr(self),
+                    local_namespace = {},
+                    global_namespace = self.__root._triggerns,
+                    builtin_namespace = {})
 
+            self.__function = execution_context.build_function(
+                    name = self.getDescription(),
+                    parameters = ['self'],
+                    code = self.getChildrenAsContent())
 
+
     # -------------------------------------------------------------------------
-    # Initialize the trigger's call function
+    # Run the trigger code
     # -------------------------------------------------------------------------
 
-    def initCall (self):
-        """
-        This function get's called in the trigger's phase II init and connectes
-        another's trigger's function to the call-method
-        """
+    def __call__(__self, *args, **params):
 
-        if self.src is not None:
-            self.__set_function_from(self.__root._triggerDictionary [self.src])
+        # We call our own self parameter "__self" here so that the user
+        # function can have a parameter "self".
 
+        if __self.src is not None:
+            __self.__root._triggerDictionary[__self.src](*args, **params)
+        elif __self.__function is not None:
+            __self.__function(*args, **params)
 
 
-    def __set_function_from(self, object):
-        self.__call__ = object.__call__
-
-
-    def __set_function(self, code):
-
-        execution_context = language.create_execution_context(
-                language = self.language,
-                name = repr(self),
-                local_namespace = {},
-                global_namespace = self.__root._triggerns,
-                builtin_namespace = {})
-
-        self.__call__ = execution_context.build_function(
-                name = self.getDescription(),
-                parameters = ['self'],
-                code = code)
-
     # -------------------------------------------------------------------------
     # Return a nice description of this object for designer
     # -------------------------------------------------------------------------
 
     def getDescription(self):
         """
-        Return a useful description of this object
-        for use by designer
+        Return a useful description of this object for use by designer
         """
         if self.type == 'NAMED':
             return self.name
@@ -173,14 +161,6 @@
             return string.upper(self.type)
 
 
-# -----------------------------------------------------------------------------
-# Dummy function for non-implemented triggers
-# -----------------------------------------------------------------------------
-
-def dummyFunction(self):
-    assert gDebug(1, "Trigger not implemented")
-
-
 # =============================================================================
 # Base class for all objects that can have triggers associated
 # =============================================================================
@@ -253,9 +233,6 @@
         Fire the requested trigger if a trigger of that type has been
         associated with this object.
 
-        B{Note:} You cannot fire a trigger before phase 3 of a gnue object
-        tree phased init.
-
         @param key: The name of the trigger.
         @type key: str
         @param ignoreAbort: If True (the default), then





reply via email to

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