diff options
author | Tom Rondeau | 2011-05-08 19:58:43 +0100 |
---|---|---|
committer | Tom Rondeau | 2011-05-08 19:58:43 +0100 |
commit | a72bde633dda63c4471111894ca6b92a87318d5f (patch) | |
tree | c60e447e922b1a7076dd839ed8a94fcc9b665919 /grc | |
parent | bdd0bd405c2ea645395917c1abb91c964210c4d9 (diff) | |
parent | 207a2ae73bd5d6cab201bb57ed8db64fd54cfd90 (diff) | |
download | gnuradio-a72bde633dda63c4471111894ca6b92a87318d5f.tar.gz gnuradio-a72bde633dda63c4471111894ca6b92a87318d5f.tar.bz2 gnuradio-a72bde633dda63c4471111894ca6b92a87318d5f.zip |
Merge branch 'master' into 8psk
Diffstat (limited to 'grc')
31 files changed, 315 insertions, 180 deletions
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/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 096fdec41..a66c28ab9 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 @@ -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 @@ -91,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/blocks/Makefile.am b/grc/blocks/Makefile.am index 6f7802169..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 \ @@ -119,6 +120,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 \ @@ -147,6 +149,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/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 @@ <make>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 @@ <type>real</type> </param> <param> - <name>Costas Alpha</name> - <key>costas_alpha</key> - <value>0.175</value> + <name>FLL Alpha</name> + <key>freq_alpha</key> + <value>0.010</value> + <type>real</type> + </param> + <param> + <name>Phase Alpha</name> + <key>phase_alpha</key> + <value>0.100</value> <type>real</type> </param> <param> 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 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Polyphase Channelizer +################################################### + --> +<block> + <name>Polyphase Channelizer</name> + <key>blks2_pfb_channelizer_ccf</key> + <import>from gnuradio import blks2</import> + <import>from gnuradio.gr import firdes</import> + <make>blks2.pfb_channelizer_ccf( + $nchans, + $taps, + $osr, + $atten) + </make> + <!-- Set taps not implemented yet + <callback>set_taps($taps)</callback> + --> + <param> + <name>Channels</name> + <key>nchans</key> + <type>int</type> + </param> + <param> + <name>Taps</name> + <key>taps</key> + <value>None</value> + <type>real_vector</type> + </param> + <param> + <name>Over Sample Ratio</name> + <key>osr</key> + <value>1.0</value> + <type>real</type> + </param> + <param> + <name>Attenuation</name> + <key>atten</key> + <value>100</value> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>complex</type> + </sink> + <source> + <name>out</name> + <type>complex</type> + <nports>$nchans</nports> + </source> +</block> diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index 549ffbdbf..66094a80d 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -76,6 +76,8 @@ <block>gr_float_to_short</block> <block>gr_short_to_float</block> + <block>gr_int_to_float</block> + <block>gr_float_to_char</block> <block>gr_char_to_float</block> @@ -173,6 +175,8 @@ <block>blks2_analysis_filterbank</block> <!-- Polyphase filters --> <block>blks2_pfb_arb_resampler_ccf</block> + <block>blks2_pfb_channelizer_ccf</block> + <block>gr_pfb_synthesis_filterbank_ccf</block> <!-- Other filters --> <block>gr_single_pole_iir_filter_xx</block> <block>gr_hilbert_fc</block> 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 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Int to Float: +################################################### + --> +<block> + <name>Int To Float</name> + <key>gr_int_to_float</key> + <import>from gnuradio import gr</import> + <make>gr.int_to_float()</make> + <sink> + <name>in</name> + <type>int</type> + </sink> + <source> + <name>out</name> + <type>float</type> + </source> +</block> 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 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Polyphase Synthesis Filterbank +################################################### + --> +<block> + <name>Polyphase Synthesis Filterbank</name> + <key>gr_pfb_synthesis_filterbank_ccf</key> + <import>from gnuradio import gr</import> + <import>from gnuradio.gr import firdes</import> + <make>gr.pfb_synthesis_filterbank_ccf( + $numchans, $taps) + </make> + <callback>set_taps($taps)</callback> + + <param> + <name>Channels</name> + <key>numchans</key> + <value>2</value> + <type>int</type> + </param> + <param> + <name>Connections</name> + <key>connections</key> + <value>2</value> + <type>int</type> + </param> + <param> + <name>Taps</name> + <key>taps</key> + <type>real_vector</type> + </param> + <sink> + <name>in</name> + <type>complex</type> + <nports>$connections</nports> + </sink> + <source> + <name>out</name> + <type>complex</type> + </source> +</block> 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/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), 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 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 diff --git a/grc/python/Param.py b/grc/python/Param.py index 303ab3ed8..5536138c1 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,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,12 +341,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 +377,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 +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 ec3f94096..a9c2b18ad 100644 --- a/grc/python/Platform.py +++ b/grc/python/Platform.py @@ -1,5 +1,5 @@ -""" -Copyright 2008, 2009, 2010, 2011 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 e16e86f5b..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 @@ -242,6 +244,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') |