commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r7805 - in grc/branches/grc_reloaded/src: grc/gui grc/


From: jblum
Subject: [Commit-gnuradio] r7805 - in grc/branches/grc_reloaded/src: grc/gui grc/gui/elements grc/platforms/gnuradio_python grc/platforms/gnuradio_python/blocks/sources grc/platforms/gnuradio_python/data grc_gnuradio/wxgui
Date: Sun, 24 Feb 2008 00:11:56 -0700 (MST)

Author: jblum
Date: 2008-02-24 00:11:56 -0700 (Sun, 24 Feb 2008)
New Revision: 7805

Added:
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/sources/gr_sig_source_x.xml
Modified:
   grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Param.py
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Block.py
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/block_tree.xml
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/no_gui.tmpl
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/wx_gui.tmpl
   grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/Controls.py
Log:
callbacks in wxgui

Modified: grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py    
2008-02-24 02:08:31 UTC (rev 7804)
+++ grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py    
2008-02-24 07:11:56 UTC (rev 7805)
@@ -60,7 +60,6 @@
                scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, 
gtk.POLICY_AUTOMATIC)
                scrolled_window.add_with_viewport(vbox)
                self.vbox.pack_start(scrolled_window, True)
-               self.original_data = list()
                #Error Messages for the block
                self._error_messages_box = err_box = gtk.VBox()
                self._error_messages_text_display = TextDisplay('')
@@ -69,7 +68,6 @@
                err_box.pack_start(self._error_messages_text_display, False)    
        
                #Add all the parameters
                for param in filter(lambda p: p.get_key() not in ('position',), 
self.block.get_params()): 
-                       self.original_data.append(param.get_value())
                        
vbox.pack_start(param.get_input_object(self._handle_changed), False)    
                vbox.pack_start(err_box, False)
                #Done adding parameters                                         
        
@@ -121,10 +119,13 @@
                Call run().
                @return true if a change occured.
                """
+               original_data = list()
+               for param in self.block.get_params():
+                       original_data.append(param.get_value())
                gtk.Dialog.run(self)            
                self.destroy()
-               self.data = list()
+               new_data = list()
                for param in self.block.get_params():
-                       self.data.append(param.get_value())
-               return self.original_data != self.data
+                       new_data.append(param.get_value())
+               return original_data != new_data
                        

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Param.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Param.py     2008-02-24 
02:08:31 UTC (rev 7804)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Param.py     2008-02-24 
07:11:56 UTC (rev 7805)
@@ -150,7 +150,7 @@
                name = Utils.xml_encode(self.get_name())
                #special markups if param is involved in a callback
                if hasattr(self.get_parent(), 'get_callbacks') and \
-                       filter(lambda c: self.get_key() in c, 
self.get_parent().get_callbacks()):
+                       filter(lambda c: self.get_key() in c, 
self.get_parent()._callbacks):
                        name = '<span underline="low">%s</span>'%name           
                if not self.is_valid(): 
                        self.input.set_markup('<span 
foreground="red"><b>%s</b></span>'%name)

Modified: grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Block.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Block.py        
2008-02-24 02:08:31 UTC (rev 7804)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Block.py        
2008-02-24 07:11:56 UTC (rev 7805)
@@ -95,5 +95,6 @@
        
        def get_make(self): return self.resolve_dependencies(self._make, 
to_code=True)
        
-       def get_callbacks(self): return self._callbacks
+       def get_callbacks(self):
+               return map(lambda c: self.get_id() + '.' + 
self.resolve_dependencies(c, to_code=True), self._callbacks)
        

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py    
2008-02-24 02:08:31 UTC (rev 7804)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py    
2008-02-24 07:11:56 UTC (rev 7805)
@@ -42,7 +42,6 @@
                namespace = dict()
                namespace['__builtins__'] = __builtins__                
                namespace['gr'] = gr
-               namespace['blks2'] = blks2
                namespace['firdes'] = firdes
                namespace['math'] = math
                namespace['cmath'] = cmath

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py    
2008-02-24 02:08:31 UTC (rev 7804)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py    
2008-02-24 07:11:56 UTC (rev 7805)
@@ -41,7 +41,7 @@
                """
                all_blocks = self._flow_graph.get_blocks()
                #get imports
