From ec0edceb88e9603aedd4f6dd7a8a73702ce59547 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 9 Apr 2011 14:15:05 -0500 Subject: grc: added int to float support --- grc/blocks/Makefile.am | 1 + grc/blocks/block_tree.xml | 2 ++ grc/blocks/gr_int_to_float.xml | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 grc/blocks/gr_int_to_float.xml (limited to 'grc') diff --git a/grc/blocks/Makefile.am b/grc/blocks/Makefile.am index 6f7802169..fc2d3f161 100644 --- a/grc/blocks/Makefile.am +++ b/grc/blocks/Makefile.am @@ -119,6 +119,7 @@ dist_ourdata_DATA = \ gr_head.xml \ gr_hilbert_fc.xml \ gr_iir_filter_ffd.xml \ + gr_int_to_float.xml \ gr_integrate_xx.xml \ gr_interleave.xml \ gr_interleaved_short_to_complex.xml \ diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index 549ffbdbf..e7aa7c810 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -76,6 +76,8 @@ gr_float_to_short gr_short_to_float + gr_int_to_float + gr_float_to_char gr_char_to_float diff --git a/grc/blocks/gr_int_to_float.xml b/grc/blocks/gr_int_to_float.xml new file mode 100644 index 000000000..8e6d024e2 --- /dev/null +++ b/grc/blocks/gr_int_to_float.xml @@ -0,0 +1,20 @@ + + + + Int To Float + gr_int_to_float + from gnuradio import gr + gr.int_to_float() + + in + int + + + out + float + + -- cgit From 1046a3301307a2d2d5ab9c3279e78e89519be101 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 12 Apr 2011 16:24:15 -0400 Subject: Adding GRC block for the PFB synthesis filterbank. --- grc/blocks/Makefile.am | 1 + grc/blocks/block_tree.xml | 1 + grc/blocks/gr_pfb_synthesis_filterbank.xml | 43 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 grc/blocks/gr_pfb_synthesis_filterbank.xml (limited to 'grc') diff --git a/grc/blocks/Makefile.am b/grc/blocks/Makefile.am index fc2d3f161..d830a1bb4 100644 --- a/grc/blocks/Makefile.am +++ b/grc/blocks/Makefile.am @@ -148,6 +148,7 @@ dist_ourdata_DATA = \ gr_peak_detector2_fb.xml \ gr_peak_detector_xb.xml \ gr_pfb_clock_sync.xml \ + gr_pfb_synthesis_filterbank.xml \ gr_phase_modulator_fc.xml \ gr_pll_carriertracking_cc.xml \ gr_pll_freqdet_cf.xml \ diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index e7aa7c810..3eb56f82b 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -175,6 +175,7 @@ blks2_analysis_filterbank blks2_pfb_arb_resampler_ccf + gr_pfb_synthesis_filterbank_ccf gr_single_pole_iir_filter_xx gr_hilbert_fc diff --git a/grc/blocks/gr_pfb_synthesis_filterbank.xml b/grc/blocks/gr_pfb_synthesis_filterbank.xml new file mode 100644 index 000000000..a8b944c6a --- /dev/null +++ b/grc/blocks/gr_pfb_synthesis_filterbank.xml @@ -0,0 +1,43 @@ + + + + Polyphase Synthesis Filterbank + gr_pfb_synthesis_filterbank_ccf + from gnuradio import gr + from gnuradio.gr import firdes + gr.pfb_synthesis_filterbank_ccf( + $numchans, $taps) + + set_taps($taps) + + + Channels + numchans + 2 + int + + + Connections + connections + 2 + int + + + Taps + taps + real_vector + + + in + complex + $connections + + + out + complex + + -- cgit From 1c6d4023303198397e0a43f2f1c68877903f3b2f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 12 Apr 2011 16:30:46 -0400 Subject: Adding GRC block for the PFB channelizer filterbank. --- grc/blocks/Makefile.am | 1 + grc/blocks/blks2_pfb_channelizer.xml | 53 ++++++++++++++++++++++++++++++++++++ grc/blocks/block_tree.xml | 1 + 3 files changed, 55 insertions(+) create mode 100644 grc/blocks/blks2_pfb_channelizer.xml (limited to 'grc') diff --git a/grc/blocks/Makefile.am b/grc/blocks/Makefile.am index d830a1bb4..81eb81182 100644 --- a/grc/blocks/Makefile.am +++ b/grc/blocks/Makefile.am @@ -48,6 +48,7 @@ dist_ourdata_DATA = \ blks2_packet_decoder.xml \ blks2_packet_encoder.xml \ blks2_pfb_arb_resampler.xml \ + blks2_pfb_channelizer.xml \ blks2_qamx_demod.xml \ blks2_qamx_mod.xml \ blks2_rational_resampler_xxx.xml \ diff --git a/grc/blocks/blks2_pfb_channelizer.xml b/grc/blocks/blks2_pfb_channelizer.xml new file mode 100644 index 000000000..aee9dd512 --- /dev/null +++ b/grc/blocks/blks2_pfb_channelizer.xml @@ -0,0 +1,53 @@ + + + + Polyphase Channelizer + blks2_pfb_channelizer_ccf + from gnuradio import blks2 + from gnuradio.gr import firdes + blks2.pfb_channelizer_ccf( + $nchans, + $taps, + $osr, + $atten) + + + + Channels + nchans + int + + + Taps + taps + None + real_vector + + + Over Sample Ratio + osr + 1.0 + real + + + Attenuation + atten + 100 + real + + + in + complex + + + out + complex + $nchans + + diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index 3eb56f82b..66094a80d 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -175,6 +175,7 @@ blks2_analysis_filterbank blks2_pfb_arb_resampler_ccf + blks2_pfb_channelizer_ccf gr_pfb_synthesis_filterbank_ccf gr_single_pole_iir_filter_xx -- cgit From b7f8d86f0e0f022ad44fc5293ffc4cb52c85de20 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 12 Apr 2011 18:20:11 -0400 Subject: grc: fixing grc block for dxpsk2 demods to use the right parameters. --- grc/blocks/blks2_dxpsk2_demod.xml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'grc') diff --git a/grc/blocks/blks2_dxpsk2_demod.xml b/grc/blocks/blks2_dxpsk2_demod.xml index ce8305c50..7fe4be32b 100644 --- a/grc/blocks/blks2_dxpsk2_demod.xml +++ b/grc/blocks/blks2_dxpsk2_demod.xml @@ -11,7 +11,8 @@ blks2.$(type)2_demod( samples_per_symbol=$samples_per_symbol, excess_bw=$excess_bw, - costas_alpha=$costas_alpha, + freq_alpha=$freq_alpha, + phase_alpha=$phase_alpha, timing_alpha=$timing_alpha, timing_max_dev=$timing_max_dev, gray_code=$gray_code, @@ -48,9 +49,15 @@ real - Costas Alpha - costas_alpha - 0.175 + FLL Alpha + freq_alpha + 0.010 + real + + + Phase Alpha + phase_alpha + 0.100 real -- cgit From e762abc703e3224b54466685bf51b3fa90ee8edc Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 13 Apr 2011 22:18:12 -0700 Subject: grc: stop the top block after qapp exec for qtgui generation --- grc/python/flow_graph.tmpl | 1 + 1 file changed, 1 insertion(+) (limited to 'grc') diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl index e16e86f5b..7a74cf84c 100644 --- a/grc/python/flow_graph.tmpl +++ b/grc/python/flow_graph.tmpl @@ -242,6 +242,7 @@ if __name__ == '__main__': #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') -- cgit From 4f41cde8c65a76cfd74d40ec24b530ef3fe4a5f4 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 14 Apr 2011 09:37:27 -0700 Subject: grc: remove integrity checks, we wont need them when I'm done --- grc/base/Platform.py | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'grc') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index 096fdec41..0620cf21b 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -17,16 +17,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ -#Perform python integrity checks: -# GRC will not work with interpreters that fail the checks below. -# This can fail on interpreters built with special optimizations. -try: - assert False - raise Exception, 'Failed python integrity check: assert not supported' -except AssertionError: pass -if __doc__ is None: - raise Exception, 'Failed python integrity check: __doc__ not supported' - import os import sys from .. base import ParseXML, odict -- cgit From 8fb43aa9093fbbb5c9d8b9418c144dbf33730127 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 14 Apr 2011 09:39:07 -0700 Subject: grc: define __doc__ for license in case its optimized out (that was easy) --- grc/python/Platform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grc') diff --git a/grc/python/Platform.py b/grc/python/Platform.py index ec3f94096..54535965b 100644 --- a/grc/python/Platform.py +++ b/grc/python/Platform.py @@ -1,4 +1,4 @@ -""" +__doc__ = """ Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc. This file is part of GNU Radio -- cgit From 4cdd41c1046cef12601602bd38dc8ebf42d1550d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 14 Apr 2011 10:05:33 -0700 Subject: grc: replaced asserts in python subdirectory --- grc/base/Platform.py | 2 +- grc/python/Block.py | 13 ++++---- grc/python/Connection.py | 6 ++-- grc/python/Param.py | 78 ++++++++++++++++++++++------------------------ grc/python/Platform.py | 2 +- grc/python/Port.py | 21 ++++++------- grc/python/expr_utils.py | 6 ++-- grc/python/extract_docs.py | 6 ++-- 8 files changed, 64 insertions(+), 70 deletions(-) (limited to 'grc') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index 0620cf21b..a6d420799 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009, 2011 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 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/Param.py b/grc/python/Param.py index 303ab3ed8..f62a33550 100644 --- a/grc/python/Param.py +++ b/grc/python/Param.py @@ -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,25 @@ 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) + for ei in e: + if not isinstance(ei, COMPLEX_TYPES): + 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) + for ei in e: + if not isinstance(ei, REAL_TYPES): + 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) + for ei in e: + if not isinstance(ei, INT_TYPES): + raise Exception, 'Expression "%s" is invalid for type integer vector.'%str(e) return e ######################### # String Types @@ -327,13 +325,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,12 +344,12 @@ 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 @@ -382,17 +380,15 @@ class Param(_Param, _GUIParam): 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 = '' @@ -421,8 +417,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 54535965b..a9c2b18ad 100644 --- a/grc/python/Platform.py +++ b/grc/python/Platform.py @@ -1,5 +1,5 @@ __doc__ = """ -Copyright 2008, 2009, 2010, 2011 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 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/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__': -- cgit From 66d7b23402dd9c366bb6c824d693274ccf3868db Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 14 Apr 2011 10:40:36 -0700 Subject: grc: replaced asserts in base subdirectory --- grc/base/Block.py | 14 +++++++------- grc/base/Connection.py | 12 +++++++----- grc/base/FlowGraph.py | 20 ++++++++++++++------ grc/base/Param.py | 30 +++++++++++++++--------------- grc/base/Platform.py | 9 ++++----- grc/base/Port.py | 6 +++--- grc/base/odict.py | 8 ++++---- grc/python/Param.py | 15 ++++++--------- 8 files changed, 60 insertions(+), 54 deletions(-) (limited to 'grc') diff --git a/grc/base/Block.py b/grc/base/Block.py index 42eb6b3fb..fe7ad3c2f 100644 --- a/grc/base/Block.py +++ b/grc/base/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 @@ -92,8 +92,8 @@ class Block(Element): for param in map(lambda n: self.get_parent().get_parent().Param(block=self, n=n), params): key = param.get_key() #test against repeated keys - try: assert key not in self.get_param_keys() - except AssertionError: raise Exception, 'Key "%s" already exists in params'%key + if key in self.get_param_keys(): + raise Exception, 'Key "%s" already exists in params'%key #store the param self.get_params().append(param) #create the source objects @@ -101,8 +101,8 @@ class Block(Element): for source in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir='source'), sources): key = source.get_key() #test against repeated keys - try: assert key not in self.get_source_keys() - except AssertionError: raise Exception, 'Key "%s" already exists in sources'%key + if key in self.get_source_keys(): + raise Exception, 'Key "%s" already exists in sources'%key #store the port self.get_sources().append(source) #create the sink objects @@ -110,8 +110,8 @@ class Block(Element): for sink in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir='sink'), sinks): key = sink.get_key() #test against repeated keys - try: assert key not in self.get_sink_keys() - except AssertionError: raise Exception, 'Key "%s" already exists in sinks'%key + if key in self.get_sink_keys(): + raise Exception, 'Key "%s" already exists in sinks'%key #store the port self.get_sinks().append(sink) diff --git a/grc/base/Connection.py b/grc/base/Connection.py index 94d4751b2..3ce7fd07f 100644 --- a/grc/base/Connection.py +++ b/grc/base/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 @@ -37,10 +37,12 @@ class Connection(Element): for port in (porta, portb): if port.is_source(): source = port if port.is_sink(): sink = port - assert(source and sink) + if not source: raise ValueError('Connection could not isolate source') + if not sink: raise ValueError('Connection could not isolate sink') #ensure that this connection (source -> sink) is unique for connection in self.get_parent().get_connections(): - assert not (connection.get_source() is source and connection.get_sink() is sink) + if connection.get_source() is source and connection.get_sink() is sink: + raise Exception('This connection between source and sink is not unique.') self._source = source self._sink = sink @@ -62,8 +64,8 @@ class Connection(Element): Element.validate(self) source_type = self.get_source().get_type() sink_type = self.get_sink().get_type() - try: assert source_type == sink_type - except AssertionError: self.add_error_message('Source type "%s" does not match sink type "%s".'%(source_type, sink_type)) + if source_type != sink_type: + self.add_error_message('Source type "%s" does not match sink type "%s".'%(source_type, sink_type)) def get_enabled(self): """ diff --git a/grc/base/FlowGraph.py b/grc/base/FlowGraph.py index b4ac8fc3a..0ba1f2389 100644 --- a/grc/base/FlowGraph.py +++ b/grc/base/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 @@ -194,18 +194,26 @@ class FlowGraph(Element): sink_key = connection_n.find('sink_key') #verify the blocks block_ids = map(lambda b: b.get_id(), self.get_blocks()) - assert(source_block_id in block_ids) - assert(sink_block_id in block_ids) + if source_block_id not in block_ids: + raise LookupError('source block id "%s" not in block ids'%source_block_id) + if sink_block_id not in block_ids: + raise LookupError('sink block id "%s" not in block ids'%sink_block_id) #get the blocks source_block = self.get_block(source_block_id) sink_block = self.get_block(sink_block_id) #verify the ports - assert(source_key in source_block.get_source_keys()) - assert(sink_key in sink_block.get_sink_keys()) + if source_key not in source_block.get_source_keys(): + raise LookupError('source key "%s" not in source block keys'%source_key) + if sink_key not in sink_block.get_sink_keys(): + raise LookupError('sink key "%s" not in sink block keys'%sink_key) #get the ports source = source_block.get_source(source_key) sink = sink_block.get_sink(sink_key) #build the connection self.connect(source, sink) - except AssertionError: Messages.send_error_load('Connection between %s(%s) and %s(%s) could not be made.'%(source_block_id, source_key, sink_block_id, sink_key)) + except LookupError, e: Messages.send_error_load( + 'Connection between %s(%s) and %s(%s) could not be made.\n\t%s'%( + source_block_id, source_key, sink_block_id, sink_key, e + ) + ) self.rewrite() #global rewrite diff --git a/grc/base/Param.py b/grc/base/Param.py index 5cd0f9d6d..c2fa5461a 100644 --- a/grc/base/Param.py +++ b/grc/base/Param.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 @@ -34,16 +34,16 @@ class Option(Element): self._opts = dict() opts = n.findall('opt') #test against opts when non enum - try: assert self.get_parent().is_enum() or not opts - except AssertionError: raise Exception, 'Options for non-enum types cannot have sub-options' + if not self.get_parent().is_enum() and opts: + raise Exception, 'Options for non-enum types cannot have sub-options' #extract opts for opt in opts: #separate the key:value try: key, value = opt.split(':') except: raise Exception, 'Error separating "%s" into key:value'%opt #test against repeated keys - try: assert not self._opts.has_key(key) - except AssertionError: raise Exception, 'Key "%s" already exists in option'%key + if self._opts.has_key(key): + raise Exception, 'Key "%s" already exists in option'%key #store the option self._opts[key] = value @@ -79,24 +79,24 @@ class Param(Element): for option in map(lambda o: Option(param=self, n=o), n.findall('option')): key = option.get_key() #test against repeated keys - try: assert key not in self.get_option_keys() - except AssertionError: raise Exception, 'Key "%s" already exists in options'%key + if key in self.get_option_keys(): + raise Exception, 'Key "%s" already exists in options'%key #store the option self.get_options().append(option) #test the enum options if self.is_enum(): #test against options with identical keys - try: assert len(set(self.get_option_keys())) == len(self.get_options()) - except AssertionError: raise Exception, 'Options keys "%s" are not unique.'%self.get_option_keys() + if len(set(self.get_option_keys())) != len(self.get_options()): + raise Exception, 'Options keys "%s" are not unique.'%self.get_option_keys() #test against inconsistent keys in options opt_keys = self.get_options()[0].get_opt_keys() for option in self.get_options(): - try: assert set(opt_keys) == set(option.get_opt_keys()) - except AssertionError: raise Exception, 'Opt keys "%s" are not identical across all options.'%opt_keys + if set(opt_keys) != set(option.get_opt_keys()): + raise Exception, 'Opt keys "%s" are not identical across all options.'%opt_keys #if a value is specified, it must be in the options keys self._value = value if value or value in self.get_option_keys() else self.get_option_keys()[0] - try: assert self.get_value() in self.get_option_keys() - except AssertionError: raise Exception, 'The value "%s" is not in the possible values of "%s".'%(self.get_value(), self.get_option_keys()) + if self.get_value() not in self.get_option_keys(): + raise Exception, 'The value "%s" is not in the possible values of "%s".'%(self.get_value(), self.get_option_keys()) else: self._value = value or '' def validate(self): @@ -105,8 +105,8 @@ class Param(Element): The value must be evaluated and type must a possible type. """ Element.validate(self) - try: assert self.get_type() in self.get_types() - except AssertionError: self.add_error_message('Type "%s" is not a possible type.'%self.get_type()) + if self.get_type() not in self.get_types(): + self.add_error_message('Type "%s" is not a possible type.'%self.get_type()) def get_evaluated(self): raise NotImplementedError diff --git a/grc/base/Platform.py b/grc/base/Platform.py index a6d420799..a66c28ab9 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -81,13 +81,12 @@ class Platform(_Element): block = self.Block(self._flow_graph, n) key = block.get_key() #test against repeated keys - try: - assert key not in self.get_block_keys() - #store the block + if key in self.get_block_keys(): + print >> sys.stderr, 'Warning: Block with key "%s" already exists.\n\tIgnoring: %s'%(key, xml_file) + #store the block + else: self._blocks[key] = block self._blocks_n[key] = n - except AssertionError: - print >> sys.stderr, 'Warning: Block with key "%s" already exists.\n\tIgnoring: %s'%(key, xml_file) except ParseXML.XMLSyntaxError, e: try: #try to add the xml file as a block tree ParseXML.validate_dtd(xml_file, BLOCK_TREE_DTD) diff --git a/grc/base/Port.py b/grc/base/Port.py index 494ea894f..7a1b5d4e6 100644 --- a/grc/base/Port.py +++ b/grc/base/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 @@ -42,8 +42,8 @@ class Port(Element): The port must be non-empty and type must a possible type. """ Element.validate(self) - try: assert self.get_type() in self.get_types() - except AssertionError: self.add_error_message('Type "%s" is not a possible type.'%self.get_type()) + if self.get_type() not in self.get_types(): + self.add_error_message('Type "%s" is not a possible type.'%self.get_type()) def __str__(self): if self.is_source(): diff --git a/grc/base/odict.py b/grc/base/odict.py index ac3cb2070..044d04ad7 100644 --- a/grc/base/odict.py +++ b/grc/base/odict.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 @@ -55,7 +55,7 @@ class odict(DictMixin): @param val the value for the new entry """ index = (pos_key is None) and len(self._keys) or self._keys.index(pos_key) - assert key not in self._keys + if key in self._keys: raise KeyError('Cannot insert, key "%s" already exists'%str(key)) self._keys.insert(index+1, key) self._data[key] = val @@ -67,8 +67,8 @@ class odict(DictMixin): @param key the key for the new entry @param val the value for the new entry """ - index = (pos_key is not None) and self._keys.index(pos_key) or 0 - assert key not in self._keys + index = (pos_key is not None) and self._keys.index(pos_key) or 0 + if key in self._keys: raise KeyError('Cannot insert, key "%s" already exists'%str(key)) self._keys.insert(index, key) self._data[key] = val diff --git a/grc/python/Param.py b/grc/python/Param.py index f62a33550..5536138c1 100644 --- a/grc/python/Param.py +++ b/grc/python/Param.py @@ -293,25 +293,22 @@ class Param(_Param, _GUIParam): if not isinstance(e, VECTOR_TYPES): self._lisitify_flag = True e = [e] - for ei in e: - if not isinstance(ei, COMPLEX_TYPES): - 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] - for ei in e: - if not isinstance(ei, REAL_TYPES): - 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] - for ei in e: - if not isinstance(ei, INT_TYPES): - 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 -- cgit From af1d0a61d01c7c17dedcb5388ed8a077213d4b4f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 14 Apr 2011 10:49:23 -0700 Subject: grc: replaced asserts in gui subdirectory --- grc/gui/ActionHandler.py | 5 ++--- grc/gui/Actions.py | 5 +++-- grc/gui/FlowGraph.py | 10 +++++----- grc/gui/Utils.py | 5 +++-- 4 files changed, 13 insertions(+), 12 deletions(-) (limited to 'grc') diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index 350b297bb..15785f2ee 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -1,5 +1,5 @@ """ -Copyright 2007, 2008, 2009, 2011 Free Software Foundation, Inc. +Copyright 2007-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -78,8 +78,7 @@ class ActionHandler: When not in focus, gtk and the accelerators handle the the key press. @return false to let gtk handle the key action """ - try: assert self.get_focus_flag() - except AssertionError: return False + if not self.get_focus_flag(): return False return Actions.handle_key_press(event) def _quit(self, window, event): diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py index f374efde1..4d196477e 100644 --- a/grc/gui/Actions.py +++ b/grc/gui/Actions.py @@ -1,5 +1,5 @@ """ -Copyright 2007, 2008, 2009 Free Software Foundation, Inc. +Copyright 2007-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -76,7 +76,8 @@ class Action(gtk.Action): for i in range(len(keypresses)/2): keyval, mod_mask = keypresses[i*2:(i+1)*2] #register this keypress - assert not _actions_keypress_dict.has_key((keyval, mod_mask)) + if _actions_keypress_dict.has_key((keyval, mod_mask)): + raise KeyError('keyval/mod_mask pair already registered "%s"'%str((keyval, mod_mask))) _actions_keypress_dict[(keyval, mod_mask)] = self #set the accelerator group, and accelerator path #register the key name and mod mask with the accelerator path diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py index 897145a1d..9f3326ada 100644 --- a/grc/gui/FlowGraph.py +++ b/grc/gui/FlowGraph.py @@ -1,5 +1,5 @@ """ -Copyright 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +Copyright 2007-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -290,10 +290,10 @@ class FlowGraph(Element): for selected in selected_elements: if selected in elements: continue selected_elements.remove(selected) - try: assert self._old_selected_port.get_parent() in elements - except: self._old_selected_port = None - try: assert self._new_selected_port.get_parent() in elements - except: self._new_selected_port = None + if self._old_selected_port and self._old_selected_port.get_parent() not in elements: + self._old_selected_port = None + if self._new_selected_port and self._new_selected_port.get_parent() not in elements: + self._new_selected_port = None #update highlighting for element in elements: element.set_highlighted(element in selected_elements) diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py index b5489d56e..bb19ed3d9 100644 --- a/grc/gui/Utils.py +++ b/grc/gui/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 @@ -53,7 +53,8 @@ def get_rotated_coordinate(coor, rotation): """ #handles negative angles rotation = (rotation + 360)%360 - assert rotation in POSSIBLE_ROTATIONS + if rotation not in POSSIBLE_ROTATIONS: + raise ValueError('unusable rotation angle "%s"'%str(rotation)) #determine the number of degrees to rotate cos_r, sin_r = { 0: (1, 0), -- cgit From a92cb89b5529728d9fce781aff85916b3879fbdd Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 15 Apr 2011 13:09:55 -0700 Subject: grc: added logic to discover the path to the python interpreter Rather than simply exec-ing the application w/ "python", use the same interpreter that executed grc w/ full path. Added code to handle the following exceptions: - for a wx app on mac osx, use the pythonw interpreter (this was in the m4 file, but its easier as a runtime check) - for a no gui app on linux, prepend xterm cuz its nice (we were already doing that but its now restricted to linux) --- grc/Makefile.am | 1 - grc/grc.conf.in | 1 - grc/python/Constants.py | 6 ++---- grc/python/Generator.py | 20 +++++++++++++++----- 4 files changed, 17 insertions(+), 11 deletions(-) (limited to 'grc') diff --git a/grc/Makefile.am b/grc/Makefile.am index c36786281..9d473b4d3 100644 --- a/grc/Makefile.am +++ b/grc/Makefile.am @@ -43,7 +43,6 @@ BUILT_SOURCES += grc.conf grc.conf: $(srcdir)/grc.conf.in Makefile sed \ - -e 's|@pythonw[@]|$(PYTHONW)|g' \ -e 's|@blocksdir[@]|$(grc_blocksdir)|g' \ -e 's|@docdir[@]|$(gr_docdir)|g' \ $< > $@ diff --git a/grc/grc.conf.in b/grc/grc.conf.in index 37a049971..9363ca981 100644 --- a/grc/grc.conf.in +++ b/grc/grc.conf.in @@ -3,7 +3,6 @@ # ~/.gnuradio/config.conf [grc] -pythonw = @pythonw@ doc_dir = @docdir@ global_blocks_path = @blocksdir@ local_blocks_path = 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/Generator.py b/grc/python/Generator.py index b669fa65a..b31f0a009 100644 --- a/grc/python/Generator.py +++ b/grc/python/Generator.py @@ -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 @@ -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 -- cgit From a4ac44d7adbd9c6cdd107ec7985e294fea81845a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 21 Apr 2011 11:02:28 -0700 Subject: grc: fix hier block generation w/ multiple pad blocks --- grc/python/FlowGraph.py | 31 +++++++++++++++++-------------- grc/python/convert_hier.py | 14 ++++++++------ grc/python/flow_graph.tmpl | 16 +++++++++------- 3 files changed, 34 insertions(+), 27 deletions(-) (limited to 'grc') 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/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/flow_graph.tmpl b/grc/python/flow_graph.tmpl index 7a74cf84c..d5e53b52b 100644 --- a/grc/python/flow_graph.tmpl +++ b/grc/python/flow_graph.tmpl @@ -74,8 +74,8 @@ 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] @@ -153,11 +153,13 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))]) ## 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 @@ -175,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 -- cgit