]> git.gag.com Git - debian/gnuradio/commitdiff
nicer display formatting, and use of eng notation
authorjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Wed, 4 Feb 2009 23:03:47 +0000 (23:03 +0000)
committerjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Wed, 4 Feb 2009 23:03:47 +0000 (23:03 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10391 221aa14e-8319-0410-a670-987f0aec2ac5

grc/data/platforms/python/blocks/gr_threshold_ff.xml
grc/src/platforms/base/Param.py
grc/src/platforms/gui/Param.py
grc/src/platforms/python/Param.py

index 97764d733b50ce2956d6a3da595ebdaba8a75af1..740ce5794c3a2cf7710636fd384913de5b9651e2 100644 (file)
@@ -9,6 +9,8 @@
        <key>gr_threshold_ff</key>
        <import>from gnuradio import gr</import>
        <make>gr.threshold_ff($low, $high, $init)</make>
+       <callback>set_hi($high)</callback>
+       <callback>set_lo($low)</callback>
        <param>
                <name>Low</name>
                <key>low</key>
index 6f512cb870cba2c106d6d2821119c7fc39957cab..ebc9977fc9c693ff9064ffba3c4ec25cb31001cf 100644 (file)
@@ -228,6 +228,16 @@ class Param(Element):
        def get_type(self): return self.get_parent().resolve_dependencies(self._type)
        def is_enum(self): return bool(self.get_options())
 
+       def __repr__(self):
+               """
+               Get the repr (nice string format) for this param.
+               Just return the value (special case enum).
+               Derived classes can handle complex formatting.
+               @return the string representation
+               """
+               if self.is_enum(): return self.get_option(self.get_value()).get_name()
+               return self.get_value()
+
        def get_input_class(self):
                """
                Get the graphical gtk class to represent this parameter.
index 7bc0d354f0145d1cd31838e48dc6bee7d586bae2..2afe18c571b5199c82efc295bd07256a0d8d5da3 100644 (file)
@@ -85,48 +85,15 @@ class Param(Element):
 
        def get_markup(self):
                """
-               Create a markup to display the Param as a label on the SignalBlock.
-               If the data type is an Enum type, use the cname of the Enum's current choice.
-               Otherwise, use parsed the data type and use its string representation.
-               If the data type is not valid, use a red foreground color.
+               Create a markup to display the param as a label on the block.
+               If the param is valid, use the param's repr representation.
+               Otherwise, create a markup for error.
                @return pango markup string
                """
-               ###########################################################################
-               # display logic for numbers
-               ###########################################################################
-               def float_to_str(var):
-                       if var-int(var) == 0: return '%d'%int(var)
-                       if var*10-int(var*10) == 0: return '%.1f'%var
-                       if var*100-int(var*100) == 0: return '%.2f'%var
-                       if var*1000-int(var*1000) == 0: return '%.3f'%var
-                       else: return '%.3g'%var
-               def to_str(var):
-                       if isinstance(var, str): return var
-                       elif isinstance(var, complex):
-                               if var == 0: return '0' #value is zero
-                               elif var.imag == 0: return '%s'%float_to_str(var.real) #value is real
-                               elif var.real == 0: return '%sj'%float_to_str(var.imag) #value is imaginary
-                               elif var.imag < 0: return '%s-%sj'%(float_to_str(var.real), float_to_str(abs(var.imag)))
-                               else: return '%s+%sj'%(float_to_str(var.real), float_to_str(var.imag))
-                       elif isinstance(var, float): return float_to_str(var)
-                       elif isinstance(var, int): return '%d'%var
-                       else: return str(var)
-               ###########################################################################
                if self.is_valid():
-                       data = self.evaluate()
-                       t = self.get_type()
-                       if self.is_enum():
-                               dt_str = self.get_option(self.get_value()).get_name()
-                       elif isinstance(data, (list, tuple, set)): #vector types
-                               if len(data) > 8: dt_str = self.get_value() #large vectors use code
-                               else: dt_str = ', '.join(map(to_str, data)) #small vectors use eval
-                       else: dt_str = to_str(data)     #other types
-                       #truncate
-                       max_len = max(27 - len(self.get_name()), 3)
-                       if len(dt_str) > max_len:
-                               dt_str = dt_str[:max_len/2 -3] + '...' + dt_str[-max_len/2:]
-                       return '<b>%s:</b> %s'%(Utils.xml_encode(self.get_name()), Utils.xml_encode(dt_str))
-               else: return '<span foreground="red"><b>%s:</b> error</span>'%Utils.xml_encode(self.get_name())
+                       return '<b>%s:</b> %s'%(Utils.xml_encode(self.get_name()), Utils.xml_encode(repr(self)))
+               else:
+                       return '<span foreground="red"><b>%s:</b> error</span>'%Utils.xml_encode(self.get_name())
 
        def get_layout(self):
                """
index 42406788fd8c52e68fb1ad734f86d29c5edfad65..f830342a8c33d5508b0b4b6984f30228e1ba2eb0 100644 (file)
@@ -25,6 +25,7 @@ import os
 import pygtk
 pygtk.require('2.0')
 import gtk
+from gnuradio import eng_notation
 
 class FileParam(EntryParam):
        """Provide an entry box for filename and a button to browse for a file."""
@@ -88,6 +89,54 @@ class Param(_Param):
                'grid_pos', 'import',
        ]
 