-               imports = ['from gnuradio import gr']
+               imports = ['from gnuradio import gr', 'from gnuradio.gr import 
firdes', 'import math', 'import cmath']
                for block in all_blocks: imports.extend(block.get_imports())
                imports = set(imports) #all entries unique
                #separate variables
@@ -68,6 +68,9 @@
                        sliders = filter(lambda v: v.get_key() == 
'variable_slider', variables)
                        buttons = filter(lambda v: v.get_key() == 
'variable_button', variables)
                        drop_downs = filter(lambda v: v.get_key() == 
'variable_drop_down', variables)
+                       #all callbacks
+                       callbacks = list()
+                       for block in blocks: 
callbacks.extend(block.get_callbacks())
                        #load the namespace
                        namespace = {
                                'imports':      imports,
@@ -78,6 +81,7 @@
                                'drop_downs': drop_downs,
                                'blocks': blocks,
                                'connections': 
self._flow_graph.get_connections(),
+                               'callbacks': callbacks,
                        }
                        #build the template
                        t = Template(open(WX_GUI_TEMPLATE, 'r').read(), 
namespace)

Added: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/sources/gr_sig_source_x.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/sources/gr_sig_source_x.xml
                              (rev 0)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/sources/gr_sig_source_x.xml
      2008-02-24 07:11:56 UTC (rev 7805)
@@ -0,0 +1,104 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!-- 
+###################################################
+##Signal Source
+###################################################
+ -->
+<block>
+       <name>Signal Source</name>
+       <key>gr_sig_source_x</key>
+       <import>from gnuradio import gr</import>
+       <make>$type:fcn($samp_rate, $waveform, $freq, $amp, $offset)</make>
+       <callback>set_sampling_freq($samp_rate)</callback>
+       <callback>set_frequency($freq)</callback>
+       <callback>set_amplitude($amp)</callback>
+       <callback>set_offset($offset)</callback>
+       <param>
+               <name>Output Type</name>
+               <key>type</key>
+               <type>enum</type>
+               <option>
+                       <name>Complex</name>
+                       <key>complex</key>
+                       <opt>fcn:gr.sig_source_c</opt>                          
        
+               </option>
+               <option>
+                       <name>Float</name>
+                       <key>float</key>
+                       <opt>fcn:gr.sig_source_f</opt>                  
+               </option>
+               <option>
+                       <name>Int</name>
+                       <key>int</key>
+                       <opt>fcn:gr.sig_source_i</opt>                          
        
+               </option>
+               <option>
+                       <name>Short</name>
+                       <key>short</key>
+                       <opt>fcn:gr.sig_source_s</opt>                          
+               </option>
+       </param>        
+       <param>
+               <name>Sample Rate</name>
+               <key>samp_rate</key>
+               <value>samp_rate</value>
+               <type>real</type>               
+       </param>
+       <param>
+               <name>Waveform</name>
+               <key>waveform</key>
+               <value>gr.GR_COS_WAVE</value>
+               <type>enum</type>
+               <option>
+                       <name>Constant</name>
+                       <key>gr.GR_CONST_WAVE</key>
+               </option>
+               <option>
+                       <name>Constant</name>
+                       <key>gr.GR_SIN_WAVE</key>
+               </option>
+               <option>
+                       <name>Constant</name>
+                       <key>gr.GR_COS_WAVE</key>
+               </option>
+               <option>
+                       <name>Constant</name>
+                       <key>gr.GR_SQR_WAVE</key>
+               </option>
+               <option>
+                       <name>Constant</name>
+                       <key>gr.GR_TRI_WAVE</key>
+               </option>
+               <option>
+                       <name>Constant</name>
+                       <key>gr.GR_SAW_WAVE</key>
+               </option>
+       </param>
+       <param>
+               <name>Frequency</name>
+               <key>freq</key>
+               <value>1000</value>
+               <type>real</type>               
+       </param>
+       <param>
+               <name>Amplitude</name>
+               <key>amp</key>
+               <value>1</value>
+               <type>real</type>               
+       </param>
+       <param>
+               <name>Offset</name>
+               <key>offset</key>
+               <value>0</value>
+               <type>complex</type>            
+       </param>
+       <source>
+               <name>out</name>
+               <type>$type</type>
+       </source>
+       <doc>
+Signal source creates a sinusoid, square, triangle, sawtooth or constant 
(dc-level) waveform. \
+In the case of complex output, the output is 2 waveforms (I and Q), 90 degrees 
out of phase.
+       </doc>
+</block>

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/block_tree.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/block_tree.xml 
    2008-02-24 02:08:31 UTC (rev 7804)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/block_tree.xml 
    2008-02-24 07:11:56 UTC (rev 7805)
@@ -8,7 +8,7 @@
 <block_tree>
        <cat>
                <name>Sources</name>
-               <block>signal_source</block>    
+               <block>gr_sig_source_x</block>  
                <block>noise_source</block>     
                <block>vector_source</block>    
                <block>random_source</block>    

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/no_gui.tmpl
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/no_gui.tmpl    
    2008-02-24 02:08:31 UTC (rev 7804)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/no_gui.tmpl    
    2008-02-24 07:11:56 UTC (rev 7805)
@@ -45,5 +45,7 @@
 )
 #end for
 
