commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r11199 - in gnuradio/branches/developers/jblum/grc: gr


From: jblum
Subject: [Commit-gnuradio] r11199 - in gnuradio/branches/developers/jblum/grc: gr-wxgui/src/python/forms grc/blocks grc/python
Date: Sun, 14 Jun 2009 22:40:40 -0600 (MDT)

Author: jblum
Date: 2009-06-14 22:40:40 -0600 (Sun, 14 Jun 2009)
New Revision: 11199

Modified:
   gnuradio/branches/developers/jblum/grc/gr-wxgui/src/python/forms/forms.py
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_chooser.xml
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_slider.xml
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_text_box.xml
   gnuradio/branches/developers/jblum/grc/grc/python/Block.py
   gnuradio/branches/developers/jblum/grc/grc/python/Generator.py
   gnuradio/branches/developers/jblum/grc/grc/python/expr_utils.py
   gnuradio/branches/developers/jblum/grc/grc/python/flow_graph.tmpl
Log:
Replaced expression utils prepend function with find-replace function.
Added callbacks for the variables controls/forms... Now a graphical variable 
could change another.
Minor change to forms so that the callback is only called from an internal 
change event.



Modified: 
gnuradio/branches/developers/jblum/grc/gr-wxgui/src/python/forms/forms.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/gr-wxgui/src/python/forms/forms.py   
2009-06-15 03:19:16 UTC (rev 11198)
+++ gnuradio/branches/developers/jblum/grc/gr-wxgui/src/python/forms/forms.py   
2009-06-15 04:40:40 UTC (rev 11199)
@@ -115,7 +115,6 @@
                self.subscribe(INT_KEY, update)
                self.subscribe(INT_KEY, self._translate_internal_to_external)
                self.subscribe(EXT_KEY, self._translate_external_to_internal)
-               if self._callback: self.subscribe(EXT_KEY, self._callback)
 
        def _translate_external_to_internal(self, external):
                try:
@@ -134,6 +133,7 @@
                except Exception, e:
                        self._err_msg(internal, e)
                        self[EXT_KEY] = self[EXT_KEY] #reset to last good 
setting
+               if self._callback: self._callback(self[EXT_KEY])
 
        def _err_msg(self, value, e):
                print >> sys.stderr, self, 'Error translating value: 
"%s"\n\t%s\n\t%s'%(value, e, self._converter.help())

Modified: gnuradio/branches/developers/jblum/grc/grc/blocks/variable_chooser.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable_chooser.xml      
2009-06-15 03:19:16 UTC (rev 11198)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_chooser.xml      
2009-06-15 04:40:40 UTC (rev 11199)
@@ -11,12 +11,10 @@
        <key>variable_chooser</key>
        <import>from gnuradio.wxgui import forms</import>
        <make>$value
