commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r10616 - in gnuradio/branches/releases/3.2: . gnuradio


From: jcorgan
Subject: [Commit-gnuradio] r10616 - in gnuradio/branches/releases/3.2: . gnuradio-core/src/python/gnuradio/gr gr-wxgui/src/python
Date: Sun, 15 Mar 2009 13:43:30 -0600 (MDT)

Author: jcorgan
Date: 2009-03-15 13:43:30 -0600 (Sun, 15 Mar 2009)
New Revision: 10616

Added:
   gnuradio/branches/releases/3.2/gnuradio-core/src/python/gnuradio/gr/pubsub.py
Modified:
   gnuradio/branches/releases/3.2/
   
gnuradio/branches/releases/3.2/gnuradio-core/src/python/gnuradio/gr/Makefile.am
   gnuradio/branches/releases/3.2/gr-wxgui/src/python/form.py
   gnuradio/branches/releases/3.2/gr-wxgui/src/python/gui.py
Log:
Applied changset r10573:10575, r10582 to release 3.2 branch.


Property changes on: gnuradio/branches/releases/3.2
___________________________________________________________________
Modified: svn:mergeinfo
   - /gnuradio/branches/developers/michaelld/two_mods:10540-10546
/gnuradio/trunk:10356-10359,10481-10482,10497-10499,10506-10507,10511,10514,10521,10523-10524,10529,10531,10535,10537-10538,10550-10551,10556,10558-10560,10562-10563,10565,10578-10579,10581,10585,10600
   + /gnuradio/branches/developers/michaelld/two_mods:10540-10546
/gnuradio/trunk:10356-10359,10481-10482,10497-10499,10506-10507,10511,10514,10521,10523-10524,10529,10531,10535,10537-10538,10550-10551,10556,10558-10560,10562-10563,10565,10574-10575,10578-10579,10581-10582,10585,10600

Modified: 
gnuradio/branches/releases/3.2/gnuradio-core/src/python/gnuradio/gr/Makefile.am
===================================================================
--- 
gnuradio/branches/releases/3.2/gnuradio-core/src/python/gnuradio/gr/Makefile.am 
    2009-03-15 19:41:59 UTC (rev 10615)
+++ 
gnuradio/branches/releases/3.2/gnuradio-core/src/python/gnuradio/gr/Makefile.am 
    2009-03-15 19:43:30 UTC (rev 10616)
@@ -40,7 +40,8 @@
        hier_block2.py          \
        prefs.py                \
        scheduler.py            \
-       top_block.py
+       top_block.py            \
+       pubsub.py
 
 noinst_PYTHON =                        \
        benchmark_filters.py            \

Copied: 
gnuradio/branches/releases/3.2/gnuradio-core/src/python/gnuradio/gr/pubsub.py 
(from rev 10575, gnuradio/trunk/gnuradio-core/src/python/gnuradio/gr/pubsub.py)
===================================================================
--- 
gnuradio/branches/releases/3.2/gnuradio-core/src/python/gnuradio/gr/pubsub.py   
                            (rev 0)
+++ 
gnuradio/branches/releases/3.2/gnuradio-core/src/python/gnuradio/gr/pubsub.py   
    2009-03-15 19:43:30 UTC (rev 10616)
