commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r7680 - in grc/branches/grc_reloaded/src/grc: elements


From: jblum
Subject: [Commit-gnuradio] r7680 - in grc/branches/grc_reloaded/src/grc: elements gui gui/elements platforms/gnuradio_python platforms/gnuradio_python/blocks platforms/gnuradio_python/blocks/operators platforms/gnuradio_python/blocks/variables
Date: Thu, 14 Feb 2008 12:52:33 -0700 (MST)

Author: jblum
Date: 2008-02-14 12:52:33 -0700 (Thu, 14 Feb 2008)
New Revision: 7680

Modified:
   grc/branches/grc_reloaded/src/grc/elements/Block.py
   grc/branches/grc_reloaded/src/grc/elements/Param.py
   grc/branches/grc_reloaded/src/grc/gui/MainWindow.py
   grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Block.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/blocks/operators/add_const.xml
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/options.xml
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
   
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_drop_down.xml
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/default_flow_graph.grc.xml
Log:
variables are functional

Modified: grc/branches/grc_reloaded/src/grc/elements/Block.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Block.py 2008-02-14 19:50:41 UTC 
(rev 7679)
+++ grc/branches/grc_reloaded/src/grc/elements/Block.py 2008-02-14 19:52:33 UTC 
(rev 7680)
@@ -55,7 +55,7 @@
                        {
                                'name': 'ID', 
                                'key': 'id', 
-                               'type': 'var_key',
+                               'type': 'id',
                        }
                )
                for param in map(lambda n: 
self.get_parent().get_parent().Param(self, n), params):
@@ -104,7 +104,7 @@
                        try: assert(c.is_valid())
                        except AssertionError: self._add_error_message('%s is 
not valid.'%c)
                for check in self._checks:
-                       check_res = self.resolve_dependencies(check)
+                       check_res = self.resolve_dependencies(check, 
to_code=True)
                        try: 
                                check_eval = 
self.get_parent().evaluate(check_res)
                                try: assert(check_eval)
@@ -146,7 +146,7 @@
        def get_source(self, key): return self._sources[key]
        def get_sources(self): return self._sources.values()
        
-       def resolve_dependencies(self, string):
+       def resolve_dependencies(self, string, to_code=False):
                """
                Resolve a paramater dependency.
                Dependencies are simple strings. 
@@ -155,6 +155,7 @@
                Dependencies are specified as $param_key where param_key is an 
existing parameter.
                For enumerated parameters, dependencies are $param_key:opt_key 
where opt_key is an existing opt key.
                @param string the string with dependencies
+               @param to_code true if to_code method should be used
                @return the resolved value
                """
                #create a dictionary of all possible dependency strings
@@ -163,7 +164,7 @@
                        if param.is_enum():
                                for key in param.get_opt_keys():
                                        deps['$'+param.get_key()+':'+key] = 
param.get_opt(key)
-                       else: deps['$'+param.get_key()] = param.get_value()
+                       else: deps['$'+param.get_key()] = to_code and 
param.to_code() or param.get_value()
                #replace any dependencies with actual values
                for key,value in deps.iteritems():
                        string = string.replace(key, value)

Modified: grc/branches/grc_reloaded/src/grc/elements/Param.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Param.py 2008-02-14 19:50:41 UTC 
(rev 7679)
+++ grc/branches/grc_reloaded/src/grc/elements/Param.py 2008-02-14 19:52:33 UTC 
(rev 7680)
@@ -90,6 +90,7 @@
                @param n the nested odict
                @return a new param
                """
+               self._cached_params = list()
                #grab the data
                name = n['name']
                key = n['key']
@@ -150,13 +151,20 @@
                                if not self.get_error_messages():
                                        self._add_error_message('Value "%s" 
cannot be evaluated.'%self.get_value())             
                except AssertionError: self._add_error_message('Type "%s" is 
not a possible type.'%type)        
-               
+       
        def evaluate(self):
                """!
                Evaluate the value of this param.
                @throw NotImplementedError
                """
                raise NotImplementedError       
+               
+       def to_code(self):
+               """!
+               Convert the value to code.
+               @throw NotImplementedError
+               """
+               raise NotImplementedError
        
        def __str__(self): return 'Param: %s(%s)'%(self.get_name(), 
self.get_key())
        

Modified: grc/branches/grc_reloaded/src/grc/gui/MainWindow.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/MainWindow.py 2008-02-14 19:50:41 UTC 
(rev 7679)
+++ grc/branches/grc_reloaded/src/grc/gui/MainWindow.py 2008-02-14 19:52:33 UTC 
(rev 7680)
@@ -243,11 +243,12 @@
                @param notebook the notebook
                @param page new page
                @param page_num new page number
-               """             
+               """
                self.current_page = self.notebook.get_nth_page(page_num)
                Messages.send_page_switch(self.current_page.get_file_path())
                state = self.get_page().get_state_cache().get_current_state()
                self.get_flow_graph().import_data(state)
+               self.get_flow_graph().update()
                self.handle_states(NOTHING_SELECT) 
                
        ############################################################

Modified: grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py    
2008-02-14 19:50:41 UTC (rev 7679)
+++ grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py    
2008-02-14 19:52:33 UTC (rev 7680)
@@ -23,9 +23,23 @@
 import pygtk
 pygtk.require('2.0')
 import gtk
+
 from Dialogs import TextDisplay
 from grc.Constants import MIN_DIALOG_WIDTH,MIN_DIALOG_HEIGHT
 
+def get_title_label(title):
+       """!
+       Get a title label for the params window.
+       The title will be bold, underlined, and left justified.
+       @param title the text of the title
+       @return a gtk object
+       """
+       label = gtk.Label()
+       label.set_markup('\n<b><span underline="low">%s</span>:</b>\n'%title)
+       hbox = gtk.HBox()
+       hbox.pack_start(label, False, False, padding=11)        
+       return hbox
+
 class SignalBlockParamsDialog(gtk.Dialog):
        """A dialog box to set signal block parameters."""
        
@@ -36,13 +50,11 @@
                """
                gtk.Dialog.__init__(self, buttons=('gtk-close', 
gtk.RESPONSE_CLOSE))
                self.block = block
-               self.set_title('Properties: %s'%block.get_id())
+               self.set_title('Properties: %s'%block.get_name())
                self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
                vbox = gtk.VBox()
-               #Create the title label
-               label = gtk.Label()
-               label.set_markup('\n<b>Parameters: 
%s</b>\n'%self.block.get_id())
-               vbox.pack_start(label, False)
+               #Add the title label            
+               vbox.pack_start(get_title_label('Parameters'), False)
                #Create the scrolled window to hold all the parameters
                scrolled_window = gtk.ScrolledWindow()
                scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, 
gtk.POLICY_AUTOMATIC)
@@ -54,11 +66,11 @@
                        self.original_data.append(param.get_value())
                        
vbox.pack_start(param.get_input_object(self._handle_changed), False)    
                #Done adding parameters                                         
        
-               if self.block.get_doc():        
-                       #Create the title label
-                       label = gtk.Label()
-                       label.set_markup('\n\n<b>Documentation: 
%s</b>\n'%self.block.get_name())
-                       vbox.pack_start(label, False)   
+               if self.block.get_doc():
+                       #Create some additional spacing
+                       vbox.pack_start(gtk.Label(''), False, False, 7)
+                       #Add the title label            
+                       vbox.pack_start(get_title_label('Documentation'), False)
                        #Create the text box to display notes about the block
                        
vbox.pack_start(TextDisplay(self.block.get_doc().strip('\n')), False)
                self.show_all()

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Block.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Block.py     2008-02-14 
19:50:41 UTC (rev 7679)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Block.py     2008-02-14 
19:52:33 UTC (rev 7680)
@@ -109,7 +109,7 @@
                if not self.is_valid(): layout.set_markup('<span 
foreground="red"><b>'+self.get_name()+'</b></span>')                   
                self.label_width,self.label_height = layout.get_pixel_size()    
                #display the params (except for the special params id and 
position)
-               for param in filter(lambda p: p.get_key() not in ('id', 
'position'), self.get_params()):
+               for param in filter(lambda p: p.get_key() not in ('position', 
), self.get_params()):
                        layout = param.get_layout()
                        layouts.append(layout)
                        w,h = layout.get_pixel_size()

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Param.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Param.py     2008-02-14 
19:50:41 UTC (rev 7679)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Param.py     2008-02-14 
19:52:33 UTC (rev 7680)
@@ -75,7 +75,7 @@
                """ If the button was clicked, open a file dialog in open/save 
format.
                Replace the text in the entry with the new filename from the 
file dialog.       """
                file_path = self.param.evaluate()
-               #       bad file paths will be redirected to default    #
+               #bad file paths will be redirected to default
                if not path.exists(path.dirname(file_path)): file_path = 
DEFAULT_FILE_PATH      
                if self.get_type() == 'file_open': 
                        file_dialog = gtk.FileChooserDialog('Open a Data 
File...', None,
@@ -153,7 +153,7 @@
                        tip = '- ' + '\n- '.join(self.get_error_messages())
                else: 
                        self.input.set_markup(name)
-                       tip = self.evaluate()           
+                       tip = self.evaluate()   
                #set the tooltip                
                if self.input.tp: self.input.tp.set_tip(self.input.entry, 
str(tip))
                #execute the external callback 

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-14 19:50:41 UTC (rev 7679)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Block.py        
2008-02-14 19:52:33 UTC (rev 7680)
@@ -57,7 +57,7 @@
        
        def get_deps(self): return self._deps
        
-       def get_fcn(self): return self._fcn
+       def get_fcn(self): return self.resolve_dependencies(self._fcn, 
to_code=True)
        
        def get_callbacks(self): return 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-14 19:50:41 UTC (rev 7679)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py    
2008-02-14 19:52:33 UTC (rev 7680)
@@ -33,20 +33,23 @@
                @throw Exception bad expression
                @return the evaluated data
                """
+               namespace = dict()      
+               namespace['__builtins__'] = __builtins__        
                #bring in gnuradio modules
+               from gnuradio import gr
+               from gnuradio import blks2
                from gnuradio.gr import firdes
                import math
                import cmath
-               my_eval = lambda exp: eval(
-                       exp, 
-                       {
-                               '__builtins__': __builtins__,
-                               'firdes': firdes,
-                               'math': math,
-                               'cmath': cmath,
-                               #TODO add varables here
-                       },
-               )               
-               return my_eval(expr)
+               namespace['gr'] = gr
+               namespace['blks2'] = blks2
+               namespace['firdes'] = firdes
+               namespace['math'] = math
+               namespace['cmath'] = cmath
+               #load variables
+               for block in filter(lambda b: 
b.get_key().startswith('variable'), self.get_blocks()):
+                       try: namespace[block.get_id()] = eval(block.get_fcn(), 
{}, {})
+                       except: pass
+               return eval(expr, namespace, {})        
+       
                
-               

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add_const.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add_const.xml
  2008-02-14 19:50:41 UTC (rev 7679)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add_const.xml
  2008-02-14 19:52:33 UTC (rev 7680)
@@ -13,7 +13,7 @@
        <fcn>$type:fcn($const)</fcn>
        <callback>set_k($const)</callback>
        <param>
-               <name>Constant</name>
+               <name>Constant*</name>
                <key>const</key>
                <value>0</value>
                <type>$type:const_type</type>

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/options.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/options.xml  
    2008-02-14 19:50:41 UTC (rev 7679)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/options.xml  
    2008-02-14 19:52:33 UTC (rev 7680)
@@ -44,6 +44,6 @@
                </option>
        </param>        
        <check>len(($window_size)) == 2</check>
-       <check>400 &lt;= ($window_size)[0] &lt;= 1600</check>
-       <check>300 &lt;= ($window_size)[1] &lt;= 1200</check>
+       <check>400 &lt;= $window_size[0] &lt;= 1600</check>
+       <check>300 &lt;= $window_size[1] &lt;= 1200</check>
 </block>

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
   2008-02-14 19:50:41 UTC (rev 7679)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
   2008-02-14 19:52:33 UTC (rev 7680)
@@ -8,14 +8,8 @@
 <block>
        <name>Variable</name>
        <key>variable</key>
-       <fcn />
+       <fcn>$value</fcn>
        <param>
-               <name>Key</name>
-               <key>key</key>
-               <value>my_var</value>
-               <type>var_key</type>
-       </param>
-       <param>
                <name>Value</name>
                <key>value</key>
                <value>0</value>

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-14 19:50:41 UTC (rev 7679)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
    2008-02-14 19:52:33 UTC (rev 7680)
@@ -8,25 +8,21 @@
 <block>
        <name>Variable Button</name>
        <key>variable_button</key>
-       <fcn />
+       <fcn>($off_value, $on_value)[$default_value]</fcn>
        <param>
-               <name>Key</name>
-               <key>key</key>
-               <value>my_var</value>
-               <type>var_key</type>
-       </param>
-       <param>
                <name>Default Value</name>      
                <key>default_value</key>
                <value>on</value>
                <type>enum</type>
                <option>
                        <name>On</name>
-                       <key>on</key>                   
+                       <key>on</key>
+                       <opt>i:1</opt>          
                </option>
                <option>
                        <name>Off</name>
-                       <key>off</key>                  
+                       <key>off</key>  
+                       <opt>i:0</opt>          
                </option>
        </param>
        <param>

Modified: 
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_drop_down.xml
 2008-02-14 19:50:41 UTC (rev 7679)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_drop_down.xml
 2008-02-14 19:52:33 UTC (rev 7680)
@@ -8,14 +8,8 @@
 <block>
        <name>Variable Drop Down</name>
        <key>variable_drop_down</key>
-       <fcn />
+       <fcn>$choices[$default_value]</fcn>
        <param>
-               <name>Key</name>
-               <key>key</key>
-               <value>my_var</value>
-               <type>var_key</type>
-       </param>
-       <param>
                <name>Default Value</name>
                <key>default_value</key>
                <value>0</value>
@@ -27,8 +21,7 @@
                <value>[val0, val1, val2...]</value>
                <type>raw</type>
        </param>
-       <check>len($choices) > 0</check>
-       <check>$default_value in range(0, len($choices))</check>
+       <check>$choices[$default_value]</check>
        <doc>
 This block creates a variable with a drop down. 
 The variable key must be unique.

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
    2008-02-14 19:50:41 UTC (rev 7679)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
    2008-02-14 19:52:33 UTC (rev 7680)
@@ -8,14 +8,8 @@
 <block>
        <name>Variable Slider</name>
        <key>variable_slider</key>
-       <fcn />
+       <fcn>$value</fcn>
        <param>
-               <name>Key</name>
-               <key>key</key>
-               <value>my_var</value>
-               <type>var_key</type>
-       </param>
-       <param>
                <name>Value</name>
                <key>value</key>
                <type>real</type>

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/default_flow_graph.grc.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/default_flow_graph.grc.xml
      2008-02-14 19:50:41 UTC (rev 7679)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/default_flow_graph.grc.xml
      2008-02-14 19:52:33 UTC (rev 7680)
@@ -1,4 +1,10 @@
 <?xml version="1.0"?>
+<!-- 
+###################################################
+##Default Flow Graph:
+##     include an options block and a variable for sample rate
+###################################################
+ -->
 <flow_graph>
        <block>
                <key>options</key>
@@ -15,4 +21,19 @@
                        <value>{'x': 20, 'y': 20, 'rot': 0}</value>
                </param>
        </block>
-</flow_graph>
\ No newline at end of file
+       <block>
+               <key>variable</key>
+               <param>
+                       <key>id</key>           
+                       <value>samp_rate</value>
+               </param>        
+               <param>
+                       <key>value</key>                
+                       <value>32e3</value>
+               </param>        
+               <param>
+                       <key>position</key>             
+                       <value>{'x': 20, 'y': 150, 'rot': 0}</value>
+               </param>
+       </block>
+</flow_graph>





reply via email to

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