work on a special connect function that registers a callback
authorJosh Blum <josh@joshknows.com>
Wed, 7 Oct 2009 05:28:09 +0000 (22:28 -0700)
committerJosh Blum <josh@joshknows.com>
Wed, 7 Oct 2009 05:28:09 +0000 (22:28 -0700)
gr-wxgui/src/python/common.py
gr-wxgui/src/python/fftsink_gl.py

index f355fd3ce6d91e4deecf19529702d672674f327c..09ce4471944d1d04b80aa4904618ee994376e473 100644 (file)
@@ -54,6 +54,26 @@ def bind_to_visible_event(win, callback):
                        win.Bind(wx.EVT_ACTIVATE, handler)
                win = win.GetParent()
 
+from gnuradio import gr
+
+def special_connect(source, sink, hb, win, size):
+       nulls = [gr.null_sink(size), gr.null_source(size)]
+       def callback(visible, init=False):
+               if not init: hb.lock()
+               if visible:
+                       if not init: hb.disconnect(source, nulls[0])
+                       if not init: hb.disconnect(nulls[1], sink)
+                       hb.connect(source, sink)
+                       #hb.connect(nulls[1], nulls[0])
+               else:
+                       if not init: hb.disconnect(source, sink)
+                       #if not init: hb.disconnect(nulls[1], nulls[0])
+                       hb.connect(source, nulls[0])
+                       hb.connect(nulls[1], sink)
+               if not init: hb.unlock()
+       callback(False, init=True) #initially connect
+       bind_to_visible_event(win, callback)
+
 #A macro to apply an index to a key
 index_key = lambda key, i: "%s_%d"%(key, i+1)
 
index 3f0a93fc8b3056fa34771ae998d17746d04a919e..4edb11b4aad72af99b4b1526ca06aec8b03901f0 100644 (file)
@@ -73,8 +73,6 @@ class _fft_sink_base(gr.hier_block2):
                )
                msgq = gr.msg_queue(2)
                sink = gr.message_sink(gr.sizeof_float*fft_size, msgq, True)
-               #connect
-               self.connect(self, fft, sink)
                #controller
                self.controller = pubsub()
                self.controller.subscribe(AVERAGE_KEY, fft.set_average)
@@ -106,6 +104,9 @@ class _fft_sink_base(gr.hier_block2):
                common.register_access_methods(self, self.win)
                setattr(self.win, 'set_baseband_freq', getattr(self, 'set_baseband_freq')) #BACKWARDS
                setattr(self.win, 'set_peak_hold', getattr(self, 'set_peak_hold')) #BACKWARDS
+               #connect
+               common.special_connect(self, fft, hb=self, win=self.win, size=self._item_size)
+               self.connect(fft, sink)
 
 class fft_sink_f(_fft_sink_base):
        _fft_chain = blks2.logpwrfft_f