commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: jblum
Subject: [Commit-gnuradio] r11208 - in gnuradio/branches/developers/jblum/grc: gr-wxgui/src/python/forms grc/base grc/blocks grc/grc_gnuradio/wxgui grc/python
Date: Tue, 16 Jun 2009 19:05:38 -0600 (MDT)

Author: jblum
Date: 2009-06-16 19:05:37 -0600 (Tue, 16 Jun 2009)
New Revision: 11208

Added:
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_check_box.xml
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_static_text.xml
Modified:
   
gnuradio/branches/developers/jblum/grc/gr-wxgui/src/python/forms/converters.py
   gnuradio/branches/developers/jblum/grc/grc/base/Platform.py
   gnuradio/branches/developers/jblum/grc/grc/blocks/Makefile.am
   gnuradio/branches/developers/jblum/grc/grc/blocks/block_tree.xml
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_text_box.xml
   
gnuradio/branches/developers/jblum/grc/grc/grc_gnuradio/wxgui/top_block_gui.py
   gnuradio/branches/developers/jblum/grc/grc/python/FlowGraph.py
   gnuradio/branches/developers/jblum/grc/grc/python/Param.py
Log:
Added variable static text and check box.
Use regexps for id matching in python platform.
Added formatter args to int, str, and eval converters.



Modified: 
gnuradio/branches/developers/jblum/grc/gr-wxgui/src/python/forms/converters.py
===================================================================
--- 
gnuradio/branches/developers/jblum/grc/gr-wxgui/src/python/forms/converters.py  
    2009-06-16 06:51:25 UTC (rev 11207)
+++ 
gnuradio/branches/developers/jblum/grc/gr-wxgui/src/python/forms/converters.py  
    2009-06-17 01:05:37 UTC (rev 11208)
@@ -85,22 +85,28 @@
        Possible uses, set a complex number, constellation points.
        Used in text box.
        """
-       def external_to_internal(self, s):
-               return str(s)
+       def __init__(self, formatter=lambda x: '%s'%(x)):
+               self._formatter = formatter
+       def external_to_internal(self, v):
+               return self._formatter(v)
        def internal_to_external(self, s):
                return eval(s)
        def help(self):
                return "Value must be evaluatable by python's eval."
 
 class str_converter(abstract_converter):
+       def __init__(self, formatter=lambda x: '%s'%(x)):
+               self._formatter = formatter
        def external_to_internal(self, v):
-               return str(v)
+               return self._formatter(v)
        def internal_to_external(self, s):
                return str(s)
 
 class int_converter(abstract_converter):
+       def __init__(self, formatter=lambda x: '%d'%round(x)):
+               self._formatter = formatter
        def external_to_internal(self, v):
-               return str(int(round(v)))
+               return self._formatter(v)
        def internal_to_external(self, s):
                return int(s, 0)
        def help(self):

Modified: gnuradio/branches/developers/jblum/grc/grc/base/Platform.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/base/Platform.py 2009-06-16 
06:51:25 UTC (rev 11207)
+++ gnuradio/branches/developers/jblum/grc/grc/base/Platform.py 2009-06-17 
01:05:37 UTC (rev 11208)
@@ -83,7 +83,7 @@
                                        ParseXML.validate_dtd(xml_file, 
BLOCK_TREE_DTD)
                                        self._block_tree_files.append(xml_file)
                                except ParseXML.XMLSyntaxError, e:
-                                       print >> sys.stderr, 'Warning: Block 
validation failed: %s\n\tIgnoring: %s'%(e, xml_file)
+                                       print >> sys.stderr, 'Warning: Block 
validation failed:\n\t%s\n\tIgnoring: %s'%(e, xml_file)
 
        def parse_flow_graph(self, flow_graph_file):
                """
@@ -114,15 +114,19 @@
                        map(lambda c: load_category(c, parent), 
cat_n.findall('cat'))
                        #add blocks in this category
                        for block_key in cat_n.findall('block'):
+                               if block_key not in self.get_block_keys():
+                                       print >> sys.stderr, 'Warning: Block 
key "%s" not found when loading category tree.'%(block_key)
+                                       continue
                                block_tree.add_block(parent, 
self.get_block(block_key))
                #load the block tree
                for block_tree_file in self._block_tree_files:
-                       #add all blocks in the tree
+                       #recursivly add all blocks in the tree
                        
