using gr copy in the wxgui connect, added gr copy to grc xml
authorJosh Blum <josh@joshknows.com>
Fri, 9 Oct 2009 04:46:53 +0000 (21:46 -0700)
committerJosh Blum <josh@joshknows.com>
Fri, 9 Oct 2009 04:46:53 +0000 (21:46 -0700)
gr-wxgui/src/python/common.py
grc/blocks/Makefile.am
grc/blocks/block_tree.xml
grc/blocks/gr_copy.xml [new file with mode: 0644]
grc/blocks/gr_kludge_copy.xml
grc/blocks/gr_nop.xml

index 9bf3094f2eb46261511c16d27c223a229c788d24..fa11b3152fd358bc005226697faebe6857d05fbd 100644 (file)
@@ -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
index 617a3bf6085bd50f2f1b577d1c7fc404dd1fbe2d..df3479761a32d137d7e0267b5b42bc769ad1cb1b 100644 (file)
@@ -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 \
index 296f0ee911b505298cc893675656aa1cd88f74e1..6fec0be675871d9cbe4cc263100b289ee5107fca 100644 (file)
                <block>gr_skiphead</block>
 
                <block>gr_kludge_copy</block>
+               <block>gr_copy</block>
                <block>gr_nop</block>
 
                <block>xmlrpc_server</block>
diff --git a/grc/blocks/gr_copy.xml b/grc/blocks/gr_copy.xml
new file mode 100644 (file)
index 0000000..757f143
--- /dev/null
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Copy
+###################################################
+ -->
+<block>
+       <name>Copy</name>
+       <key>gr_copy</key>
+       <import>from gnuradio import gr</import>
+       <make>gr.copy($type.size*$vlen)
+self.$(id).set_enabled($enabled)</make>
+       <callback>set_enabled($enabled)</callback>
+       <param>
+               <name>Type</name>
+               <key>type</key>
+               <type>enum</type>
+               <option>
+                       <name>Complex</name>
+                       <key>complex</key>
+                       <opt>size:gr.sizeof_gr_complex</opt>
+               </option>
+               <option>
+                       <name>Float</name>
+                       <key>float</key>
+                       <opt>size:gr.sizeof_float</opt>
+               </option>
+               <option>
+                       <name>Int</name>
+                       <key>int</key>
+                       <opt>size:gr.sizeof_int</opt>
+               </option>
+               <option>
+                       <name>Short</name>
+                       <key>short</key>
+                       <opt>size:gr.sizeof_short</opt>
+               </option>
+               <option>
+                       <name>Byte</name>
+                       <key>byte</key>
+                       <opt>size:gr.sizeof_char</opt>
+               </option>
+       </param>
+       <param>
+               <name>Enabled</name>
+               <key>enabled</key>
+               <value>True</value>
+               <type>bool</type>
+       </param>
+       <param>
+               <name>Vec Length</name>
+               <key>vlen</key>
+               <value>1</value>
+               <type>int</type>
+       </param>
+       <check>$vlen &gt; 0</check>
+       <sink>
+               <name>in</name>
+               <type>$type</type>
+               <vlen>$vlen</vlen>
+       </sink>
+       <source>
+               <name>out</name>
+               <type>$type</type>
+               <vlen>$vlen</vlen>
+       </source>
+</block>
index 3c817c5726709402a6fe48152f7ab1864f6d2145..8058b082dbd370fa540a0cbe9f8dfb77e7b5a738 100644 (file)
@@ -5,7 +5,7 @@
 ###################################################
  -->
 <block>
-       <name>Copy</name>
+       <name>Kludge Copy</name>
        <key>gr_kludge_copy</key>
        <import>from gnuradio import gr</import>
        <make>gr.kludge_copy($type.size*$vlen)</make>
                        <opt>size:gr.sizeof_char</opt>
                </option>
        </param>
+       <param>
+               <name>Num Ports</name>
+               <key>num_ports</key>
+               <value>1</value>
+               <type>int</type>
+       </param>
        <param>
                <name>Vec Length</name>
                <key>vlen</key>
                <value>1</value>
                <type>int</type>
        </param>
+       <check>$num_ports &gt; 0</check>
        <check>$vlen &gt; 0</check>
        <sink>
                <name>in</name>
                <type>$type</type>
                <vlen>$vlen</vlen>
+               <nports>$num_ports</nports>
        </sink>
        <source>
                <name>out</name>
                <type>$type</type>
                <vlen>$vlen</vlen>
+               <nports>$num_ports</nports>
        </source>
 </block>
index 127a78a55364cfbc739fcc74ac6856e5acfeed22..bd884d6b8bff7f22f95d83c1a0361c4cd470ea15 100644 (file)
                        <opt>size:gr.sizeof_char</opt>
                </option>
        </param>
+       <param>
+               <name>Num Ports</name>
+               <key>num_ports</key>
+               <value>1</value>
+               <type>int</type>
+       </param>
        <param>
                <name>Vec Length</name>
                <key>vlen</key>
                <value>1</value>
                <type>int</type>
        </param>
+       <check>$num_ports &gt; 0</check>
        <check>$vlen &gt; 0</check>
        <sink>
                <name>in</name>
                <type>$type</type>
                <vlen>$vlen</vlen>
+               <nports>$num_ports</nports>
        </sink>
        <source>
                <name>out</name>
                <type>$type</type>
                <vlen>$vlen</vlen>
+               <nports>$num_ports</nports>
        </source>
 </block>