commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10800 - in gnuradio/branches/developers/jblum/grc/grc


From: jblum
Subject: [Commit-gnuradio] r10800 - in gnuradio/branches/developers/jblum/grc/grc: data/platforms/python/blocks src/platforms/base src/platforms/python
Date: Thu, 9 Apr 2009 22:24:16 -0600 (MDT)

Author: jblum
Date: 2009-04-09 22:24:16 -0600 (Thu, 09 Apr 2009)
New Revision: 10800

Modified:
   
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/gr_noise_source_x.xml
   
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/gr_sig_source_x.xml
   gnuradio/branches/developers/jblum/grc/grc/src/platforms/base/Param.py
   gnuradio/branches/developers/jblum/grc/grc/src/platforms/python/Param.py
Log:
Added an enum/raw type. Basically a chooser combined with a text entry 
box. Example, the waveform type can be set via a variable and callback in 
signal/noise source.



Modified: 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/gr_noise_source_x.xml
===================================================================
--- 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/gr_noise_source_x.xml
       2009-04-10 02:34:55 UTC (rev 10799)
+++ 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/gr_noise_source_x.xml
       2009-04-10 04:24:16 UTC (rev 10800)
@@ -9,6 +9,7 @@
        <key>gr_noise_source_x</key>
        <import>from gnuradio import gr</import>
        <make>gr.noise_source_$(type.fcn)($noise_type, $amp, $seed)</make>
+       <callback>set_type($noise_type)</callback>
        <callback>set_amplitude($amp)</callback>
        <param>
                <name>Output Type</name>
@@ -39,7 +40,7 @@
                <name>Noise Type</name>
                <key>noise_type</key>
                <value>gr.GR_GAUSSIAN</value>
-               <type>enum</type>
+               <type>raw_enum</type>
                <option>
                        <name>Uniform</name>
                        <key>gr.GR_UNIFORM</key>

Modified: 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/gr_sig_source_x.xml
===================================================================
--- 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/gr_sig_source_x.xml
 2009-04-10 02:34:55 UTC (rev 10799)
+++ 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/gr_sig_source_x.xml
 2009-04-10 04:24:16 UTC (rev 10800)
@@ -10,6 +10,7 @@
        <import>from gnuradio import gr</import>
        <make>gr.sig_source_$(type.fcn)($samp_rate, $waveform, $freq, $amp, 
$offset)</make>
        <callback>set_sampling_freq($samp_rate)</callback>
+       <callback>set_waveform($waveform)</callback>
        <callback>set_frequency($freq)</callback>
        <callback>set_amplitude($amp)</callback>
        <callback>set_offset($offset)</callback>
@@ -52,7 +53,7 @@
                <name>Waveform</name>
                <key>waveform</key>
                <value>gr.GR_COS_WAVE</value>
-               <type>enum</type>
+               <type>raw_enum</type>
                <option>
                        <name>Constant</name>
                        <key>gr.GR_CONST_WAVE</key>

Modified: gnuradio/branches/developers/jblum/grc/grc/src/platforms/base/Param.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/platforms/base/Param.py      
2009-04-10 02:34:55 UTC (rev 10799)
+++ gnuradio/branches/developers/jblum/grc/grc/src/platforms/base/Param.py      
2009-04-10 04:24:16 UTC (rev 10800)
@@ -61,7 +61,7 @@
                InputParam.__init__(self, *args, **kwargs)
                self._input = gtk.combo_box_new_text()
                for option in self.param.get_options(): 
self._input.append_text(option.get_name())
-               
self._input.set_active(int(self.param.get_option_keys().index(self.param.get_value())))
+               
self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
                self._input.connect('changed', self._handle_changed)
                self.pack_start(self._input, False)
        def get_text(self): return 
self.param.get_option_keys()[self._input.get_active()]
@@ -192,7 +192,7 @@
                self._value = str(value) #must be a string
 
        def get_type(self): return 
self.get_parent().resolve_dependencies(self._type)
-       def is_enum(self): return bool(self.get_options())
+       def is_enum(self): return self._type == 'enum'
 
        def __repr__(self):
                """

Modified: 
gnuradio/branches/developers/jblum/grc/grc/src/platforms/python/Param.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/platforms/python/Param.py    
2009-04-10 02:34:55 UTC (rev 10799)
+++ gnuradio/branches/developers/jblum/grc/grc/src/platforms/python/Param.py    
2009-04-10 04:24:16 UTC (rev 10800)
@@ -18,7 +18,7 @@
 """
 
 from utils import expr_utils
-from .. base.Param import Param as _Param, EntryParam
+from .. base.Param import Param as _Param, EntryParam, InputParam
 import Constants
 import numpy
 import os
@@ -63,6 +63,24 @@
                        self._handle_changed()
                file_dialog.destroy() #destroy the dialog
 
+class EnumEntryParam(InputParam):
+       """Provide an entry box and drop down menu for Raw Enum types."""
+
+       def __init__(self, *args, **kwargs):
+               InputParam.__init__(self, *args, **kwargs)
+               self._input = gtk.combo_box_entry_new_text()
+               for option in self.param.get_options(): 
self._input.append_text(option.get_name())
+               try: 
self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
+               except:
+                       self._input.set_active(-1)
+                       self._input.get_child().set_text(self.param.get_value())
+               self._input.connect('changed', self._handle_changed)
+               self._input.get_child().connect('changed', self._handle_changed)
+               self.pack_start(self._input, False)
+       def get_text(self):
+               if self._input.get_active() == -1: return 
self._input.get_child().get_text()
+               return self.param.get_option_keys()[self._input.get_active()]
+
 #define types, native python + numpy
 VECTOR_TYPES = (tuple, list, set, numpy.ndarray)
 COMPLEX_TYPES = [complex, numpy.complex, numpy.complex64, numpy.complex128]
@@ -87,6 +105,7 @@
                'file_open', 'file_save',
                'id',
                'grid_pos', 'import',
+               'raw_enum',
        ]
 
        def __repr__(self):
@@ -94,7 +113,7 @@
                Get the repr (nice string format) for this param.
                @return the string representation
                """
-               if self.is_enum(): return _Param.__repr__(self)
+               if self.get_value() in self.get_option_keys(): return 
self.get_option(self.get_value()).get_name()
                ##################################################
                # display logic for numbers
                ##################################################
@@ -138,6 +157,7 @@
 
        def get_input_class(self):
                if self.get_type() in ('file_open', 'file_save'): return 
FileParam
+               if self.get_type() == 'raw_enum': return EnumEntryParam
                return _Param.get_input_class(self)
 
        def get_color(self):
@@ -219,14 +239,14 @@
                #########################
                # Numeric Types
                #########################
-               elif t in ('raw', 'complex', 'real', 'int', 'complex_vector', 
'real_vector', 'int_vector', 'hex'):
+               elif t in ('raw_enum', 'raw', 'complex', 'real', 'int', 
'complex_vector', 'real_vector', 'int_vector', 'hex'):
                        #raise exception if python cannot evaluate this value
                        try: e = self.get_parent().get_parent().evaluate(v)
                        except:
                                self._add_error_message('Value "%s" cannot be 
evaluated.'%v)
                                raise Exception
                        #raise an exception if the data is invalid
-                       if t == 'raw': return e
+                       if t in ('raw', 'raw_enum'): return e
                        elif t == 'complex':
                                try: assert(isinstance(e, COMPLEX_TYPES))
                                except AssertionError:





reply via email to

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