commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r7854 - in grc/branches/grc_reloaded: . notes scripts


From: jblum
Subject: [Commit-gnuradio] r7854 - in grc/branches/grc_reloaded: . notes scripts src/grc src/grc/platforms/gnuradio_python src/grc/platforms/gnuradio_python/blocks src/grc/platforms/gnuradio_python/blocks/graphical_sinks src/grc/platforms/gnuradio_python/blocks/misc src/grc/platforms/gnuradio_python/blocks/usrp src/grc/platforms/gnuradio_python/blocks/variables src/grc/platforms/gnuradio_python/data src/grc_gnuradio/wxgui
Date: Tue, 26 Feb 2008 19:27:25 -0700 (MST)

Author: jblum
Date: 2008-02-26 19:27:25 -0700 (Tue, 26 Feb 2008)
New Revision: 7854

Added:
   grc/branches/grc_reloaded/scripts/usrp_diagnostics
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/misc/
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/misc/gr_throttle.xml
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/usrp/
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/usrp/usrp_diagnostics.xml
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_chooser.xml
Removed:
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_drop_down.xml
Modified:
   grc/branches/grc_reloaded/notes/todo.txt
   grc/branches/grc_reloaded/setup.py
   grc/branches/grc_reloaded/src/grc/ActionHandler.py
   grc/branches/grc_reloaded/src/grc/Preferences.py
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/graphical_sinks/wxgui_fftsink2.xml
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/graphical_sinks/wxgui_scopesink2.xml
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/block_tree.xml
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/wx_gui.tmpl
   grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/Controls.py
Log:
usrp diagnostics script, radio button support, exec of generated flow graphs

Modified: grc/branches/grc_reloaded/notes/todo.txt
===================================================================
--- grc/branches/grc_reloaded/notes/todo.txt    2008-02-27 02:10:50 UTC (rev 
7853)
+++ grc/branches/grc_reloaded/notes/todo.txt    2008-02-27 02:27:25 UTC (rev 
7854)
@@ -30,9 +30,6 @@
         self.Bind(wx.EVT_CHOICE, self.scale, self.scaling_chooser)
         selection = event.GetSelection()
 
-############   User Prefs:     ####################
---save scrollbar positions (hidden pref)
-
 ############   Uninteresting Features: ####################
 -add the concept of a current working directory
 -auto param to usrp diagnose dialog