-self['$id'] = $id
-self.subscribe('$id', self.set_$(id))
-self._$(id)_control = forms.$(type)(
+self.$(id)_chooser = forms.$(type)(
        parent=self.GetWin(),
-       ps=self,
-       key='$id',
+       value=self.$id,
+       callback=self.set_$(id),
        #if $label()
        label=$label,
        #else
@@ -30,10 +28,11 @@
 )
 #set $grid_pos = $grid_pos()
 #if not grid_pos
-self.Add(self._$(id)_control)
+self.Add(self.$(id)_chooser)
 #else
-self.GridAdd(self._$(id)_control, $grid_pos[0], $grid_pos[1], $grid_pos[2], 
$grid_pos[3])
+self.GridAdd(self.$(id)_chooser, $grid_pos[0], $grid_pos[1], $grid_pos[2], 
$grid_pos[3])
 #end if</make>
+       <callback>self.$(id)_chooser.set_value($id)</callback>
        <param>
                <name>Label</name>
                <key>label</key>

Modified: gnuradio/branches/developers/jblum/grc/grc/blocks/variable_slider.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable_slider.xml       
2009-06-15 03:19:16 UTC (rev 11198)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_slider.xml       
2009-06-15 04:40:40 UTC (rev 11199)
@@ -10,14 +10,12 @@
        <key>variable_slider</key>
        <import>from gnuradio.wxgui import forms</import>
        <make>$value
-self['$id'] = $id
-self.subscribe('$id', self.set_$(id))
-self._$(id)_sizer = wx.BoxSizer(wx.VERTICAL)
-forms.text_box(
+_$(id)_sizer = wx.BoxSizer(wx.VERTICAL)
+self.$(id)_text_box = forms.text_box(
        parent=self.GetWin(),
-       sizer=self._$(id)_sizer,
-       ps=self,
-       key='$id',
+       sizer=_$(id)_sizer,
+       value=self.$id,
+       callback=self.set_$(id),
        #if $label()
        label=$label,
        #else
@@ -26,11 +24,11 @@
        converter=forms.$(converver)(),
        proportion=0,
 )
-forms.slider(
+self.$(id)_slider = forms.slider(
        parent=self.GetWin(),
-       sizer=self._$(id)_sizer,
-       ps=self,
-       key='$id',
+       sizer=_$(id)_sizer,
+       value=self.$id,
+       callback=self.set_$(id),
        minimum=$min,
        maximum=$max,
        num_steps=$num_steps,
@@ -40,10 +38,12 @@
 )
 #set $grid_pos = $grid_pos()
 #if not grid_pos
-self.Add(self._$(id)_sizer)
+self.Add(_$(id)_sizer)
 #else
-self.GridAdd(self._$(id)_sizer, $grid_pos[0], $grid_pos[1], $grid_pos[2], 
$grid_pos[3])
+self.GridAdd(_$(id)_sizer, $grid_pos[0], $grid_pos[1], $grid_pos[2], 
$grid_pos[3])
 #end if</make>
+       <callback>self.$(id)_slider.set_value($id)</callback>
+       <callback>self.$(id)_text_box.set_value($id)</callback>
        <param>
                <name>Label</name>
                <key>label</key>

Modified: 
gnuradio/branches/developers/jblum/grc/grc/blocks/variable_text_box.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable_text_box.xml     
2009-06-15 03:19:16 UTC (rev 11198)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_text_box.xml     
2009-06-15 04:40:40 UTC (rev 11199)
@@ -10,12 +10,12 @@
        <key>variable_text_box</key>
        <import>from gnuradio.wxgui import forms</import>
        <make>$value
-self['$id'] = $id
+self['$id'] = self.$id
 self.subscribe('$id', self.set_$(id))
-self._$(id)_control = forms.text_box(
+self.$(id)_text_box = forms.text_box(
        parent=self.GetWin(),
-       ps=self,
-       key='$id',
+       value=self.$id,
+       callback=self.set_$(id),
        #if $label()
        label=$label,
        #else
@@ -25,10 +25,11 @@
 )
 #set $grid_pos = $grid_pos()
 #if not grid_pos
-self.Add(self._$(id)_control)
+self.Add(self.$(id)_text_box)
 #else
-self.GridAdd(self._$(id)_control, $grid_pos[0], $grid_pos[1], $grid_pos[2], 
$grid_pos[3])
+self.GridAdd(self.$(id)_text_box, $grid_pos[0], $grid_pos[1], $grid_pos[2], 
$grid_pos[3])
 #end if</make>
+       <callback>self.$(id)_text_box.set_value($id)</callback>
        <param>
                <name>Label</name>
                <key>label</key>

Modified: gnuradio/branches/developers/jblum/grc/grc/python/Block.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/Block.py  2009-06-15 
03:19:16 UTC (rev 11198)
+++ gnuradio/branches/developers/jblum/grc/grc/python/Block.py  2009-06-15 
04:40:40 UTC (rev 11199)
@@ -149,4 +149,8 @@
                Get a list of function callbacks for this block.
                @return a list of strings
                """
-               return map(lambda c: self.get_id() + '.' + 
self.resolve_dependencies(c), self._callbacks)
+               def make_callback(callback):
+                       callback = self.resolve_dependencies(callback)
+                       if callback.startswith('self.'): return callback
+                       return 'self.%s.%s'%(self.get_id(), callback)
+               return map(make_callback, self._callbacks)

Modified: gnuradio/branches/developers/jblum/grc/grc/python/Generator.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/Generator.py      
2009-06-15 03:19:16 UTC (rev 11198)
+++ gnuradio/branches/developers/jblum/grc/grc/python/Generator.py      
2009-06-15 04:40:40 UTC (rev 11199)
@@ -94,14 +94,16 @@
                connections = self._flow_graph.get_enabled_connections()
                #list of variable names
                var_ids = [var.get_id() for var in parameters + variables]
-               #list of callbacks (prepend self.)
+               #prepend self.
+               replace_dict = dict([(var_id, 'self.%s'%var_id) for var_id in 
var_ids])
+               #list of callbacks
                callbacks = [
-                       expr_utils.expr_prepend(cb, var_ids, 'self.')
+                       expr_utils.expr_replace(cb, replace_dict)
                        for cb in sum([block.get_callbacks() for block in 
self._flow_graph.get_enabled_blocks()], [])
                ]
-               #map var id to the expression (prepend self.)
+               #map var id to the expression
                var_id2expr = dict(
-                       [(var.get_id(), 
expr_utils.expr_prepend(var.get_make().split('\n')[0], var_ids, 'self.'))
+                       [(var.get_id(), 
expr_utils.expr_replace(var.get_make().split('\n')[0], replace_dict))
                        for var in parameters + variables]
                )
                #create graph structure for variables

Modified: gnuradio/branches/developers/jblum/grc/grc/python/expr_utils.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/expr_utils.py     
2009-06-15 03:19:16 UTC (rev 11198)
+++ gnuradio/branches/developers/jblum/grc/grc/python/expr_utils.py     
2009-06-15 04:40:40 UTC (rev 11199)
@@ -75,17 +75,17 @@
        toks.append(tok)
        return filter(lambda t: t, toks)
 
-def expr_prepend(expr, vars, prepend):
+def expr_replace(expr, replace_dict):
        """
        Search for vars in the expression and add the prepend.
        @param expr an expression string
-       @param vars a list of variable names
-       @param prepend the prepend string
+       @param replace_dict a dict of find:replace
        @return a new expression with the prepend
        """
        expr_splits = expr_split(expr)
        for i, es in enumerate(expr_splits):
-               if es in vars: expr_splits[i] = prepend + es
+               if es in replace_dict.keys():
+                       expr_splits[i] = replace_dict[es]
        return ''.join(expr_splits)
 
 def get_variable_dependencies(expr, vars):

Modified: gnuradio/branches/developers/jblum/grc/grc/python/flow_graph.tmpl
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/flow_graph.tmpl   
2009-06-15 03:19:16 UTC (rev 11198)
+++ gnuradio/branches/developers/jblum/grc/grc/python/flow_graph.tmpl   
2009-06-15 04:40:40 UTC (rev 11199)
@@ -172,7 +172,7 @@
                self.set_$(dep)($var_id2expr[$dep])
        #end for
        #for $callback in $var_id2cbs[$id]
-               self.$callback
+               $callback
        #end for
 
 #end for





reply via email to

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