Removed the flagging api and usage from the base classes.
authorJosh Blum <josh@joshknows.com>
Wed, 2 Sep 2009 20:16:47 +0000 (13:16 -0700)
committerJosh Blum <josh@joshknows.com>
Wed, 2 Sep 2009 20:16:47 +0000 (13:16 -0700)
Far better to flag the namespace for renewing once in the flowgraph.py

grc/base/Element.py
grc/base/FlowGraph.py
grc/base/Param.py
grc/python/FlowGraph.py

index 87cedb37f71ae40f15dc39064a0e8c28685da81d..02b57df3a9ff267ef9dd685169a34bc89fd03223 100644 (file)
@@ -21,7 +21,6 @@ class Element(object):
 
        def __init__(self, parent=None):
                self._parent = parent
-               self.flag()
 
        def test(self):
                """
@@ -44,17 +43,6 @@ class Element(object):
 
        def get_parent(self): return self._parent
 
-       ##############################################
-       ## Update flagging
-       ##############################################
-       def is_flagged(self): return self._flag
-       def flag(self):
-               self._flag = True
-               if self.get_parent(): self.get_parent().flag()
-       def deflag(self):
-               self._flag = False
-               if self.get_parent(): self.get_parent().deflag()
-
        ##############################################
        ## Type testing methods
        ##############################################
index 9252f3668b43a2b303dd03b506f019a4c9cbf8ec..b24f13b092ba2196a1a40c8ffe6de92e34df4eb7 100644 (file)
@@ -102,7 +102,6 @@ class FlowGraph(Element):
                @param key the block key
                @return the new block or None if not found
                """
-               self.flag()
                if key not in self.get_parent().get_block_keys(): return None
                block = self.get_parent().get_new_block(self, key)
                self.get_elements().append(block)
@@ -116,7 +115,6 @@ class FlowGraph(Element):
                @throw Exception bad connection
                @return the new connection
                """
-               self.flag()
                connection = self.get_parent().Connection(flow_graph=self, porta=porta, portb=portb)
                self.get_elements().append(connection)
                return connection
@@ -128,7 +126,6 @@ class FlowGraph(Element):
                If the element is a block, remove its connections.
                If the element is a connection, just remove the connection.
                """
-               self.flag()
                if element not in self.get_elements(): return
                #found a port, set to parent signal block
                if element.is_port():
index 9279e736bbf3623f299e02bc5869bd2adfc5975e..eb7a57f514e5e16d2464c776a145f0fb2d00b533 100644 (file)
@@ -146,9 +146,7 @@ class Param(Element):
                        self.set_value(value)
                return value
 
-       def set_value(self, value):
-               self.flag()
-               self._value = str(value) #must be a string
+       def set_value(self, value): self._value = str(value) #must be a string
 
        def get_type(self): return self.get_parent().resolve_dependencies(self._type)
        def is_enum(self): return self._type == 'enum'
index 96188b8160ffac2dff3d05477d9c399fdfcba529..6b2936c7584a7824c4c747e887082b649edd3c04 100644 (file)
@@ -32,8 +32,8 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph):
        def __init__(self, **kwargs):
                _FlowGraph.__init__(self, **kwargs)
                _GUIFlowGraph.__init__(self)
+               self._eval_cache = dict()
 
-       _eval_cache = dict()
        def _eval(self, code, namespace, namespace_hash):
                """
                Evaluate the code with the given namespace.
@@ -114,6 +114,13 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph):
                parameters = filter(lambda b: _parameter_matcher.match(b.get_key()), self.get_enabled_blocks())
                return parameters
 
+       def rewrite(self):
+               """
+               Flag the namespace to be renewed.
+               """
+               self._renew_eval_ns = True
+               _FlowGraph.rewrite(self)
+
        def evaluate(self, expr):
                """
                Evaluate the expression.
@@ -121,8 +128,8 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph):
                @throw Exception bad expression
                @return the evaluated data
                """
-               if self.is_flagged():
-                       self.deflag()
+               if self._renew_eval_ns:
+                       self._renew_eval_ns = False
                        #reload namespace
                        n = dict()
                        #load imports