summaryrefslogtreecommitdiff
path: root/grc
diff options
context:
space:
mode:
authorjblum2008-08-29 20:55:06 +0000
committerjblum2008-08-29 20:55:06 +0000
commitf1b6dd89d43ddf896e5b6dd0df0e43f0e35308f1 (patch)
treed423a93c0cee7f08875be6311991d01c89225d96 /grc
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')
-rw-r--r--grc/data/grc_gnuradio/flow_graph.tmpl23
-rw-r--r--grc/src/grc_gnuradio/FlowGraph.py27
-rw-r--r--grc/src/grc_gnuradio/Generator.py3
3 files changed, 40 insertions, 13 deletions
diff --git a/grc/data/grc_gnuradio/flow_graph.tmpl b/grc/data/grc_gnuradio/flow_graph.tmpl
index 932aa42ec..90ef3bbae 100644
--- a/grc/data/grc_gnuradio/flow_graph.tmpl
+++ b/grc/data/grc_gnuradio/flow_graph.tmpl
@@ -5,6 +5,7 @@
##@param imports the import statements
##@param flow_graph the flow_graph
##@param variables the variable blocks
+##@param controls the variables with gui controls
##@param parameters the paramater blocks
##@param blocks the signal blocks
##@param connections the connections
@@ -83,7 +84,7 @@ class $(class_name)(gr.hier_block2):
########################################################
##Create Variables
## Set the variable to a property of self.
-## Write the variable make, and indent with 2 tabs.
+## Write the first line of the variable make.
########################################################
#if $variables
@@ -92,9 +93,23 @@ class $(class_name)(gr.hier_block2):
$DIVIDER
#end if
#for $var in $variables
- #set $code = '\n\t\t'.join($var.get_make().splitlines())
- $var.get_id() = $code
- self.$var.get_id() = $var.get_id()
+ #set $code = $var.get_make().splitlines()[0]
+ self.$var.get_id() = $var.get_id() = $code
+#end for
+########################################################
+##Create Controls
+## Write the variable make (excluding first line).
+## Indent each line with 2 tabs.
+########################################################
+#if $controls
+
+ $DIVIDER
+ # Controls
+ $DIVIDER
+#end if
+#for $ctrl in $controls
+ #set $code = '\n\t\t'.join($ctrl.get_make().splitlines()[1:])
+ $code
#end for
########################################################
##Create Blocks
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,