-tb.run()
+tb.start()
+raw_input('Press Enter to quit: ')
+tb.stop()
 

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/wx_gui.tmpl
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/wx_gui.tmpl    
    2008-02-24 02:08:31 UTC (rev 7804)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/wx_gui.tmpl    
    2008-02-24 07:11:56 UTC (rev 7805)
@@ -10,6 +10,7 @@
 address@hidden sliders variable blocks for sliders
 address@hidden buttons variable blocks for buttons
 address@hidden drop_downs variable blocks for drop_downs
address@hidden callbacks the block callback strings
 ########################################################
 #import time
 #import os
@@ -24,10 +25,45 @@
 $flow_graph.get_option('description')
 $('"""')
 
+#def make_callback($id)
+       #set $my_callbacks = filter(lambda c: id in c, $callbacks)
+       #if $my_callbacks
+               def callback(value):
+                       $id = value
+               #for $callback in $my_callbacks
+                       exec("""$callback""")
+               #end for
+       #else
+               def callback(value): pass#slurp
+       #end if         
+#end def
+
 #for $imp in $imports
 $imp
 #end for
 
+#for $var in $variables
+$("%s = %s"%($var.get_id(), $var.get_make()))
+#end for
+
+#for $blk in $blocks
+$("%s = %s"%($blk.get_id(), $blk.get_make()))
+#end for
+
+tb = gr.top_block()
+
+#for $con in $connections
+       #set $source = $con.get_source()
+       #set $sink = $con.get_sink()
+$("tb.connect((%s, %s), (%s, %s))"%(
+               $source.get_parent().get_id(), 
+               $source.get_key(),
+               $sink.get_parent().get_id(), 
+               $sink.get_key(),
+       )
+)
+#end for
+
 class Frame(wx.Frame):
                
        def __init__(self):             
@@ -36,11 +72,9 @@
                self.SetIcon(wx.Icon("$os.path.abspath($WX_APP_ICON)", 
wx.BITMAP_TYPE_ANY))
 #end if                
                self.SetSizeHints(400, 100)
