]> git.gag.com Git - debian/gnuradio/commitdiff
separated controls and variables generation, removed evaluation dependency on variabl...
authorjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 29 Aug 2008 20:55:06 +0000 (20:55 +0000)
committerjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 29 Aug 2008 20:55:06 +0000 (20:55 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9450 221aa14e-8319-0410-a670-987f0aec2ac5

grc/data/grc_gnuradio/flow_graph.tmpl
grc/src/grc_gnuradio/FlowGraph.py
grc/src/grc_gnuradio/Generator.py

index 932aa42ec4681ebdd32727ebbdfb46afc81f9a66..90ef3bbaeb9929c4497765cb2acec5f6494d61c1 100644 (file)
@@ -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
index 42783aab3e1c5aaa9c6ea4783a4ad3d5dc546766..e9e876bbe41913bbbd7af5bf976ca36deaa814ec 100644 (file)
@@ -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
index 70e174ca8e9351d46e260ef99b8b0871a149ae13..2c84edb3fe6fc510ee739abad9bed5b6e601b3ca 100644 (file)
@@ -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,