Added: grc/branches/grc_reloaded/scripts/usrp_diagnostics
===================================================================
--- grc/branches/grc_reloaded/scripts/usrp_diagnostics                          
(rev 0)
+++ grc/branches/grc_reloaded/scripts/usrp_diagnostics  2008-02-27 02:27:25 UTC 
(rev 7854)
@@ -0,0 +1,120 @@
+#!/usr/bin/python
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden Graphics.USRPDiagnostics
+#A dialog for querying USRP subdevices. USRP interfacing methods encapsulated 
here.
address@hidden Josh Blum
+
+from gnuradio import usrp
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+
+from grc.gui.Dialogs import TextDisplay
+
+from grc.platforms.gnuradio_python.Platform import Platform
+platform = Platform()
+
+from grc.gui.elements.Platform import Platform
+platform = Platform(platform)
+
+flow_graph = platform.get_new_flow_graph()
+block = flow_graph.get_new_block('usrp_diagnostics')
+
+##all params
+usrp_number_param = block.get_param('usrp_number')
+usrp_type_param = block.get_param('usrp_type')
+side_subdev_param = block.get_param('side_subdev')
+
+class USRPDiagnosticsWindow(gtk.Window):
+       """
+       The main window for USRP Dignostics.
+       """
+       
+       def delete_event(self, widget, event, data=None): return False
+       
+       def destroy(self, widget, data=None): gtk.main_quit()
+       
+       def __init__(self):
+               """
+               USRPDiagnosticsWindow contructor.
+               Create a new gtk Dialog with a close button, USRP input 
paramaters, and output labels.
+               """             
+               gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+               #quit signals
+               self.connect("delete_event", self.delete_event)
+               self.connect("destroy", self.destroy)
+               #set the title
+               self.set_title('USRP Diagnostics')
+               #create decorative frame
+               frame = gtk.Frame()
+               self.add(frame)
+               #create vbox for storage
+               vbox = gtk.VBox()
+               frame.add(vbox)
+               vbox.pack_start(usrp_number_param.get_input_object(), False)
+               vbox.pack_start(usrp_type_param.get_input_object(), False)
+               vbox.pack_start(side_subdev_param.get_input_object(), False)
+               self.diagnose_button = gtk.Button('Query')
+               self.diagnose_button.connect('clicked', self._diagnose_usrp)
+               vbox.pack_start(self.diagnose_button, False)            
+               #Create a text box for USRP queries
+               self.query_buffer = TextDisplay()
+               self.query_buffer.set_text('Press "Query" to retrieve USRP 
information...')                     
+               vbox.pack_start(self.query_buffer)      
+               self.show_all()
+               
+       def _diagnose_usrp(self, widget=None):
+               """Query the USRP device and copy the results into the query 
text box."""               
+               type = usrp_type_param.evaluate()
+               if type == 'rx':        #for the rx query, use the source and 
rx methods
+                       make = usrp.source_c
+                       get_mux = usrp.determine_rx_mux_value
+               elif type == 'tx':      #for the tx query, use the sink and tx 
methods
+                       make = usrp.sink_c
+                       get_mux = usrp.determine_tx_mux_value
+               try:            
+                       u = make(usrp_number_param.evaluate())
+                       subdev_spec = side_subdev_param.evaluate()      
+                       subdev = usrp.selected_subdev(u, subdev_spec)#get the 
subdev
+                       msg = ">>> USRP Query\n"
+                       msg = "%s\nName:\n\t%s\n"%(msg,str(subdev.name()))
+                       msg = "%s\nAutomated Mux:\n\t0x%08x\n"%(msg, 
0xFFFFFFFFL & long(get_mux(u, subdev_spec))) #ensure that the value is 
displayed as: 8 nibbles, unsigned, hex
+                       msg = "%s\nConverter 
Rate:\n\t%s\n"%(msg,u.converter_rate())
+                       msg = "%s\nUses Quadrature:\n\t%s\n"%(msg, 
str(subdev.is_quadrature()))
+                       gain_min, gain_max, gain_step = subdev.gain_range()
+                       msg = "%s\nGain Range (min, max, step 
size):\n\t%s\n\t%s\n\t%s\n"%(msg, gain_min, gain_max, gain_step)
+                       freq_min, freq_max, freq_step = subdev.freq_range()
+                       msg = "%s\nFreq Range (min, max, step 
size):\n\t%s\n\t%s\n\t%s\n"%(msg, freq_min, freq_max, freq_step)
+                       self.query_buffer.set_text(msg)
+               except Exception, e:    #display the error message
+                       self.query_buffer.set_text('''\
+>>> Error\n%s
+
+If the USRP cannot be found, make sure that the USRP is plugged-in and restart 
this program. \
+If the problem persists, there may be a problem with you gnuradio installation 
or USB 2.0.
+'''%str(e))    
+
+#enter the mainloop            
+gtk.gdk.threads_init()
+gtk.gdk.threads_enter()
+USRPDiagnosticsWindow()
+gtk.main()
+gtk.gdk.threads_leave()        


Property changes on: grc/branches/grc_reloaded/scripts/usrp_diagnostics
___________________________________________________________________
Name: svn:executable
   + *

Modified: grc/branches/grc_reloaded/setup.py
===================================================================
--- grc/branches/grc_reloaded/setup.py  2008-02-27 02:10:50 UTC (rev 7853)
+++ grc/branches/grc_reloaded/setup.py  2008-02-27 02:27:25 UTC (rev 7854)
@@ -48,6 +48,8 @@
        'platforms/gnuradio_python/blocks/graphical_sinks/*.xml',
        'platforms/gnuradio_python/blocks/operators/*.xml',
        'platforms/gnuradio_python/blocks/variables/*.xml',
+       'platforms/gnuradio_python/blocks/misc/*.xml',
+       'platforms/gnuradio_python/blocks/usrp/*.xml',
 ]
 
 setup(
@@ -60,5 +62,5 @@
        packages=PACKAGES,
        package_dir={'': 'src'},
        package_data={'grc': DATA},
-       scripts=['scripts/grc'],
+       scripts=['scripts/grc', 'scripts/usrp_diagnostics'],
 )

