From 38d5389f3054164a2f04d6e4e8fe381aa5ee03fc Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 8 Oct 2009 21:46:53 -0700 Subject: [PATCH] using gr copy in the wxgui connect, added gr copy to grc xml --- gr-wxgui/src/python/common.py | 56 ++++++++++------------------- grc/blocks/Makefile.am | 1 + grc/blocks/block_tree.xml | 1 + grc/blocks/gr_copy.xml | 67 +++++++++++++++++++++++++++++++++++ grc/blocks/gr_kludge_copy.xml | 11 +++++- grc/blocks/gr_nop.xml | 9 +++++ 6 files changed, 107 insertions(+), 38 deletions(-) create mode 100644 grc/blocks/gr_copy.xml diff --git a/gr-wxgui/src/python/common.py b/gr-wxgui/src/python/common.py index 9bf3094f..fa11b315 100644 --- a/gr-wxgui/src/python/common.py +++ b/gr-wxgui/src/python/common.py @@ -30,7 +30,7 @@ class wxgui_hb(object): The wxgui hier block helper/wrapper class: A hier block should inherit from this class to make use of the wxgui connect method. To use, call wxgui_connect in place of regular connect; self.win must be defined. - The implementation will conditionally connect or disconnect the self (source) of the hb. + The implementation will conditionally enable the copy block after the source (self). This condition depends on weather or not the window is visible with the parent notebooks. This condition will be re-checked on every ui update event. """ @@ -45,47 +45,29 @@ class wxgui_hb(object): """ try: assert points[0] == self or points[0][0] == self - self._conditional_connect(points[0], points[1]) - if len(points[1:]) > 1: self.connect(*points[1:]) - except (AssertionError, IndexError): self.connect(*points) + copy = gr.copy(self._hb.input_signature().sizeof_stream_item(0)) + handler = self._handler_factory(copy.set_enabled) + handler(False) #initially disable the copy block + self._bind_to_visible_event(win=self.win, handler=handler) + points = list(points) + points.insert(1, copy) #insert the copy block into the chain + except (AssertionError, IndexError): pass + self.connect(*points) #actually connect the blocks - def _conditional_connect(self, source, sink): - """ - Create a handler for visibility changes. - Initially call the handler to setup the fg. - Bind the handler to the visibility meta event. - """ - handler = self._conditional_connect_handler_factory(source=source, sink=sink) - handler(False, init=True) #initially connect - self._bind_to_visible_event(win=self.win, handler=handler) - - def _conditional_connect_handler_factory(self, source, sink): + @staticmethod + def _handler_factory(handler): """ - Create a function that will handle the re-connections based on a flag. - The current state of the connection is stored in the namespace. - !!!#TODO This entire method could be replaced with a mute block that starves the stream. + Create a function that will cache the visibility flag, + and only call the handler when that flag changes. + @param handler the function to call on a change + @return a function of 1 argument """ - nulls = list() cache = [None] - size = self._hb.input_signature().sizeof_stream_item(0) - def callback(visible, init=False): - if visible == cache[0]: return + def callback(visible): + if cache[0] == visible: return cache[0] = visible - if not init: self.lock() - #print 'visible', visible, source, sink - if visible: - if not init: - self.disconnect(source, nulls[0]) - self.disconnect(nulls[1], nulls[2]) - self.disconnect(nulls[2], sink) - while nulls: nulls.pop() - self.connect(source, sink) - else: - if not init: self.disconnect(source, sink) - nulls.extend([gr.null_sink(size), gr.null_source(size), gr.head(size, 0)]) - self.connect(source, nulls[0]) - self.connect(nulls[1], nulls[2], sink) - if not init: self.unlock() + #print visible, handler + handler(visible) return callback @staticmethod diff --git a/grc/blocks/Makefile.am b/grc/blocks/Makefile.am index 617a3bf6..df347976 100644 --- a/grc/blocks/Makefile.am +++ b/grc/blocks/Makefile.am @@ -84,6 +84,7 @@ dist_ourdata_DATA = \ gr_complex_to_real.xml \ gr_conjugate_cc.xml \ gr_constellation_decoder_cb.xml \ + gr_copy.xml \ gr_correlate_access_code_bb.xml \ gr_costas_loop_cc.xml \ gr_cpfsk_bc.xml \ diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index 296f0ee9..6fec0be6 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -300,6 +300,7 @@ gr_skiphead gr_kludge_copy + gr_copy gr_nop xmlrpc_server diff --git a/grc/blocks/gr_copy.xml b/grc/blocks/gr_copy.xml new file mode 100644 index 00000000..757f1430 --- /dev/null +++ b/grc/blocks/gr_copy.xml @@ -0,0 +1,67 @@ + + + + Copy + gr_copy + from gnuradio import gr + gr.copy($type.size*$vlen) +self.$(id).set_enabled($enabled) + set_enabled($enabled) + + Type + type + enum + + + + + + + + Enabled + enabled + True + bool + + + Vec Length + vlen + 1 + int + + $vlen > 0 + + in + $type + $vlen + + + out + $type + $vlen + + diff --git a/grc/blocks/gr_kludge_copy.xml b/grc/blocks/gr_kludge_copy.xml index 3c817c57..8058b082 100644 --- a/grc/blocks/gr_kludge_copy.xml +++ b/grc/blocks/gr_kludge_copy.xml @@ -5,7 +5,7 @@ ################################################### --> - Copy + Kludge Copy gr_kludge_copy from gnuradio import gr gr.kludge_copy($type.size*$vlen) @@ -39,21 +39,30 @@ size:gr.sizeof_char + + Num Ports + num_ports + 1 + int + Vec Length vlen 1 int + $num_ports > 0 $vlen > 0 in $type $vlen + $num_ports out $type $vlen + $num_ports diff --git a/grc/blocks/gr_nop.xml b/grc/blocks/gr_nop.xml index 127a78a5..bd884d6b 100644 --- a/grc/blocks/gr_nop.xml +++ b/grc/blocks/gr_nop.xml @@ -39,21 +39,30 @@ size:gr.sizeof_char + + Num Ports + num_ports + 1 + int + Vec Length vlen 1 int + $num_ports > 0 $vlen > 0 in $type $vlen + $num_ports out $type $vlen + $num_ports -- 2.30.2