@@ -0,0 +1,153 @@
+#!/usr/bin/env python
+#
+# Copyright 2008,2009 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+"""
+Abstract GNU Radio publisher/subscriber interface
+
+This is a proof of concept implementation, will likely change significantly.
+"""
+
+class pubsub(dict):
+    def __init__(self):
+       self._publishers = { }
+       self._subscribers = { }
+       self._proxies = { }
+       
+    def __missing__(self, key, value=None):
+       dict.__setitem__(self, key, value)
+       self._publishers[key] = None
+       self._subscribers[key] = []
+       self._proxies[key] = None
+       
+    def __setitem__(self, key, val):
+       if not self.has_key(key): 
+           self.__missing__(key, val)
+       elif self._proxies[key] is not None:
+           (p, newkey) = self._proxies[key]
+           p[newkey] = val
+       else:
+           dict.__setitem__(self, key, val)
+       for sub in self._subscribers[key]:
+           # Note this means subscribers will get called in the thread
+           # context of the 'set' caller.
+           sub(val)
+
+    def __getitem__(self, key):
+       if not self.has_key(key): self.__missing__(key)
+       if self._proxies[key] is not None:
+           (p, newkey) = self._proxies[key]
+           return p[newkey]
+       elif self._publishers[key] is not None:
+           return self._publishers[key]()
+       else:
+           return dict.__getitem__(self, key)
+
+    def publish(self, key, publisher):
+       if not self.has_key(key): self.__missing__(key)
+        if self._proxies[key] is not None:
+            (p, newkey) = self._proxies[key]
+            p.publish(newkey, publisher)
+        else:
+            self._publishers[key] = publisher
+       
+    def subscribe(self, key, subscriber):
+       if not self.has_key(key): self.__missing__(key)
+        if self._proxies[key] is not None:
+            (p, newkey) = self._proxies[key]
+            p.subscribe(newkey, subscriber)
+        else:
+            self._subscribers[key].append(subscriber)
+       
+    def unpublish(self, key):
+        if self._proxies[key] is not None:
+            (p, newkey) = self._proxies[key]
+            p.unpublish(newkey)
+        else:
+            self._publishers[key] = None
+       
+    def unsubscribe(self, key, subscriber):
+        if self._proxies[key] is not None:
+            (p, newkey) = self._proxies[key]
+            p.unsubscribe(newkey, subscriber)
+        else:
+            self._subscribers[key].remove(subscriber)
+
+    def proxy(self, key, p, newkey=None):
+       if not self.has_key(key): self.__missing__(key)
+       if newkey is None: newkey = key
+       self._proxies[key] = (p, newkey)        
+
+    def unproxy(self, key):
+        self._proxies[key] = None
+
+# Test code
+if __name__ == "__main__":
+    import sys
+    o = pubsub()
+
+    # Non-existent key gets auto-created with None value
+    print "Auto-created key 'foo' value:", o['foo']
+
+    # Add some subscribers
+    # First is a bare function
+    def print_len(x):
+       print "len=%i" % (len(x), )
+    o.subscribe('foo', print_len)
+
+    # The second is a class member function
+    class subber(object):
+       def __init__(self, param):
+           self._param = param
+       def printer(self, x):
+           print self._param, `x`
+    s = subber('param')
+    o.subscribe('foo', s.printer)
+
+    # The third is a lambda function
+    o.subscribe('foo', lambda x: sys.stdout.write('val='+`x`+'\n'))
+
+    # Update key 'foo', will notify subscribers    
+    print "Updating 'foo' with three subscribers:"
+    o['foo'] = 'bar';
+
+    # Remove first subscriber
+    o.unsubscribe('foo', print_len)
+
+    # Update now will only trigger second and third subscriber
+    print "Updating 'foo' after removing a subscriber:"
+    o['foo'] = 'bar2';
+    
+    # Publish a key as a function, in this case, a lambda function
+    o.publish('baz', lambda : 42)
+    print "Published value of 'baz':", o['baz']
+
+    # Unpublish the key
+    o.unpublish('baz')
+
+    # This will return None, as there is no publisher
+    print "Value of 'baz' with no publisher:", o['baz']
+    
+    # Set 'baz' key, it gets cached
+    o['baz'] = 'bazzz'
+
+    # Now will return cached value, since no provider
+    print "Cached value of 'baz' after being set:", o['baz']


Property changes on: 
gnuradio/branches/releases/3.2/gnuradio-core/src/python/gnuradio/gr/pubsub.py
___________________________________________________________________
Added: svn:mergeinfo
   + 
/gnuradio/branches/developers/michaelld/two_mods/gr-wxgui/src/python/pubsub.py:10540-10546
/gnuradio/trunk/gnuradio-core/src/python/gnuradio/gr/pubsub.py:10582

Modified: gnuradio/branches/releases/3.2/gr-wxgui/src/python/form.py
===================================================================
--- gnuradio/branches/releases/3.2/gr-wxgui/src/python/form.py  2009-03-15 
19:41:59 UTC (rev 10615)
+++ gnuradio/branches/releases/3.2/gr-wxgui/src/python/form.py  2009-03-15 
19:43:30 UTC (rev 10616)
@@ -263,7 +263,7 @@
 
 
 class radiobox_field(field):
-    def __init__(self, parent=None, sizer=None, label="", value=None,
+    def __init__(self, parent=None, sizer=None, label=None, value=None,
                  converter=identity_converter(), callback=None, weight=1,
                  choices=None, major_dimension=1, specify_rows=False):
         new_id = wx.NewId()
@@ -273,9 +273,9 @@
         else:
             style=wx.RA_SPECIFY_COLS | wx.RA_HORIZONTAL
             
-        w = wx.RadioBox(parent, new_id, label="", style=style, 
majorDimension=major_dimension,
+        w = wx.RadioBox(parent, new_id, label=label, style=style, 
majorDimension=major_dimension,
                         choices=choices)
-        self.f = self._pair_with_label(w, parent=parent, sizer=sizer, 
label=label, weight=weight)
+        self.f = self._pair_with_label(w, parent=parent, sizer=sizer, 
label=None, weight=weight)
         if callback:
             wx.EVT_RADIOBOX(w, new_id, lambda evt: callback(evt.GetString()))
         field.__init__(self, converter, value)

Modified: gnuradio/branches/releases/3.2/gr-wxgui/src/python/gui.py
===================================================================
--- gnuradio/branches/releases/3.2/gr-wxgui/src/python/gui.py   2009-03-15 
19:41:59 UTC (rev 10615)
+++ gnuradio/branches/releases/3.2/gr-wxgui/src/python/gui.py   2009-03-15 
19:43:30 UTC (rev 10616)
@@ -52,6 +52,11 @@
         self.SetAutoLayout(True)
         vbox.Fit(self)
 
+    def shutdown(self):
+        try:
+            self.gui.shutdown()
+        except AttributeError:
+            pass
 
 #
 # Top-level window frame with menu and status bars.
@@ -91,6 +96,10 @@
             self.top_block.start()
 
     def OnCloseWindow(self, event):
+        # Give user API a chance to do something
+        self.panel.shutdown()
+
+        # Stop flowgraph as a convenience
         self.SetStatusText("Ensuring flowgraph has completed before 
exiting...")
         if self.top_block is not None:
             self.top_block.stop()





reply via email to

[Prev in Thread] Current Thread [Next in Thread]