Modified: grc/branches/grc_reloaded/src/grc/ActionHandler.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/ActionHandler.py  2008-02-27 02:10:50 UTC 
(rev 7853)
+++ grc/branches/grc_reloaded/src/grc/ActionHandler.py  2008-02-27 02:27:25 UTC 
(rev 7854)
@@ -20,7 +20,7 @@
 #ActionHandler builds the interface and handles most of the user inputs.       
        
 address@hidden Josh Blum
 
-import os, sys
+import os, sys, popen2
 from Constants import *
 from Actions import *
 import pygtk
@@ -273,11 +273,6 @@
                        else:
                                try:
                                        
ParseXML.to_file(ParseXML.to_xml(self.get_flow_graph().export_data()), 
self.get_page().get_file_path())
-                                       #TODO (tmp)
-                                       g = 
self.get_flow_graph().get_parent().get_generator()
-                                       g = g(self.get_flow_graph())
-                                       
open(self.get_page().get_file_path().rstrip(FLOW_GRAPH_FILE_EXTENSION) + '.py', 
'w').write(str(g))
-                                       
                                        self.get_page().set_saved(True)         
                                except IOError: 
                                        
Messages.send_fail_save(self.get_page().get_file_path())
@@ -346,31 +341,33 @@
                self.page = action_handler.get_page()
                #random id so multiple flow graphs can run w/o files 
intersecting
                rand_id = random.randint(10000, 99999) 
-               #set files              
-               self.file_path = self.page.get_file_path()
-               self.report_file = '/tmp/grc-%d-%d.report'%(os.getpid(), 
rand_id)
+               #generate
+               try:
+                       generator = self.flow_graph.get_parent().get_generator()
+                       g = generator(self.flow_graph)
+                       self.exec_file = 
self.page.get_file_path().replace(FLOW_GRAPH_FILE_EXTENSION, '') + '.py'
+                       open(self.exec_file, 'w').write(str(g))
+               except:
+                       #TODO Messages
+                       print "Could not generate file"
+                       return
+               #set files      
                self.pid_file = '/tmp/grc-%d-%d.pid'%(os.getpid(), rand_id)     
        
                self.page.set_pid_file(self.pid_file)
                self.update_exec_stop()
-               Messages.send_start_exec(self.page.get_file_path())
+               Messages.send_start_exec(self.exec_file)
                self.start()
                
        def run(self):  
                """Execute the flow graph."""
-               cmd = '%s "%s" --pid_file="%s" 2> "%s"'%(
+               cmd = '%s "%s" --pid_file="%s"'%(
                        PYEXEC, 
-                       self.file_path, 
-                       self.pid_file, 
-                       self.report_file,
+                       self.exec_file, 
+                       self.pid_file
                )
-               os.system(cmd)  
-               try:                                            
-                       report = open(self.report_file, 'r')    
-                       #       read all the lines of the report file into a 
list       #
-                       Messages.send_end_exec(report.readlines())
-                       report.close()  
-                       os.remove(self.report_file)
-               except IOError: print "could not read report file: 
%s"%self.report_file
+               p = popen2.Popen3(cmd=cmd, capturestderr=True)
+               #read all the lines of the stderr into a list
+               Messages.send_end_exec(p.childerr.readlines())  
                try: os.remove(self.pid_file)
                except: print "could not remove pid file: %s"%self.pid_file
                self.page.set_pid_file('')

Modified: grc/branches/grc_reloaded/src/grc/Preferences.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/Preferences.py    2008-02-27 02:10:50 UTC 
(rev 7853)
+++ grc/branches/grc_reloaded/src/grc/Preferences.py    2008-02-27 02:27:25 UTC 
(rev 7854)
@@ -20,10 +20,9 @@
 #Holds global paramerences
 address@hidden Josh Blum
 
-from Constants import *
+from Constants import PREFERENCES_FILE_PATH
 import ParseXML
 import Messages
-import os
 
 from grc.platforms.gnuradio_python.Platform import Platform
 platform = Platform()

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-27 02:10:50 UTC (rev 7853)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py    
2008-02-27 02:27:25 UTC (rev 7854)
@@ -68,7 +68,7 @@
                        #separate variables with wx controls
                        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)