-               main_box = wx.BoxSizer(wx.VERTICAL)
-               
-               def callback(): print "called!!!"
-               
+               main_box = wx.BoxSizer(wx.VERTICAL)             
 #for $slider in $sliders
+$make_callback($slider.get_id())
                slider = Controls.Slider(
                        window=self, 
                        callback=callback, 
@@ -52,8 +86,8 @@
                )
                main_box.Add(slider, 0, wx.ALIGN_CENTER)
 #end for               
-               
 #for $drop_down in $drop_downs
+$make_callback($drop_down.get_id())
                drop_down = Controls.DropDown(
                        window=self, 
                        callback=callback, 
@@ -62,9 +96,9 @@
                        choices=$drop_down.get_param('choices').to_code(),
                )
                main_box.Add(drop_down, 0, wx.ALIGN_CENTER)
-#end for               
-
+#end for
 #for $button in $buttons
+$make_callback($button.get_id())
                button = Controls.Button(
                        window=self, 
                        callback=callback, 
@@ -74,27 +108,19 @@
                        off_state=$button.get_param('on_value').to_code(),
                )
                main_box.Add(button, 0, wx.ALIGN_CENTER)
-#end for       
-               
+#end for               
                self.Bind(wx.EVT_CLOSE, self._quit)     
                self.SetSizerAndFit(main_box)
                self.Show()
+               tb.start()
                        
        def _quit(self, event):
                self.Destroy()
-               
-class App(wx.App):
-       
-       def __init__(self):             
-               wx.App.__init__(self, 0)        
-                       
-       def OnInit(self):
-               self.SetTopWindow(Frame())
-               return True
-               
-if __name__ == '__main__':     
-       app = App()
-       app.MainLoop()
-       exit(0)
+               tb.stop()
 
+app = wx.App()
+app.SetTopWindow(Frame())
+app.MainLoop()
+exit(0)
 
+

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/Controls.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/Controls.py        
2008-02-24 02:08:31 UTC (rev 7804)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/Controls.py        
2008-02-24 07:11:56 UTC (rev 7805)
@@ -34,7 +34,7 @@
                
        def get_window(self): return self.window
        
-       def get_callback(self): return self.callback
+       def call(self): return self.callback(self.get_value())
        
        def get_value(self): raise NotImplementedError
        
@@ -76,7 +76,7 @@
                """
                self.state = not self.state
                self._set_button_label()
-               try: self.get_callback()()
+               try: self.call()
                except Exception, e: print 'Error in handle change: "%s".'%e    
        
 
        def _set_button_label(self):
@@ -126,7 +126,7 @@
                """!
                A change is detected. Call the callback.
                """
-               try: self.get_callback()()
+               try: self.call()
                except Exception, e: print 'Error in handle change: "%s".'%e    
        
 
        def get_value(self):
@@ -187,7 +187,7 @@
                @return the numeric representation of the slider
                """
                slider_value = self.slider.GetValue()                   
-               return 
str(slider_value*(float(self.max)-float(self.min))/self.num_steps + 
float(self.min))
+               return 
slider_value*(float(self.max)-float(self.min))/self.num_steps + float(self.min)
                
        def _set_slider_value(self, real_value):
                """!
@@ -203,7 +203,7 @@
                A scroll event is detected. Read the slider, call the callback.
                """
                new_value = str(self.get_value())       #the new value must be 
a string!
-               try: self.get_callback()()
+               try: self.call()
                except Exception, e: print 'Error in handle scroll: "%s".'%e 
                self._set_slider_value(new_value)
                self.text_box.SetValue(new_value)
@@ -213,7 +213,7 @@
                An enter key was pressed. Read the text box, call the callback.
                """     
                new_value = str(self.text_box.GetValue())       #the new value 
must be a string!        
-               try: self.get_callback()()
+               try: self.call()
                except Exception, e: print 'Error in handle enter: "%s".'%e 
                self._set_slider_value(new_value)
                self.text_box.SetValue(new_value)





reply via email to

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