load_category(ParseXML.from_file(block_tree_file).find('cat'))
-                       #add all other blocks, use the catgory
-                       for block in self.get_blocks():
-                               #blocks with empty categories are in the xml 
block tree or hidden
-                               if block.get_category(): 
block_tree.add_block(block.get_category(), block)
+               #add all other blocks, use the catgory tag
+               for block in self.get_blocks():
+                       #blocks with empty categories are in the xml block tree 
or hidden
+                       if not block.get_category(): continue
+                       block_tree.add_block(block.get_category(), block)
 
        def __str__(self): return 'Platform - %s(%s)'%(self.get_key(), 
self.get_name())
 

Modified: gnuradio/branches/developers/jblum/grc/grc/blocks/Makefile.am
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/Makefile.am       
2009-06-16 06:51:25 UTC (rev 11207)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/Makefile.am       
2009-06-17 01:05:37 UTC (rev 11208)
@@ -207,8 +207,10 @@
        usrp_simple_sink_x.xml \
        usrp_simple_source_x.xml \
        variable.xml \
+       variable_check_box.xml \
        variable_chooser.xml \
        variable_slider.xml \
+       variable_static_text.xml \
        variable_text_box.xml \
        wxgui_constellationsink2.xml \
        wxgui_fftsink2.xml \

Modified: gnuradio/branches/developers/jblum/grc/grc/blocks/block_tree.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/block_tree.xml    
2009-06-16 06:51:25 UTC (rev 11207)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/block_tree.xml    
2009-06-17 01:05:37 UTC (rev 11208)
@@ -265,7 +265,9 @@
                <block>variable</block>
                <block>variable_slider</block>
                <block>variable_chooser</block>
+               <block>variable_check_box</block>
                <block>variable_text_box</block>
+               <block>variable_static_text</block>
                <block>parameter</block>
        </cat>
        <cat>

Added: gnuradio/branches/developers/jblum/grc/grc/blocks/variable_check_box.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable_check_box.xml    
                        (rev 0)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_check_box.xml    
2009-06-17 01:05:37 UTC (rev 11208)
@@ -0,0 +1,74 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Variable Check Box:
+##     a gui check box form
+###################################################
+ -->
+<block>
+       <name>Variable Check Box</name>
+       <key>variable_check_box</key>
+       <import>from gnuradio.wxgui import forms</import>
+       <make>$value
+self.$(id)_check_box = forms.check_box(
+       parent=self.GetWin(),
+       value=self.$id,
+       callback=self.set_$(id),
+       #if $label()
+       label=$label,
+       #else
+       label='$id',
+       #end if
+       true=$true,
+       false=$false,
+)
+#set $grid_pos = $grid_pos()
+#if not grid_pos
+self.Add(self.$(id)_check_box)
+#else
+self.GridAdd(self.$(id)_check_box, $grid_pos[0], $grid_pos[1], $grid_pos[2], 
$grid_pos[3])
+#end if</make>
+       <callback>self.$(id)_check_box.set_value($id)</callback>
+       <param>
+               <name>Label</name>
+               <key>label</key>
+               <value></value>
+               <type>string</type>
+               <hide>#if $label() then 'none' else 'part'#</hide>
+       </param>
+       <param>
+               <name>Default Value</name>
+               <key>value</key>
+               <value>True</value>
+               <type>raw</type>
+       </param>
+       <param>
+               <name>True</name>
+               <key>true</key>
+               <value>True</value>
+               <type>raw</type>
+       </param>
+       <param>
+               <name>False</name>
+               <key>false</key>
+               <value>False</value>
+               <type>raw</type>
+       </param>
+       <param>
+               <name>Grid Position</name>
+               <key>grid_pos</key>
+               <value></value>
+               <type>grid_pos</type>
+       </param>
+       <check>$value in ($true, $false)</check>
+       <doc>
+This block creates a variable with a check box form. \
+Leave the label blank to use the variable id as the label.
+
+A check box form can switch between two states; \
+the default being True and False. \
+Override True and False to use alternative states.
+
+Use the Grid Position (row, column, row span, column span) to position the 
graphical element in the window.
+       </doc>
+</block>

Added: 
gnuradio/branches/developers/jblum/grc/grc/blocks/variable_static_text.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable_static_text.xml  
                        (rev 0)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_static_text.xml  