+                       choosers = filter(lambda v: v.get_key() == 
'variable_chooser', variables)
                        #graphical sinks
                        graphical_sinks = filter(lambda b: 
b.get_key().startswith('wxgui'), blocks)
                        #all callbacks
@@ -81,7 +81,7 @@
                                'variables': variables,
                                'sliders': sliders,
                                'buttons': buttons,
-                               'drop_downs': drop_downs,
+                               'choosers': choosers,
                                'blocks': blocks,
                                'graphical_sinks': graphical_sinks,
                                'connections': 
self._flow_graph.get_connections(),

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/graphical_sinks/wxgui_fftsink2.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/graphical_sinks/wxgui_fftsink2.xml
       2008-02-27 02:10:50 UTC (rev 7853)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/graphical_sinks/wxgui_fftsink2.xml
       2008-02-27 02:27:25 UTC (rev 7854)
@@ -42,7 +42,7 @@
        <param>
                <name>Title</name>      
                <key>title</key>
-               <value>FFT Sink</value>
+               <value>FFT Plot</value>
                <type>string</type>
        </param>
        <param>

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/graphical_sinks/wxgui_scopesink2.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/graphical_sinks/wxgui_scopesink2.xml
     2008-02-27 02:10:50 UTC (rev 7853)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/graphical_sinks/wxgui_scopesink2.xml
     2008-02-27 02:27:25 UTC (rev 7854)
@@ -38,7 +38,7 @@
        <param>
                <name>Title</name>      
                <key>title</key>
-               <value>Scope Sink</value>
+               <value>Scope Plot</value>
                <type>string</type>
        </param>
        <param>

Added: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/misc/gr_throttle.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/misc/gr_throttle.xml
                             (rev 0)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/misc/gr_throttle.xml
     2008-02-27 02:27:25 UTC (rev 7854)
@@ -0,0 +1,69 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!-- 
+###################################################
+##Throttle
+###################################################
+ -->
+<block>
+       <name>Throttle</name>
+       <key>gr_throttle</key>
+       <import>from gnuradio import gr</import>
+       <make>gr.throttle($type:size*$vlen, $samples_per_second)</make>
+       <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>Samples per Second</name>
+               <key>samples_per_second</key>
+               <value>samp_rate</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Vec Length</name>
+               <key>vlen</key>
+               <value>1</value>
+               <type>int</type>                
+       </param>
+       <check>$vlen >= 1</check>
+       <sink>
+               <name>in</name>
+               <type>$type</type>
+               <vlen>$vlen</vlen>
+       </sink>
+               <source>
+               <name>out</name>
+               <type>$type</type>
+               <vlen>$vlen</vlen>
+       </source>
+       <doc>
+Throttle flow of samples such that the average rate does not exceed samples 
per second.
+       </doc>
+</block>

Added: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/usrp/usrp_diagnostics.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/usrp/usrp_diagnostics.xml
                                (rev 0)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/usrp/usrp_diagnostics.xml
        2008-02-27 02:27:25 UTC (rev 7854)
@@ -0,0 +1,55 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!-- 
+###################################################
+##USRP Diagnostics:
+##     This block should not appear in the tree.
+###################################################
+ -->
+<block>
+       <name>USRP Diagnostics</name>
+       <key>usrp_diagnostics</key>
+       <make></make>
+       <param>
+               <name>USRP Number</name>
+               <key>usrp_number</key>
+               <value>0</value>
+               <type>int</type>        
+       </param>
+       <param>
+               <name>USRP Type</name>
+               <key>usrp_type</key>
+               <value>rx</value>
+               <type>enum</type>
+               <option>
+                       <name>Receive</name>
+                       <key>rx</key>
+               </option>
+               <option>
+                       <name>Transmit</name>
+                       <key>tx</key>
+               </option>
+       </param>
+       <param>
+               <name>Side:Subdevice</name>
+               <key>side_subdev</key>
+               <value>(0, 0)</value>
+               <type>enum</type>
+               <option>
+                       <name>Side A:0</name>
+                       <key>(0, 0)</key>
+               </option>
+               <option>
+                       <name>Side B:0</name>
+                       <key>(1, 0)</key>
+               </option>
+               <option>
+                       <name>Side A:1</name>
+                       <key>(0, 1)</key>
+               </option>
+               <option>
+                       <name>Side B:0</name>
+                       <key>(1, 1)</key>
+               </option>
+       </param>
+</block>

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
    2008-02-27 02:10:50 UTC (rev 7853)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
    2008-02-27 02:27:25 UTC (rev 7854)
