summaryrefslogtreecommitdiff
path: root/grc/python
diff options
context:
space:
mode:
authorSebastian Koslowski <koslowski@kit.edu>2014-06-27 14:33:22 +0200
committerSebastian Koslowski <koslowski@kit.edu>2014-07-04 08:57:35 +0200
commit81899991d0f658e943fcd6abd2a624aa4268b7d1 (patch)
tree2782c408b77cd3d27551bbc163e2603274359998 /grc/python
parentdf8695346d527692fc5c55ceaed299f3974fd84c (diff)
grc: design time values for object-like variables
Diffstat (limited to 'grc/python')
-rw-r--r--grc/python/Block.py10
-rw-r--r--grc/python/FlowGraph.py2
-rw-r--r--grc/python/block.dtd3
3 files changed, 13 insertions, 2 deletions
diff --git a/grc/python/Block.py b/grc/python/Block.py
index 5dffcb3124..21f4bad6cb 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 8573f33fc4..6d95db86e7 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 18e53fda2a..602339ba7c 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)>