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/gui | |
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/gui')
-rw-r--r-- | grc/src/platforms/gui/Param.py | 45 |
1 files changed, 6 insertions, 39 deletions
diff --git a/grc/src/platforms/gui/Param.py b/grc/src/platforms/gui/Param.py index 7bc0d354f..2afe18c57 100644 --- a/grc/src/platforms/gui/Param.py +++ b/grc/src/platforms/gui/Param.py @@ -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): """ |