+       def __repr__(self):
+               """
+               Get the repr (nice string format) for this param.
+               @return the string representation
+               """
+               if self.is_enum(): return _Param.__repr__(self)
+               ##################################################
+               # display logic for numbers
+               ##################################################
+               def to_str(num):
+                       if isinstance(num, str): return num
+                       elif isinstance(num, complex):
+                               if num == 0: return '0' #value is zero
+                               elif num.imag == 0: return '%s'%eng_notation.num_to_str(num.real) #value is real
+                               elif num.real == 0: return '%sj'%eng_notation.num_to_str(num.imag) #value is imaginary
+                               elif num.imag < 0: return '%s-%sj'%(eng_notation.num_to_str(num.real), eng_notation.num_to_str(abs(num.imag)))
+                               else: return '%s+%sj'%(eng_notation.num_to_str(num.real), eng_notation.num_to_str(num.imag))
+                       elif isinstance(num, (float, int)): return eng_notation.num_to_str(num)
+                       else: return str(var)
+               ##################################################
+               # split up formatting by type
+               ##################################################
+               truncate = 0 #default center truncate
+               max_len = max(27 - len(self.get_name()), 3)
+               e = self.evaluate()
+               t = self.get_type()
+               if t in ('int', 'real', 'complex'): dt_str = to_str(e)
+               elif isinstance(e, (list, tuple, set, numpy.ndarray)): #vector types
+                       if len(e) > 8:
+                               dt_str = self.get_value() #large vectors use code
+                               truncate = 1
+                       else: dt_str = ', '.join(map(to_str, e)) #small vectors use eval
+               elif t in ('file_open', 'file_save'):
+                       dt_str = self.get_value()
+                       truncate = -1
+               else: dt_str = to_str(e) #other types
+               ##################################################
+               # truncate
+               ##################################################
+               if len(dt_str) > max_len:
+                       if truncate < 0: #front truncate
+                               dt_str = '...' + dt_str[3-max_len:]
+                       elif truncate == 0: #center truncate
+                               dt_str = dt_str[:max_len/2 -3] + '...' + dt_str[-max_len/2:]
+                       elif truncate > 0: #rear truncate
+                               dt_str = dt_str[:max_len-3] + '...'
+               return dt_str
+
        def get_input_class(self):
                if self.get_type() in ('file_open', 'file_save'): return FileParam
                return _Param.get_input_class(self)