diff options
author | jblum | 2009-02-04 23:03:47 +0000 |
---|---|---|
committer | jblum | 2009-02-04 23:03:47 +0000 |
commit | 68282b6ffed904bb55700314a600fe5d731dd0ea (patch) | |
tree | ae0ac23e82788e2568761677adc6b5a6cce07c9f /grc/src/platforms/python/Param.py | |
parent | f21c7b1eeed46a2edf5b082d86d5386790e99f98 (diff) | |
download | gnuradio-68282b6ffed904bb55700314a600fe5d731dd0ea.tar.gz gnuradio-68282b6ffed904bb55700314a600fe5d731dd0ea.tar.bz2 gnuradio-68282b6ffed904bb55700314a600fe5d731dd0ea.zip |
nicer display formatting, and use of eng notation
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10391 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc/src/platforms/python/Param.py')
-rw-r--r-- | grc/src/platforms/python/Param.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/grc/src/platforms/python/Param.py b/grc/src/platforms/python/Param.py index 42406788f..f830342a8 100644 --- a/grc/src/platforms/python/Param.py +++ b/grc/src/platforms/python/Param.py @@ -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) |