diff options
Diffstat (limited to 'grc/python')
-rw-r--r-- | grc/python/Block.py | 13 | ||||
-rw-r--r-- | grc/python/Connection.py | 6 | ||||
-rw-r--r-- | grc/python/Constants.py | 6 | ||||
-rw-r--r-- | grc/python/FlowGraph.py | 31 | ||||
-rw-r--r-- | grc/python/Generator.py | 46 | ||||
-rw-r--r-- | grc/python/Param.py | 102 | ||||
-rw-r--r-- | grc/python/Platform.py | 4 | ||||
-rw-r--r-- | grc/python/Port.py | 21 | ||||
-rw-r--r-- | grc/python/convert_hier.py | 14 | ||||
-rw-r--r-- | grc/python/expr_utils.py | 6 | ||||
-rw-r--r-- | grc/python/extract_docs.py | 6 | ||||
-rw-r--r-- | grc/python/flow_graph.tmpl | 72 |
12 files changed, 179 insertions, 148 deletions
diff --git a/grc/python/Block.py b/grc/python/Block.py index bd03eb5cd..14a5859e4 100644 --- a/grc/python/Block.py +++ b/grc/python/Block.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009 Free Software Foundation, Inc. +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -65,9 +65,8 @@ class Block(_Block, _GUIBlock): for check in self._checks: check_res = self.resolve_dependencies(check) try: - check_eval = self.get_parent().evaluate(check_res) - try: assert check_eval - except AssertionError: self.add_error_message('Check "%s" failed.'%check) + 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) def rewrite(self): @@ -134,9 +133,9 @@ class Block(_Block, _GUIBlock): try: value = param.get_evaluated() value = value + direction - assert 0 < value - param.set_value(value) - changed = True + if 0 < value: + param.set_value(value) + changed = True except: pass return changed diff --git a/grc/python/Connection.py b/grc/python/Connection.py index edc18841a..39f915740 100644 --- a/grc/python/Connection.py +++ b/grc/python/Connection.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009 Free Software Foundation, Inc. +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -38,5 +38,5 @@ class Connection(_Connection, _GUIConnection): #check vector length source_vlen = self.get_source().get_vlen() sink_vlen = self.get_sink().get_vlen() - try: assert source_vlen == sink_vlen - except AssertionError: self.add_error_message('Source vector length "%s" does not match sink vector length "%s".'%(source_vlen, sink_vlen)) + if source_vlen != sink_vlen: + self.add_error_message('Source vector length "%s" does not match sink vector length "%s".'%(source_vlen, sink_vlen)) diff --git a/grc/python/Constants.py b/grc/python/Constants.py index e661c3927..868c822aa 100644 --- a/grc/python/Constants.py +++ b/grc/python/Constants.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009 Free Software Foundation, Inc. +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -23,10 +23,8 @@ from gnuradio import gr _gr_prefs = gr.prefs() -PYEXEC = os.environ.get('PYTHONW', _gr_prefs.get_string('grc', 'pythonw', '')) - #setup paths -PATH_SEP = ':' +PATH_SEP = {'/':':', '\\':';'}[os.path.sep] DOCS_DIR = os.environ.get('GR_DOC_DIR', _gr_prefs.get_string('grc', 'doc_dir', '')) HIER_BLOCKS_LIB_DIR = os.path.join(os.path.expanduser('~'), '.grc_gnuradio') BLOCKS_DIRS = filter( #filter blank strings diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py index b2d406bbd..89a169355 100644 --- a/grc/python/FlowGraph.py +++ b/grc/python/FlowGraph.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009 Free Software Foundation, Inc. +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -48,15 +48,16 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph): #return from cache return self._eval_cache[my_hash] - def _get_io_signaturev(self, pad_key): + def get_io_signaturev(self, direction): """ Get a list of io signatures for this flow graph. - The pad key determines the directionality of the io signature. - @param pad_key a string of pad_source or pad_sink + @param direction a string of 'in' or 'out' @return a list of dicts with: type, label, vlen, size """ - pads = filter(lambda b: b.get_key() == pad_key, self.get_enabled_blocks()) - sorted_pads = sorted(pads, lambda x, y: cmp(x.get_id(), y.get_id())) + sorted_pads = { + 'in': self.get_pad_sources(), + 'out': self.get_pad_sinks(), + }[direction] #load io signature return [{ 'label': str(pad.get_param('label').get_evaluated()), @@ -65,19 +66,21 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph): 'size': pad.get_param('type').get_opt('size'), } for pad in sorted_pads] - def get_input_signaturev(self): + def get_pad_sources(self): """ - Get the io signature for the input side of this flow graph. - @return a list of io signature structures + Get a list of pad source blocks sorted by id order. + @return a list of pad source blocks in this flow graph """ - return self._get_io_signaturev('pad_source') + pads = filter(lambda b: b.get_key() == 'pad_source', self.get_enabled_blocks()) + return sorted(pads, lambda x, y: cmp(x.get_id(), y.get_id())) - def get_output_signaturev(self): + def get_pad_sinks(self): """ - Get the io signature for the output side of this flow graph. - @return a list of io signature structures + Get a list of pad sink blocks sorted by id order. + @return a list of pad sink blocks in this flow graph """ - return self._get_io_signaturev('pad_sink') + pads = filter(lambda b: b.get_key() == 'pad_sink', self.get_enabled_blocks()) + return sorted(pads, lambda x, y: cmp(x.get_id(), y.get_id())) def get_imports(self): """ diff --git a/grc/python/Generator.py b/grc/python/Generator.py index acd98ef84..b31f0a009 100644 --- a/grc/python/Generator.py +++ b/grc/python/Generator.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009, 2010 Free Software Foundation, Inc. +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -18,14 +18,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ import os +import sys import subprocess import tempfile from Cheetah.Template import Template import expr_utils from Constants import \ TOP_BLOCK_FILE_MODE, HIER_BLOCK_FILE_MODE, \ - HIER_BLOCKS_LIB_DIR, PYEXEC, \ - FLOW_GRAPH_TEMPLATE + HIER_BLOCKS_LIB_DIR, FLOW_GRAPH_TEMPLATE import convert_hier from .. gui import Messages @@ -58,7 +58,7 @@ class Generator(object): def write(self): #do throttle warning all_keys = ' '.join(map(lambda b: b.get_key(), self._flow_graph.get_enabled_blocks())) - if ('usrp' not in all_keys) and ('audio' not in all_keys) and ('throttle' not in all_keys) and self._generate_options != 'hb': + if ('usrp' not in all_keys) and ('uhd' not in all_keys) and ('audio' not in all_keys) and ('throttle' not in all_keys) and self._generate_options != 'hb': Messages.send_warning('''\ This flow graph may not have flow control: no audio or usrp blocks found. \ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''') @@ -74,10 +74,20 @@ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''') Execute this python flow graph. @return a popen object """ - #execute - cmds = [PYEXEC, '-u', self.get_file_path()] #-u is unbuffered stdio - if self._generate_options == 'no_gui': + #extract the path to the python executable + python_exe = sys.executable + + #when using wx gui on mac os, execute with pythonw + if self._generate_options == 'wx_gui' and 'darwin' in sys.platform.lower(): + python_exe += 'w' + + #setup the command args to run + cmds = [python_exe, '-u', self.get_file_path()] #-u is unbuffered stdio + + #when in no gui mode on linux, use an xterm (looks nice) + if self._generate_options == 'no_gui' and 'linux' in sys.platform.lower(): cmds = ['xterm', '-e'] + cmds + p = subprocess.Popen(args=cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, universal_newlines=True) return p @@ -90,18 +100,20 @@ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''') 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_make(), 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())) - probes = filter(lambda b: b.get_key().startswith('probe_'), blocks) #ensure probes are last in the block list - #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(), + def _get_block_sort_text(block): + code = block.get_make().replace(block.get_id(), ' ') + try: code += block.get_param('notebook').get_value() #older gui markup w/ wxgui + except: pass + try: code += block.get_param('gui_hint').get_value() #newer gui markup w/ qtgui + except: pass + return code + blocks = expr_utils.sort_objects( + self._flow_graph.get_enabled_blocks(), + lambda b: b.get_id(), _get_block_sort_text ) #list of regular blocks (all blocks minus the special ones) - blocks = filter(lambda b: b not in (imports + parameters + variables + probes + notebooks), blocks) + probes + blocks = filter(lambda b: b not in (imports + parameters), blocks) #list of connections where each endpoint is enabled connections = filter(lambda c: not c.is_msg(), self._flow_graph.get_enabled_connections()) messages = filter(lambda c: c.is_msg(), self._flow_graph.get_enabled_connections()) @@ -125,8 +137,6 @@ 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, 'connections': connections, diff --git a/grc/python/Param.py b/grc/python/Param.py index 6dd008d1d..5536138c1 100644 --- a/grc/python/Param.py +++ b/grc/python/Param.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009, 2010 Free Software Foundation, Inc. +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -99,7 +99,7 @@ class Param(_Param, _GUIParam): 'hex', 'string', 'bool', 'file_open', 'file_save', 'id', 'stream_id', - 'grid_pos', 'notebook', + 'grid_pos', 'notebook', 'gui_hint', 'import', ) @@ -213,8 +213,7 @@ class Param(_Param, _GUIParam): lambda p: p._vlen, self.get_parent().get_ports()) ): try: - assert int(self.get_evaluated()) == 1 - return 'part' + if int(self.get_evaluated()) == 1: return 'part' except: pass #hide empty grid positions if self.get_key() in ('grid_pos', 'notebook') and not self.get_value(): return 'part' @@ -244,8 +243,7 @@ class Param(_Param, _GUIParam): def eval_string(v): try: e = self.get_parent().get_parent().evaluate(v) - assert isinstance(e, str) - return e + if isinstance(e, str): return e except: self._stringify_flag = True return v @@ -265,21 +263,21 @@ class Param(_Param, _GUIParam): #raise an exception if the data is invalid if t == 'raw': return e elif t == 'complex': - try: assert isinstance(e, COMPLEX_TYPES) - except AssertionError: raise Exception, 'Expression "%s" is invalid for type complex.'%str(e) + if not isinstance(e, COMPLEX_TYPES): + raise Exception, 'Expression "%s" is invalid for type complex.'%str(e) return e elif t == 'real': - try: assert isinstance(e, REAL_TYPES) - except AssertionError: raise Exception, 'Expression "%s" is invalid for type real.'%str(e) + if not isinstance(e, REAL_TYPES): + raise Exception, 'Expression "%s" is invalid for type real.'%str(e) return e elif t == 'int': - try: assert isinstance(e, INT_TYPES) - except AssertionError: raise Exception, 'Expression "%s" is invalid for type integer.'%str(e) + if not isinstance(e, INT_TYPES): + raise Exception, 'Expression "%s" is invalid for type integer.'%str(e) return e elif t == 'hex': return hex(e) elif t == 'bool': - try: assert isinstance(e, bool) - except AssertionError: raise Exception, 'Expression "%s" is invalid for type bool.'%str(e) + if not isinstance(e, bool): + raise Exception, 'Expression "%s" is invalid for type bool.'%str(e) return e else: raise TypeError, 'Type "%s" not handled'%t ######################### @@ -295,25 +293,22 @@ class Param(_Param, _GUIParam): if not isinstance(e, VECTOR_TYPES): self._lisitify_flag = True e = [e] - try: - for ei in e: assert isinstance(ei, COMPLEX_TYPES) - except AssertionError: raise Exception, 'Expression "%s" is invalid for type complex vector.'%str(e) + if not all([isinstance(ei, COMPLEX_TYPES) for ei in e]): + raise Exception, 'Expression "%s" is invalid for type complex vector.'%str(e) return e elif t == 'real_vector': if not isinstance(e, VECTOR_TYPES): self._lisitify_flag = True e = [e] - try: - for ei in e: assert isinstance(ei, REAL_TYPES) - except AssertionError: raise Exception, 'Expression "%s" is invalid for type real vector.'%str(e) + if not all([isinstance(ei, REAL_TYPES) for ei in e]): + raise Exception, 'Expression "%s" is invalid for type real vector.'%str(e) return e elif t == 'int_vector': if not isinstance(e, VECTOR_TYPES): self._lisitify_flag = True e = [e] - try: - for ei in e: assert isinstance(ei, INT_TYPES) - except AssertionError: raise Exception, 'Expression "%s" is invalid for type integer vector.'%str(e) + if not all([isinstance(ei, INT_TYPES) for ei in e]): + raise Exception, 'Expression "%s" is invalid for type integer vector.'%str(e) return e ######################### # String Types @@ -327,13 +322,13 @@ class Param(_Param, _GUIParam): ######################### elif t == 'id': #can python use this as a variable? - try: assert _check_id_matcher.match(v) - except AssertionError: raise Exception, 'ID "%s" must begin with a letter and may contain letters, numbers, and underscores.'%v + if not _check_id_matcher.match(v): + raise Exception, 'ID "%s" must begin with a letter and may contain letters, numbers, and underscores.'%v ids = [param.get_value() for param in self.get_all_params(t)] - try: assert ids.count(v) <= 1 #id should only appear once, or zero times if block is disabled - except: raise Exception, 'ID "%s" is not unique.'%v - try: assert v not in ID_BLACKLIST - except: raise Exception, 'ID "%s" is blacklisted.'%v + if ids.count(v) > 1: #id should only appear once, or zero times if block is disabled + raise Exception, 'ID "%s" is not unique.'%v + if v in ID_BLACKLIST: + raise Exception, 'ID "%s" is blacklisted.'%v return v ######################### # Stream ID Type @@ -346,30 +341,51 @@ class Param(_Param, _GUIParam): )] #check that the virtual sink's stream id is unique if self.get_parent().is_virtual_sink(): - try: assert ids.count(v) <= 1 #id should only appear once, or zero times if block is disabled - except: raise Exception, 'Stream ID "%s" is not unique.'%v + if ids.count(v) > 1: #id should only appear once, or zero times if block is disabled + raise Exception, 'Stream ID "%s" is not unique.'%v #check that the virtual source's steam id is found if self.get_parent().is_virtual_source(): - try: assert v in ids - except: raise Exception, 'Stream ID "%s" is not found.'%v + if v not in ids: + raise Exception, 'Stream ID "%s" is not found.'%v return v ######################### + # GUI Position/Hint + ######################### + elif t == 'gui_hint': + if ':' in v: tab, pos = v.split(':') + elif '@' in v: tab, pos = v, '' + else: tab, pos = '', v + + if '@' in tab: tab, index = tab.split('@') + else: index = '?' + + widget_str = ({ + (True, True): 'self.%(tab)s_grid_layout_%(index)s.addWidget(%(widget)s, %(pos)s)', + (True, False): 'self.%(tab)s_layout_%(index)s.addWidget(%(widget)s)', + (False, True): 'self.top_grid_layout.addWidget(%(widget)s, %(pos)s)', + (False, False): 'self.top_layout.addWidget(%(widget)s)', + }[bool(tab), bool(pos)])%{'tab': tab, 'index': index, 'widget': '%s', 'pos': pos} + + def gui_hint(ws, w): + if 'layout' in w: ws = ws.replace('addWidget', 'addLayout') + return ws%w + + return lambda w: gui_hint(widget_str, w) + ######################### # Grid Position Type ######################### elif t == 'grid_pos': if not v: return '' #allow for empty grid pos e = self.get_parent().get_parent().evaluate(v) - try: - assert isinstance(e, (list, tuple)) and len(e) == 4 - for ei in e: assert isinstance(ei, int) - except AssertionError: raise Exception, 'A grid position must be a list of 4 integers.' + if not isinstance(e, (list, tuple)) or len(e) != 4 or not all([isinstance(ei, int) for ei in e]): + raise Exception, 'A grid position must be a list of 4 integers.' row, col, row_span, col_span = e #check row, col - try: assert row >= 0 and col >= 0 - except AssertionError: raise Exception, 'Row and column must be non-negative.' + if row < 0 or col < 0: + raise Exception, 'Row and column must be non-negative.' #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.' + if row_span <= 0 or col_span <= 0: + 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 = '' @@ -398,8 +414,8 @@ class Param(_Param, _GUIParam): 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').evaluate())) - except: raise Exception, 'Page index "%s" is not a valid index number.'%page_index + if int(page_index) not in range(len(notebook_block.get_param('labels').evaluate())): + raise Exception, 'Page index "%s" is not a valid index number.'%page_index return notebook_id, page_index ######################### # Import Type diff --git a/grc/python/Platform.py b/grc/python/Platform.py index 04db0b9b0..a9c2b18ad 100644 --- a/grc/python/Platform.py +++ b/grc/python/Platform.py @@ -1,5 +1,5 @@ -""" -Copyright 2008, 2009, 2010 Free Software Foundation, Inc. +__doc__ = """ +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or diff --git a/grc/python/Port.py b/grc/python/Port.py index 6e5a5c59f..3846b0f4e 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009 Free Software Foundation, Inc. +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -83,16 +83,16 @@ class Port(_Port, _GUIPort): def validate(self): _Port.validate(self) - try: assert self.get_enabled_connections() or self.get_optional() - except AssertionError: self.add_error_message('Port is not connected.') - try: assert self.is_source() or len(self.get_enabled_connections()) <= 1 - except AssertionError: self.add_error_message('Port has too many connections.') + if not self.get_enabled_connections() and not self.get_optional(): + self.add_error_message('Port is not connected.') + if not self.is_source() and len(self.get_enabled_connections()) > 1: + self.add_error_message('Port has too many connections.') #message port logic if self.get_type() == 'msg': - try: assert not self.get_nports() - except AssertionError: self.add_error_message('A port of type "msg" cannot have "nports" set.') - try: assert self.get_vlen() == 1 - except AssertionError: self.add_error_message('A port of type "msg" must have a "vlen" of 1.') + if self.get_nports(): + self.add_error_message('A port of type "msg" cannot have "nports" set.') + if self.get_vlen() != 1: + self.add_error_message('A port of type "msg" must have a "vlen" of 1.') def rewrite(self): """ @@ -134,8 +134,7 @@ class Port(_Port, _GUIPort): if not nports: return '' try: nports = int(self.get_parent().get_parent().evaluate(nports)) - assert 0 < nports - return nports + if 0 < nports: return nports except: return 1 def get_optional(self): return bool(self._optional) diff --git a/grc/python/convert_hier.py b/grc/python/convert_hier.py index befddccea..c6ca5b769 100644 --- a/grc/python/convert_hier.py +++ b/grc/python/convert_hier.py @@ -1,5 +1,5 @@ """ -Copyright 2008 Free Software Foundation, Inc. +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -23,11 +23,11 @@ from .. base import odict def convert_hier(flow_graph, python_file): #extract info from the flow graph - input_sigs = flow_graph.get_input_signaturev() - output_sigs = flow_graph.get_output_signaturev() + input_sigs = flow_graph.get_io_signaturev('in') + output_sigs = flow_graph.get_io_signaturev('out') parameters = flow_graph.get_parameters() block_key = flow_graph.get_option('id') - block_name = flow_graph.get_option('title') + block_name = flow_graph.get_option('title') or flow_graph.get_option('id').replace('_', ' ').title() block_category = flow_graph.get_option('category') block_desc = flow_graph.get_option('description') block_author = flow_graph.get_option('author') @@ -56,19 +56,21 @@ def convert_hier(flow_graph, python_file): params_n.append(param_n) block_n['param'] = params_n #sink data + block_n['sink'] = list() for input_sig in input_sigs: sink_n = odict() sink_n['name'] = input_sig['label'] sink_n['type'] = input_sig['type'] sink_n['vlen'] = input_sig['vlen'] - block_n['sink'] = sink_n + block_n['sink'].append(sink_n) #source data + block_n['source'] = list() for output_sig in output_sigs: source_n = odict() source_n['name'] = output_sig['label'] source_n['type'] = output_sig['type'] source_n['vlen'] = output_sig['vlen'] - block_n['source'] = source_n + block_n['source'].append(source_n) #doc data block_n['doc'] = "%s\n%s\n%s"%(block_author, block_desc, python_file) #write the block_n to file diff --git a/grc/python/expr_utils.py b/grc/python/expr_utils.py index 3c39f5d89..a2e56eedf 100644 --- a/grc/python/expr_utils.py +++ b/grc/python/expr_utils.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009 Free Software Foundation, Inc. +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -118,7 +118,7 @@ def sort_variables(exprs): Get a list of variables in order of dependencies. @param exprs a mapping of variable name to expression @return a list of variable names - @throws AssertionError circular dependencies + @throws Exception circular dependencies """ var_graph = get_graph(exprs) sorted_vars = list() @@ -126,7 +126,7 @@ def sort_variables(exprs): while var_graph.get_nodes(): #get a list of nodes with no edges indep_vars = filter(lambda var: not var_graph.get_edges(var), var_graph.get_nodes()) - assert indep_vars + if not indep_vars: raise Exception('circular dependency caught in sort_variables') #add the indep vars to the end of the list sorted_vars.extend(sorted(indep_vars)) #remove each edge-less node from the graph diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py index f41f415b2..aa85397f9 100644 --- a/grc/python/extract_docs.py +++ b/grc/python/extract_docs.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009 Free Software Foundation, Inc. +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -81,8 +81,8 @@ def extract(key): @param key the block key @return a string with documentation """ - try: assert _docs_cache.has_key(key) - except: _docs_cache[key] = _extract(key) + if not _docs_cache.has_key(key): + _docs_cache[key] = _extract(key) return _docs_cache[key] if __name__ == '__main__': diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl index a1a9308aa..d5e53b52b 100644 --- a/grc/python/flow_graph.tmpl +++ b/grc/python/flow_graph.tmpl @@ -5,8 +5,6 @@ ##@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 ##@param connections the connections @@ -59,14 +57,25 @@ class $(class_name)(grc_wxgui.top_block_gui): _icon_path = "$icon.get_filename()" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) #end if +#elif $generate_options == 'qt_gui' +class $(class_name)(gr.top_block, Qt.QWidget): + + def __init__($param_str): + gr.top_block.__init__(self, "$title") + Qt.QWidget.__init__(self) + self.setWindowTitle("$title") + self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) + self.top_layout = Qt.QVBoxLayout(self) + self.top_grid_layout = Qt.QGridLayout() + self.top_layout.addLayout(self.top_grid_layout) #elif $generate_options == 'no_gui' class $(class_name)(gr.top_block): def __init__($param_str): gr.top_block.__init__(self, "$title") #elif $generate_options == 'hb' - #set $in_sigs = $flow_graph.get_input_signaturev() - #set $out_sigs = $flow_graph.get_output_signaturev() + #set $in_sigs = $flow_graph.get_io_signaturev('in') + #set $out_sigs = $flow_graph.get_io_signaturev('out') class $(class_name)(gr.hier_block2): #def make_io_sig($io_sigs) #set $size_strs = ['%s*%s'%(io_sig['size'], io_sig['vlen']) for io_sig in $io_sigs] @@ -112,30 +121,6 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))]) $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 -######################################################## -#if $controls - - $DIVIDER - # Controls - $DIVIDER -#end if -#for $ctrl in $controls - $indent($ctrl.get_make()) -#end for -######################################################## ##Create Message Queues ######################################################## #if $messages @@ -157,18 +142,24 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))]) $DIVIDER #end if #for $blk in filter(lambda b: b.get_make(), $blocks) + #if $blk in $variables + $indent($blk.get_make()) + #else self.$blk.get_id() = $indent($blk.get_make()) + #end if #end for ######################################################## ##Create Connections ## The port name should be the id of the parent block. ## However, port names for IO pads should be self. ######################################################## -#def make_port_name($port) - #if $port.get_parent().get_key().startswith('pad_') -self#slurp +#def make_port_sig($port) + #if $port.get_parent().get_key() == 'pad_source' +(self, $flow_graph.get_pad_sources().index($port.get_parent()))#slurp + #elif $port.get_parent().get_key() == 'pad_sink' +(self, $flow_graph.get_pad_sinks().index($port.get_parent()))#slurp #else -self.$port.get_parent().get_id()#slurp +(self.$port.get_parent().get_id(), $port.get_key())#slurp #end if #end def #if $connections @@ -186,7 +177,7 @@ self.$port.get_parent().get_id()#slurp #end if ##do not generate connections with virtual sinks #if not $sink.get_parent().is_virtual_sink() - self.connect(($make_port_name($source), $source.get_key()), ($make_port_name($sink), $sink.get_key())) + self.connect($make_port_sig($source), $make_port_sig($sink)) #end if #end for @@ -196,6 +187,9 @@ self.$port.get_parent().get_id()#slurp ######################################################## #for $var in $parameters + $variables #set $id = $var.get_id() + def get_$(id)(self): + return self.$id + def set_$(id)(self, $id): self.$id = $id #for $callback in $var_id2cbs[$id] @@ -239,10 +233,20 @@ if __name__ == '__main__': if gr.enable_realtime_scheduling() != gr.RT_OK: print "Error: failed to enable realtime scheduling." #end if - tb = $(class_name)($(', '.join($params_eq_list))) #if $generate_options == 'wx_gui' + tb = $(class_name)($(', '.join($params_eq_list))) tb.Run($flow_graph.get_option('run')) + #elif $generate_options == 'qt_gui' + qapp = Qt.QApplication(sys.argv) + tb = $(class_name)($(', '.join($params_eq_list))) + #if $flow_graph.get_option('run') + tb.start() + #end if + tb.show() + qapp.exec_() + tb.stop() #elif $generate_options == 'no_gui' + tb = $(class_name)($(', '.join($params_eq_list))) #set $run_options = $flow_graph.get_option('run_options') #if $run_options == 'prompt' tb.start() |