commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 01/37: grc: design time values for object-l


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/37: grc: design time values for object-like variables
Date: Thu, 17 Jul 2014 20:23:39 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

trondeau pushed a commit to branch master
in repository gnuradio.

commit 81899991d0f658e943fcd6abd2a624aa4268b7d1
Author: Sebastian Koslowski <address@hidden>
Date:   Fri Jun 27 14:33:22 2014 +0200

    grc: design time values for object-like variables
---
 grc/base/Block.py       |  7 +++++--
 grc/python/Block.py     | 10 ++++++++++
 grc/python/FlowGraph.py |  2 +-
 grc/python/block.dtd    |  3 ++-
 4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/grc/base/Block.py b/grc/base/Block.py
index a14ffd9..a8a699f 100644
--- a/grc/base/Block.py
+++ b/grc/base/Block.py
@@ -77,6 +77,7 @@ class Block(Element):
         self._block_wrapper_path = n.find('block_wrapper_path')
         self._bussify_sink = n.find('bus_sink')
         self._bussify_source = n.find('bus_source')
+        self._var_value = n.find('var_value') or '$value'
 
         # get list of param tabs
         n_tabs = n.find('param_tab_order') or None
@@ -275,8 +276,10 @@ class Block(Element):
         tmpl = str(tmpl)
         if '$' not in tmpl: return tmpl
         n = dict((p.get_key(), TemplateArg(p)) for p in self.get_params())
-        try: return str(Template(tmpl, n))
-        except Exception, e: return "-------->\n%s: %s\n<--------"%(e, tmpl)
+        try:
+            return str(Template(tmpl, n))
+        except Exception as err:
+            return "Template error: %s\n    %s" % (tmpl, err)
 
     ##############################################
     # Controller Modify
diff --git a/grc/python/Block.py b/grc/python/Block.py
index 5dffcb3..21f4bad 100644
--- a/grc/python/Block.py
+++ b/grc/python/Block.py
@@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 02110-1301, USA
 
 from .. base.Block import Block as _Block
 from .. gui.Block import Block as _GUIBlock
+from . FlowGraph import _variable_matcher
 import extract_docs
 
 class Block(_Block, _GUIBlock):
@@ -90,6 +91,14 @@ class Block(_Block, _GUIBlock):
                 if not self.get_parent().evaluate(check_res):
                     self.add_error_message('Check "%s" failed.'%check)
             except: self.add_error_message('Check "%s" did not 
evaluate.'%check)
+        # for variables check the value (only if var_value is used
+        if _variable_matcher.match(self.get_key()) and self._var_value != 
'$value':
+            value = self._var_value
+            try:
+                value = self.get_var_value()
+                self.get_parent().evaluate(value)
+            except Exception as err:
+                self.add_error_message('Value "%s" cannot be evaluated:\n%s' % 
(value, err))
 
     def rewrite(self):
         """
@@ -169,6 +178,7 @@ class Block(_Block, _GUIBlock):
 
     def get_make(self): return self.resolve_dependencies(self._make)
     def get_var_make(self): return self.resolve_dependencies(self._var_make)
+    def get_var_value(self): return self.resolve_dependencies(self._var_value)
 
     def get_callbacks(self):
         """
diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py
index 8573f33..6d95db8 100644
--- a/grc/python/FlowGraph.py
+++ b/grc/python/FlowGraph.py
@@ -262,7 +262,7 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph):
             #load variables
             for variable in self.get_variables():
                 try:
-                    e = eval(variable.get_param('value').to_code(), n, n)
+                    e = eval(variable.get_var_value(), n, n)
                     n[variable.get_id()] = e
                 except: pass
             #make namespace public
diff --git a/grc/python/block.dtd b/grc/python/block.dtd
index 18e53fd..602339b 100644
--- a/grc/python/block.dtd
+++ b/grc/python/block.dtd
@@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 02110-1301, USA
     Top level element.
     A block contains a name, ...parameters list, and list of IO ports.
  -->
-<!ELEMENT block (name, key, category?, throttle?, import*, var_make?, make, 
callback*, param_tab_order?, param*, bus_sink?, bus_source?, check*, sink*, 
source*, bus_structure_sink?, bus_structure_source?, doc?,  grc_source?)>
+<!ELEMENT block (name, key, category?, throttle?, import*, var_make?, 
var_value?, make, callback*, param_tab_order?, param*, bus_sink?, bus_source?, 
check*, sink*, source*, bus_structure_sink?, bus_structure_source?, doc?,  
grc_source?)>
 <!--
     Sub level elements.
  -->
@@ -57,6 +57,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 02110-1301, USA
 <!ELEMENT bus_structure_sink (#PCDATA)>
 <!ELEMENT bus_structure_source (#PCDATA)>
 <!ELEMENT var_make (#PCDATA)>
+<!ELEMENT var_value (#PCDATA)>
 <!ELEMENT make (#PCDATA)>
 <!ELEMENT value (#PCDATA)>
 <!ELEMENT callback (#PCDATA)>



reply via email to

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