diff options
author | jblum | 2009-07-06 02:28:52 +0000 |
---|---|---|
committer | jblum | 2009-07-06 02:28:52 +0000 |
commit | 25c5d91fb7c4b54f1e7d77fd9af213a3675a8339 (patch) | |
tree | 317d2e623aa9de602197089dab6dcc4fbb17da6f /grc/python | |
parent | a6396abe127c504f890d0cd45171c46ebfbb0f3d (diff) | |
download | gnuradio-25c5d91fb7c4b54f1e7d77fd9af213a3675a8339.tar.gz gnuradio-25c5d91fb7c4b54f1e7d77fd9af213a3675a8339.tar.bz2 gnuradio-25c5d91fb7c4b54f1e7d77fd9af213a3675a8339.zip |
Merged r11309:11357 from grc branch.
Adds notebook cabability to grc and its wxgui windows/controls.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11358 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc/python')
-rw-r--r-- | grc/python/Block.py | 4 | ||||
-rw-r--r-- | grc/python/FlowGraph.py | 11 | ||||
-rw-r--r-- | grc/python/Generator.py | 9 | ||||
-rw-r--r-- | grc/python/Param.py | 36 | ||||
-rw-r--r-- | grc/python/expr_utils.py | 16 | ||||
-rw-r--r-- | grc/python/flow_graph.tmpl | 32 |
6 files changed, 75 insertions, 33 deletions
diff --git a/grc/python/Block.py b/grc/python/Block.py index 6d7595777..957fee18e 100644 --- a/grc/python/Block.py +++ b/grc/python/Block.py @@ -130,7 +130,7 @@ class Block(_Block): return '\n'.join([doc, extract_docs.extract(self.get_key())]).strip('\n') def get_category(self): - #category = extract_category.extract(self.get_key()) + category = extract_category.extract(self.get_key()) #if category: return category return _Block.get_category(self) @@ -154,6 +154,6 @@ class Block(_Block): """ def make_callback(callback): callback = self.resolve_dependencies(callback) - if callback.startswith('self.'): return callback + if 'self.' in callback: return callback return 'self.%s.%s'%(self.get_id(), callback) return map(make_callback, self._callbacks) diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py index 47089a305..8cad8be49 100644 --- a/grc/python/FlowGraph.py +++ b/grc/python/FlowGraph.py @@ -99,16 +99,7 @@ class FlowGraph(_FlowGraph): @return a sorted list of variable blocks in order of dependency (indep -> dep) """ variables = filter(lambda b: _variable_matcher.match(b.get_key()), self.get_enabled_blocks()) - #map var id to variable block - 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(), var.get_var_make()) for var in variables]) - #sort according to dependency - sorted_ids = expr_utils.sort_variables(id2expr) - #create list of sorted variable blocks - variables = [id2var[id] for id in sorted_ids] - return variables + return expr_utils.sort_objects(variables, lambda v: v.get_id(), lambda v: v.get_var_make()) def get_parameters(self): """ diff --git a/grc/python/Generator.py b/grc/python/Generator.py index cde7dc3d4..33be4a726 100644 --- a/grc/python/Generator.py +++ b/grc/python/Generator.py @@ -90,7 +90,13 @@ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''') #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())) probes = filter(lambda b: b.get_key().startswith('probe_'), blocks) #ensure probes are last in the block list - blocks = filter(lambda b: b not in (imports + parameters + variables + probes), blocks) + probes + #get a list of notebooks and sort them according dependencies + notebooks = expr_utils.sort_objects( + filter(lambda b: b.get_key() == 'notebook', blocks), + lambda n: n.get_id(), lambda n: n.get_param('notebook').get_value(), + ) + #list of regular blocks (all blocks minus the special ones) + blocks = filter(lambda b: b not in (imports + parameters + variables + probes + notebooks), blocks) + probes #list of connections where each endpoint is enabled connections = self._flow_graph.get_enabled_connections() #list of variable names @@ -113,6 +119,7 @@ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''') 'imports': imports, 'flow_graph': self._flow_graph, 'variables': variables, + 'notebooks': notebooks, 'controls': controls, 'parameters': parameters, 'blocks': blocks, diff --git a/grc/python/Param.py b/grc/python/Param.py index 8b5efc97f..f971d0c3f 100644 --- a/grc/python/Param.py +++ b/grc/python/Param.py @@ -30,7 +30,7 @@ import re from gnuradio import gr _check_id_matcher = re.compile('^[a-z|A-Z]\w*$') -_show_id_matcher = re.compile('^(variable\w*|parameter|options)$') +_show_id_matcher = re.compile('^(variable\w*|parameter|options|notebook)$') class FileParam(EntryParam): """Provide an entry box for filename and a button to browse for a file.""" @@ -95,7 +95,8 @@ class Param(_Param): 'hex', 'string', 'bool', 'file_open', 'file_save', 'id', - 'grid_pos', 'import', + 'grid_pos', 'notebook', + 'import', ] def __repr__(self): @@ -103,6 +104,7 @@ class Param(_Param): Get the repr (nice string format) for this param. @return the string representation """ + if not self.is_valid(): return self.get_value() if self.get_value() in self.get_option_keys(): return self.get_option(self.get_value()).get_name() ################################################## # display logic for numbers @@ -171,6 +173,7 @@ class Param(_Param): 'string': Constants.BYTE_VECTOR_COLOR_SPEC, 'id': Constants.ID_COLOR_SPEC, 'grid_pos': Constants.INT_VECTOR_COLOR_SPEC, + 'notebook': Constants.INT_VECTOR_COLOR_SPEC, 'raw': Constants.WILDCARD_COLOR_SPEC, }[self.get_type()] except: return _Param.get_color(self) @@ -201,7 +204,7 @@ class Param(_Param): return 'part' except: pass #hide empty grid positions - if self.get_key() == 'grid_pos' and not self.get_value(): return 'part' + if self.get_key() in ('grid_pos', 'notebook') and not self.get_value(): return 'part' return hide def validate(self): @@ -331,17 +334,38 @@ class Param(_Param): #check row span, col span try: assert row_span > 0 and col_span > 0 except AssertionError: raise Exception, 'Row and column span must be greater than zero.' + #get hostage cell parent + try: my_parent = self.get_parent().get_param('notebook').evaluate() + except: my_parent = '' #calculate hostage cells for r in range(row_span): for c in range(col_span): - self._hostage_cells.append((row+r, col+c)) + self._hostage_cells.append((my_parent, (row+r, col+c))) #avoid collisions params = filter(lambda p: p is not self, self.get_all_params('grid_pos')) for param in params: - for cell in param._hostage_cells: - if cell in self._hostage_cells: raise Exception, 'Another graphical element is using cell "%s".'%str(cell) + for parent, cell in param._hostage_cells: + if (parent, cell) in self._hostage_cells: + raise Exception, 'Another graphical element is using parent "%s", cell "%s".'%(str(parent), str(cell)) return e ######################### + # Notebook Page Type + ######################### + elif t == 'notebook': + if not v: return '' #allow for empty notebook + #get a list of all notebooks + notebook_blocks = filter(lambda b: b.get_key() == 'notebook', self.get_parent().get_parent().get_enabled_blocks()) + #check for notebook param syntax + try: notebook_id, page_index = map(str.strip, v.split(',')) + except: raise Exception, 'Bad notebook page format.' + #check that the notebook id is valid + try: notebook_block = filter(lambda b: b.get_id() == notebook_id, notebook_blocks)[0] + except: raise Exception, 'Notebook id "%s" is not an existing notebook id.'%notebook_id + #check that page index exists + try: assert int(page_index) in range(len(notebook_block.get_param('labels').get_evaluated())) + except: raise Exception, 'Page index "%s" is not a valid index number.'%page_index + return notebook_id, page_index + ######################### # Import Type ######################### elif t == 'import': diff --git a/grc/python/expr_utils.py b/grc/python/expr_utils.py index 1bee22497..3c39f5d89 100644 --- a/grc/python/expr_utils.py +++ b/grc/python/expr_utils.py @@ -133,5 +133,21 @@ def sort_variables(exprs): for var in indep_vars: var_graph.remove_node(var) return reversed(sorted_vars) +def sort_objects(objects, get_id, get_expr): + """ + Sort a list of objects according to their expressions. + @param objects the list of objects to sort + @param get_id the function to extract an id from the object + @param get_expr the function to extract an expression from the object + @return a list of sorted objects + """ + id2obj = dict([(get_id(obj), obj) for obj in objects]) + #map obj id to expression code + id2expr = dict([(get_id(obj), get_expr(obj)) for obj in objects]) + #sort according to dependency + sorted_ids = sort_variables(id2expr) + #return list of sorted objects + return [id2obj[id] for id in sorted_ids] + if __name__ == '__main__': for i in sort_variables({'x':'1', 'y':'x+1', 'a':'x+y', 'b':'y+1', 'c':'a+b+x+y'}): print i diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl index 742ceb944..a94e45e8e 100644 --- a/grc/python/flow_graph.tmpl +++ b/grc/python/flow_graph.tmpl @@ -5,6 +5,7 @@ ##@param imports the import statements ##@param flow_graph the flow_graph ##@param variables the variable blocks +##@param notebooks a list of notebook blocks ##@param controls the variables with gui controls ##@param parameters the paramater blocks ##@param blocks the signal blocks @@ -52,13 +53,11 @@ $imp class $(class_name)(grc_wxgui.top_block_gui): def __init__($param_str): - grc_wxgui.top_block_gui.__init__( - self, - title="$title", + grc_wxgui.top_block_gui.__init__(self, title="$title") #if $icon - icon="$icon.get_filename()", + _icon_path = "$icon.get_filename()" + self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) #end if - ) #elif $generate_options == 'no_gui' class $(class_name)(gr.top_block): @@ -71,8 +70,7 @@ class $(class_name)(gr.hier_block2): def __init__($param_str): gr.hier_block2.__init__( - self, - "$title", + self, "$title", gr.io_signature($in_sig.nports, $in_sig.nports, $in_sig.size*$in_sig.vlen), gr.io_signature($out_sig.nports, $out_sig.nports, $out_sig.size*$out_sig.vlen), ) @@ -92,8 +90,6 @@ class $(class_name)(gr.hier_block2): #end for ######################################################## ##Create Variables -## Set the variable to a property of self. -## Write the first line of the variable make. ######################################################## #if $variables @@ -105,9 +101,19 @@ class $(class_name)(gr.hier_block2): $indent($var.get_var_make()) #end for ######################################################## +##Create Notebooks +######################################################## +#if $notebooks + + $DIVIDER + # Notebooks + $DIVIDER +#end if +#for $notebook in $notebooks + $indent($notebook.get_make()) +#end for +######################################################## ##Create Controls -## Write the variable make (excluding first line). -## Indent each line with 2 tabs. ######################################################## #if $controls @@ -120,7 +126,6 @@ class $(class_name)(gr.hier_block2): #end for ######################################################## ##Create Blocks -## Write the block make, and indent with 2 tabs. ######################################################## #if $blocks @@ -161,7 +166,6 @@ class $(class_name)(gr.hier_block2): ######################################################## ##Create Callbacks ## Write a set method for this variable that calls the callbacks -## and sets the direct variable dependencies. ######################################################## #for $var in $parameters + $variables #set $id = $var.get_id() @@ -196,7 +200,7 @@ if __name__ == '__main__': #end if tb = $(class_name)($(', '.join($params_eq_list))) #if $generate_options == 'wx_gui' - tb.Run($flow_graph.get_option('autostart')) + tb.Run($flow_graph.get_option('run')) #elif $generate_options == 'no_gui' tb.start() raw_input('Press Enter to quit: ') |