@@ -2,7 +2,7 @@
 <!DOCTYPE block SYSTEM "../block.dtd">
 <!-- 
 ###################################################
-##Variable block: a grc variable with key, value, min, max, step
+##Variable block: a grc variable with two choices
 ###################################################
  -->
 <block>

Copied: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_chooser.xml
 (from rev 7847, 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_drop_down.xml)
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_chooser.xml
                           (rev 0)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_chooser.xml
   2008-02-27 02:27:25 UTC (rev 7854)
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!-- 
+###################################################
+##Variable Chooser: a grc variable with multiple choices
+###################################################
+ -->
+<block>
+       <name>Variable Chooser</name>
+       <key>variable_chooser</key>
+       <make>$choices[$value_index]</make>
+       <param>
+               <name>Value Index</name>
+               <key>value_index</key>
+               <value>0</value>
+               <type>int</type>
+       </param>
+       <param>
+               <name>Choices</name>
+               <key>choices</key>
+               <value>[1, 2, 3]</value>
+               <type>raw</type>
+       </param>
+       <param>
+               <name>Chooser Type</name>
+               <key>chooser_type</key>
+               <value>drop_down</value>
+               <type>enum</type>
+               <option>
+                       <name>Drop Down</name>
+                       <key>drop_down</key>
+               </option>
+               <option>
+                       <name>Radio Buttons</name>
+                       <key>radio_buttons</key>
+               </option>
+       </param>
+       <param>
+               <name>Grid Position</name>
+               <key>grid_pos</key>
+               <value>0, 0, 1, 1</value>
+               <type>grid_pos</type>
+       </param>
+       <check>$value_index in range(len($choices))</check>
+       <doc>
+This block creates a variable with a drop down or radio buttons. 
+The value index is the index of a particular choice.
+The choices must be a list of possible values.
+
+Use the Grid Position (row, column, row span, column span) to position the 
graphical element in the window.
+       </doc>
+</block>

Deleted: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_drop_down.xml

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-27 02:10:50 UTC (rev 7853)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/block_tree.xml 
    2008-02-27 02:27:25 UTC (rev 7854)
@@ -184,13 +184,13 @@
        <cat>
                <name>Variables</name>
                <block>variable</block>
-               <block>variable_drop_down</block>
+               <block>variable_chooser</block>
                <block>variable_button</block>
                <block>variable_slider</block>
        </cat>
        <cat>
                <name>Misc</name>
-               <block>throttle</block>
+               <block>gr_throttle</block>
                <block>valve</block>
                <block>selector</block>
                <block>head</block>

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-27 02:10:50 UTC (rev 7853)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/wx_gui.tmpl    
    2008-02-27 02:27:25 UTC (rev 7854)
@@ -9,7 +9,7 @@
 address@hidden connections the connections
 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 choosers variable blocks for choosers
 address@hidden callbacks the block callback strings
 address@hidden graphical_sinks the graphical sink blocks
 ########################################################
@@ -113,19 +113,20 @@
 #end for
 
 ########################################################
-##     Create Drop Downs
+##     Create Chooser
 ########################################################               
