[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10391 - in gnuradio/trunk/grc: data/platforms/python/
From: |
jblum |
Subject: |
[Commit-gnuradio] r10391 - in gnuradio/trunk/grc: data/platforms/python/blocks src/platforms/base src/platforms/gui src/platforms/python |
Date: |
Wed, 4 Feb 2009 16:03:48 -0700 (MST) |
Author: jblum
Date: 2009-02-04 16:03:47 -0700 (Wed, 04 Feb 2009)
New Revision: 10391
Modified:
gnuradio/trunk/grc/data/platforms/python/blocks/gr_threshold_ff.xml
gnuradio/trunk/grc/src/platforms/base/Param.py
gnuradio/trunk/grc/src/platforms/gui/Param.py
gnuradio/trunk/grc/src/platforms/python/Param.py
Log:
nicer display formatting, and use of eng notation
Modified: gnuradio/trunk/grc/data/platforms/python/blocks/gr_threshold_ff.xml
===================================================================
--- gnuradio/trunk/grc/data/platforms/python/blocks/gr_threshold_ff.xml
2009-02-04 22:46:43 UTC (rev 10390)
+++ gnuradio/trunk/grc/data/platforms/python/blocks/gr_threshold_ff.xml
2009-02-04 23:03:47 UTC (rev 10391)
@@ -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>
Modified: gnuradio/trunk/grc/src/platforms/base/Param.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/base/Param.py 2009-02-04 22:46:43 UTC
(rev 10390)
+++ gnuradio/trunk/grc/src/platforms/base/Param.py 2009-02-04 23:03:47 UTC
(rev 10391)
@@ -228,6 +228,16 @@
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.
Modified: gnuradio/trunk/grc/src/platforms/gui/Param.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/Param.py 2009-02-04 22:46:43 UTC
(rev 10390)
+++ gnuradio/trunk/grc/src/platforms/gui/Param.py 2009-02-04 23:03:47 UTC
(rev 10391)
@@ -85,48 +85,15 @@
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):
"""
Modified: gnuradio/trunk/grc/src/platforms/python/Param.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/python/Param.py 2009-02-04 22:46:43 UTC
(rev 10390)
+++ gnuradio/trunk/grc/src/platforms/python/Param.py 2009-02-04 23:03:47 UTC
(rev 10391)
@@ -25,6 +25,7 @@
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 @@
'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)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10391 - in gnuradio/trunk/grc: data/platforms/python/blocks src/platforms/base src/platforms/gui src/platforms/python,
jblum <=