2009-06-17 01:05:37 UTC (rev 11208)
@@ -0,0 +1,87 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Variable Static Text:
+##     a gui static text form
+###################################################
+ -->
+<block>
+       <name>Variable Static Text</name>
+       <key>variable_static_text</key>
+       <import>from gnuradio.wxgui import forms</import>
+       <make>$value
+self.$(id)_static_text = forms.static_text(
+       parent=self.GetWin(),
+       value=self.$id,
+       callback=self.set_$(id),
+       #if $label()
+       label=$label,
+       #else
+       label='$id',
+       #end if
+       #if $formatter()
+       converter=forms.$(converver)(formatter=$formatter),
+       #else
+       converter=forms.$(converver)(),
+       #end if
+)
+#set $grid_pos = $grid_pos()
+#if not grid_pos
+self.Add(self.$(id)_static_text)
+#else
+self.GridAdd(self.$(id)_static_text, $grid_pos[0], $grid_pos[1], $grid_pos[2], 
$grid_pos[3])
+#end if</make>
+       <callback>self.$(id)_static_text.set_value($id)</callback>
+       <param>
+               <name>Label</name>
+               <key>label</key>
+               <value></value>
+               <type>string</type>
+               <hide>#if $label() then 'none' else 'part'#</hide>
+       </param>
+       <param>
+               <name>Default Value</name>
+               <key>value</key>
+               <value>0</value>
+               <type>raw</type>
+       </param>
+       <param>
+               <name>Converter</name>
+               <key>converver</key>
+               <value>float_converter</value>
+               <type>enum</type>
+               <option>
+                       <name>Float</name>
+                       <key>float_converter</key>
+               </option>
+               <option>
+                       <name>Integer</name>
+                       <key>int_converter</key>
+               </option>
+               <option>
+                       <name>String</name>
+                       <key>str_converter</key>
+               </option>
+       </param>
+       <param>
+               <name>Formatter</name>
+               <key>formatter</key>
+               <value>None</value>
+               <type>raw</type>
+               <hide>part</hide>
+       </param>
+       <param>
+               <name>Grid Position</name>
+               <key>grid_pos</key>
+               <value></value>
+               <type>grid_pos</type>
+       </param>
+       <doc>
+This block creates a variable with a static text form. \
+Leave the label blank to use the variable id as the label.
+
+Format should be a function/lambda that converts a value into a string or None 
for the default formatter.
+
+Use the Grid Position (row, column, row span, column span) to position the 
graphical element in the window.
+       </doc>
+</block>

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-16 06:51:25 UTC (rev 11207)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_text_box.xml     
2009-06-17 01:05:37 UTC (rev 11208)
@@ -10,8 +10,6 @@
        <key>variable_text_box</key>
        <import>from gnuradio.wxgui import forms</import>
        <make>$value
-self['$id'] = self.$id
-self.subscribe('$id', self.set_$(id))
 self.$(id)_text_box = forms.text_box(
        parent=self.GetWin(),
        value=self.$id,
@@ -21,7 +19,11 @@
        #else
        label='$id',
        #end if
+       #if $formatter()
+       converter=forms.$(converver)(formatter=$formatter),
+       #else
        converter=forms.$(converver)(),
+       #end if
 )
 #set $grid_pos = $grid_pos()
 #if not grid_pos
@@ -66,6 +68,13 @@
                </option>
        </param>
        <param>
+               <name>Formatter</name>
+               <key>formatter</key>
+               <value>None</value>
+               <type>raw</type>
+               <hide>part</hide>
+       </param>
+       <param>
                <name>Grid Position</name>
                <key>grid_pos</key>
                <value></value>
@@ -75,6 +84,8 @@
 This block creates a variable with a text box. \
 Leave the label blank to use the variable id as the label.
 
+Format should be a function/lambda that converts a value into a string or None 
for the default formatter.
+
 Use the Grid Position (row, column, row span, column span) to position the 
graphical element in the window.
        </doc>
 </block>

Modified: 
gnuradio/branches/developers/jblum/grc/grc/grc_gnuradio/wxgui/top_block_gui.py
===================================================================
--- 
gnuradio/branches/developers/jblum/grc/grc/grc_gnuradio/wxgui/top_block_gui.py  
    2009-06-16 06:51:25 UTC (rev 11207)
+++ 
gnuradio/branches/developers/jblum/grc/grc/grc_gnuradio/wxgui/top_block_gui.py  
    2009-06-17 01:05:37 UTC (rev 11208)
@@ -21,11 +21,10 @@
 import wx
 import sys, os
 from gnuradio import gr