-#for $drop_down in $drop_downs
-$make_callback($drop_down.get_id())
-drop_down = Controls.DropDown(
+#for $chooser in $choosers
+$make_callback($chooser.get_id())
+chooser = Controls.Chooser(
        window=_frame, 
        callback=_callback, 
-       title="$drop_down.get_id()", 
-       index=$drop_down.get_param('value_index').to_code(),
-       choices=$drop_down.get_param('choices').to_code(),
+       title="$chooser.get_id()", 
+       index=$chooser.get_param('value_index').to_code(),
+       choices=$chooser.get_param('choices').to_code(),
+       radio=$(chooser.get_param('chooser_type').to_code() == 'radio_buttons')
 )
-#set $grid_pos = $drop_down.get_param('grid_pos').evaluate()
-_grid.Add(drop_down, wx.GBPosition($grid_pos[0], $grid_pos[1]), 
wx.GBSpan($grid_pos[2], $grid_pos[3]))
+#set $grid_pos = $chooser.get_param('grid_pos').evaluate()
+_grid.Add(chooser, wx.GBPosition($grid_pos[0], $grid_pos[1]), 
wx.GBSpan($grid_pos[2], $grid_pos[3]))
 #end for
 
 ########################################################

Modified: grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/Controls.py
===================================================================
--- grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/Controls.py        
2008-02-27 02:10:50 UTC (rev 7853)
+++ grc/branches/grc_reloaded/src/grc_gnuradio/wxgui/Controls.py        
2008-02-27 02:27:25 UTC (rev 7854)
@@ -23,7 +23,7 @@
 import wx
 
 MAX_STR_LEN = 23
-def trim(s): return str(s)[0:MAX_STR_LEN]
+def trim(s): return str(s)[0:MAX_STR_LEN].title()
 
 class Control(object):
        """Control base class"""
@@ -46,7 +46,7 @@
 
        def __init__(self, window, callback, title, on, on_state, off_state):
                """!
-               Slider contructor.
+               Button contructor.
                Create the slider, text box, and label.
                @param window the wx parent window
                @param callback call the callback on changes
@@ -94,20 +94,21 @@
                else: return self.off_state
 
 
##############################################################################################
-#      Drop Down Control
+#      Chooser Control
 
##############################################################################################
-class DropDown(Control, wx.BoxSizer):
-       """House a drop down for variable control."""
+class Chooser(Control, wx.BoxSizer):
+       """House a drop down or radio buttons for variable control."""
 
-       def __init__(self, window, callback, title, index, choices):
+       def __init__(self, window, callback, title, index, choices, 
radio=False):
                """!
-               Slider contructor.
+               Chooser contructor.
                Create the slider, text box, and label.
                @param window the wx parent window
                @param callback call the callback on changes
                @param title the label title
                @param index the default choice index
                @param choices a list of choices
+               @param radio true for radio buttons
                """
                #initialize
                Control.__init__(self, window, callback)
@@ -115,12 +116,21 @@
                wx.BoxSizer.__init__(self, wx.VERTICAL)
                #create label
                label = wx.StaticText(self.get_window(), -1, trim(title))
-               self.Add(label, 0, wx.ALIGN_CENTER)
-               #create chooser
-               self.chooser = wx.Choice(self.get_window(), -1, 
choices=map(trim, choices))
-               self.Add(self.chooser, 0, wx.ALIGN_CENTER)
-               self.chooser.Bind(wx.EVT_CHOICE, self._handle_changed)          
-               self.chooser.SetSelection(index)
+               self.Add(label, 0, wx.ALIGN_CENTER)             
+               if radio: #create radio buttons
+                       self.radio_buttons = list()
+                       for choice in choices:
+                               radio_button = 
wx.RadioButton(self.get_window(), -1, trim(choice))
+                               radio_button.SetValue(False)
+                               self.radio_buttons.append(radio_button)
+                               self.Add(radio_button, 0, wx.ALIGN_CENTER)
+                               radio_button.Bind(wx.EVT_RADIOBUTTON, 
self._handle_changed)
+                       self.radio_buttons[index].SetValue(True)
+               else: #create chooser
+                       self.chooser = wx.Choice(self.get_window(), -1, 
choices=map(trim, choices))
+                       self.Add(self.chooser, 0, wx.ALIGN_CENTER)
+                       self.chooser.Bind(wx.EVT_CHOICE, self._handle_changed)  
        
+                       self.chooser.SetSelection(index)
   
        def _handle_changed(self, event=None):
                """!
@@ -135,7 +145,11 @@
                Read the selected index and parse the choice.
                @return one of the possible choices
                """
-               selection = chooser.GetSelection()
+               if hasattr(self, 'radio_buttons'):
+                       selected_radio_button = filter(lambda rb: 
rb.GetValue(), self.radio_buttons)[0]                         
+                       selection = 
self.radio_buttons.index(selected_radio_button)
+               elif hasattr(self, 'chooser'):  
+                       selection = self.chooser.GetSelection()
                return self.choices[selection]
 
 
##############################################################################################





reply via email to

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