summaryrefslogtreecommitdiff
path: root/grc/src
diff options
context:
space:
mode:
authorjblum2008-08-29 20:55:06 +0000
committerjblum2008-08-29 20:55:06 +0000
commitf1b6dd89d43ddf896e5b6dd0df0e43f0e35308f1 (patch)
treed423a93c0cee7f08875be6311991d01c89225d96 /grc/src
parenteb5c6240718e57d6dc81be48cd29f7f3241625d3 (diff)
downloadgnuradio-f1b6dd89d43ddf896e5b6dd0df0e43f0e35308f1.tar.gz
gnuradio-f1b6dd89d43ddf896e5b6dd0df0e43f0e35308f1.tar.bz2
gnuradio-f1b6dd89d43ddf896e5b6dd0df0e43f0e35308f1.zip
separated controls and variables generation, removed evaluation dependency on variables extraction
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9450 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc/src')
-rw-r--r--grc/src/grc_gnuradio/FlowGraph.py27
-rw-r--r--grc/src/grc_gnuradio/Generator.py3
2 files changed, 21 insertions, 9 deletions
diff --git a/grc/src/grc_gnuradio/FlowGraph.py b/grc/src/grc_gnuradio/FlowGraph.py
index 42783aab3..e9e876bbe 100644
--- a/grc/src/grc_gnuradio/FlowGraph.py
+++ b/grc/src/grc_gnuradio/FlowGraph.py
@@ -24,6 +24,22 @@ from grc.elements.FlowGraph import FlowGraph as _FlowGraph
from Block import Block
from Connection import Connection
+def get_variable_code(variable):
+ """!
+ Get the code representation for a variable.
+ Normally this is the value parameter.
+ For the variable chooser, use the index and choices.
+ Avoid using the to_code method of the variables,
+ as this forces evaluation before the variables are evaluated.
+ @param variable the variable block
+ @return the code string
+ """
+ if variable.get_key() == 'variable_chooser':
+ choices = variable.get_param('choices').get_value()
+ value_index = variable.get_param('value_index').get_value()
+ return "(%s)[%s]"%(choices, value_index)
+ return variable.get_param('value').get_value()
+
class FlowGraph(_FlowGraph):
def _get_io_signature(self, pad_key):
@@ -87,9 +103,7 @@ class FlowGraph(_FlowGraph):
id2var = dict([(var.get_id(), var) for var in variables])
#map var id to variable code
#variable code is a concatenation of all param code (without the id param)
- id2expr = dict([(var.get_id(),
- ' '.join([param.to_code() for param in filter(lambda p: p.get_key() != 'id', var.get_params())])
- ) for var in variables])
+ id2expr = dict([(var.get_id(), get_variable_code(var)) for var in variables])
#sort according to dependency
sorted_ids = expr_utils.sort_variables(id2expr)
#create list of sorted variable blocks
@@ -130,12 +144,7 @@ class FlowGraph(_FlowGraph):
#load variables
for variable in self.get_variables():
try:
- if variable.get_key() == 'variable_chooser':
- choices = variable.get_param('choices').to_code()
- value_index = variable.get_param('value_index').to_code()
- e = eval("%s[%s]"%(choices, value_index), n, n)
- else:
- e = eval(variable.get_param('value').to_code(), n, n)
+ e = eval(get_variable_code(variable), n, n)
n[variable.get_id()] = e
except: pass
#make namespace public
diff --git a/grc/src/grc_gnuradio/Generator.py b/grc/src/grc_gnuradio/Generator.py
index 70e174ca8..2c84edb3f 100644
--- a/grc/src/grc_gnuradio/Generator.py
+++ b/grc/src/grc_gnuradio/Generator.py
@@ -76,6 +76,8 @@ class Generator(object):
imports = self._flow_graph.get_imports()
variables = self._flow_graph.get_variables()
parameters = self._flow_graph.get_parameters()
+ #list of variables with controls
+ controls = filter(lambda v: v.get_key().startswith('variable_'), variables)
#list of blocks not including variables and imports and parameters and disabled
blocks = sorted(self._flow_graph.get_enabled_blocks(), lambda x, y: cmp(x.get_id(), y.get_id()))
blocks = filter(lambda b: b not in (imports + parameters + variables), blocks)
@@ -117,6 +119,7 @@ class Generator(object):
'imports': imports,
'flow_graph': self._flow_graph,
'variables': variables,
+ 'controls': controls,
'parameters': parameters,
'blocks': blocks,
'connections': connections,