-from gnuradio.gr.pubsub import pubsub
 
 default_gui_size = (200, 100)
 
-class top_block_gui(gr.top_block, pubsub):
+class top_block_gui(gr.top_block):
        """gr top block with wx gui app and grid sizer."""
 
        def __init__(self, title='', size=default_gui_size, icon=None):
@@ -38,7 +37,6 @@
                """
                #initialize
                gr.top_block.__init__(self)
-               pubsub.__init__(self)
                self._size = size
                #set the icon
                if icon and os.path.isfile(icon): self._icon = icon

Modified: gnuradio/branches/developers/jblum/grc/grc/python/FlowGraph.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/FlowGraph.py      
2009-06-16 06:51:25 UTC (rev 11207)
+++ gnuradio/branches/developers/jblum/grc/grc/python/FlowGraph.py      
2009-06-17 01:05:37 UTC (rev 11208)
@@ -21,7 +21,11 @@
 from .. base.FlowGraph import FlowGraph as _FlowGraph
 from Block import Block
 from Connection import Connection
+import re
 
+_variable_matcher = re.compile('^(variable\w*)$')
+_parameter_matcher = re.compile('^(parameter)$')
+
 def _get_value_expr(variable_block):
        """
        Get the expression to evaluate from the value param.
@@ -30,7 +34,7 @@
        @return the expression string
        """
        value_param = variable_block.get_param('value')
-       if variable_block.get_key() == 'parameter': value_param.evaluate()
+       if _parameter_matcher.match(variable_block.get_key()): 
value_param.evaluate()
        return value_param.to_code()
 
 class FlowGraph(_FlowGraph):
@@ -104,9 +108,7 @@
                Exclude paramterized variables.
                @return a sorted list of variable blocks in order of dependency 
(indep -> dep)
                """
-               variables = filter(lambda b: b.get_key() in (
-                       'variable', 'variable_slider', 'variable_chooser', 
'variable_text_box'
-               ), self.get_enabled_blocks())
+               variables = filter(lambda b: 
_variable_matcher.match(b.get_key()), self.get_enabled_blocks())
                #map var id to variable block
                id2var = dict([(var.get_id(), var) for var in variables])
                #map var id to variable code
@@ -123,7 +125,7 @@
                Get a list of all paramterized variables in this flow graph 
namespace.
                @return a list of paramterized variables
                """
-               parameters = filter(lambda b: b.get_key() == 'parameter', 
self.get_enabled_blocks())
+               parameters = filter(lambda b: 
_parameter_matcher.match(b.get_key()), self.get_enabled_blocks())
                return parameters
 
        def evaluate(self, expr):

Modified: gnuradio/branches/developers/jblum/grc/grc/python/Param.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/Param.py  2009-06-16 
06:51:25 UTC (rev 11207)
+++ gnuradio/branches/developers/jblum/grc/grc/python/Param.py  2009-06-17 
01:05:37 UTC (rev 11208)
@@ -26,7 +26,10 @@
 pygtk.require('2.0')
 import gtk
 from gnuradio import eng_notation
+import re
 
+_show_id_matcher = re.compile('^(variable\w*|parameter|options)$')
+
 class FileParam(EntryParam):
        """Provide an entry box for filename and a button to browse for a 
file."""
 
@@ -117,7 +120,8 @@
                max_len = max(27 - len(self.get_name()), 3)
                e = self.evaluate()
                t = self.get_type()
-               if isinstance(e, COMPLEX_TYPES): dt_str = num_to_str(e)
+               if isinstance(e, bool): return str(e)
+               elif isinstance(e, COMPLEX_TYPES): dt_str = num_to_str(e)
                elif isinstance(e, VECTOR_TYPES): #vector types
                        if len(e) > 8:
                                dt_str = self.get_value() #large vectors use 
code
@@ -178,9 +182,7 @@
                hide = _Param.get_hide(self)
                if hide: return hide
                #hide ID in non variable blocks
-               if self.get_key() == 'id' and self.get_parent().get_key() not 
in (
-                       'variable', 'variable_slider', 'variable_chooser', 
'variable_text_box', 'parameter', 'options'
-               ): return 'part'
+               if self.get_key() == 'id' and not 
_show_id_matcher.match(self.get_parent().get_key()): return 'part'
                #hide port controllers for type and nports
                if self.get_key() in ' '.join(map(
                        lambda p: ' '.join([p._type, p._nports]), 
self.get_parent().get_ports())





reply via email to

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