diff options
author | jblum | 2009-05-01 20:28:04 +0000 |
---|---|---|
committer | jblum | 2009-05-01 20:28:04 +0000 |
commit | a3ba8cf268816af51c4bb39ea7ecd7e85ea0807b (patch) | |
tree | 21dbd446e92672a56b323e005088d3c03edc238f /grc/src/platforms/gui/Param.py | |
parent | 6ce881caaacdd60a8bea37584c7286e08bea97a7 (diff) | |
download | gnuradio-a3ba8cf268816af51c4bb39ea7ecd7e85ea0807b.tar.gz gnuradio-a3ba8cf268816af51c4bb39ea7ecd7e85ea0807b.tar.bz2 gnuradio-a3ba8cf268816af51c4bb39ea7ecd7e85ea0807b.zip |
Merged grc developer branch r10679:10938
Misc fixes and internal changes.
Added help menu for usage tips.
Added drag and drop for blocks.
Removed callback controls, adopted forms.
Any type can have enumerated options.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10941 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc/src/platforms/gui/Param.py')
-rw-r--r-- | grc/src/platforms/gui/Param.py | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/grc/src/platforms/gui/Param.py b/grc/src/platforms/gui/Param.py index 2afe18c57..33a9b1f52 100644 --- a/grc/src/platforms/gui/Param.py +++ b/grc/src/platforms/gui/Param.py @@ -1,5 +1,5 @@ """ -Copyright 2007 Free Software Foundation, Inc. +Copyright 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -22,8 +22,30 @@ from Element import Element import pygtk pygtk.require('2.0') import gtk -import pango -from Constants import PARAM_LABEL_FONT, PARAM_FONT + +PARAM_MARKUP_TMPL="""\ +#set $foreground = $param.is_valid() and 'black' or 'red' +#set $value = not $param.is_valid() and 'error' or repr($param) +<span foreground="$foreground" font_desc="Sans 7.5"><b>$encode($param.get_name()): </b>$encode($value)</span>""" + +PARAM_LABEL_MARKUP_TMPL="""\ +#set $foreground = $param.is_valid() and 'black' or 'red' +#set $underline = $has_cb and 'low' or 'none' +<span underline="$underline" foreground="$foreground" font_desc="Sans 9">$encode($param.get_name())</span>""" + +TIP_MARKUP_TMPL="""\ +Key: $param.get_key() +Type: $param.get_type() +#if $param.is_valid() +Value: $param.evaluate() +#elif len($param.get_error_messages()) == 1 +Error: $(param.get_error_messages()[0]) +#else +Error: + #for $error_msg in $param.get_error_messages() + * $error_msg + #end for +#end if""" class Param(Element): """The graphical parameter.""" @@ -52,24 +74,12 @@ class Param(Element): When the input changes, write the inputs to the data type. Finish by calling the exteral callback. """ - value = self._input.get_text() - if self.is_enum(): value = self.get_option_keys()[int(value)] - self.set_value(value) - #set the markup on the label, red for errors in corresponding data type. - name = '<span font_desc="%s">%s</span>'%( - PARAM_LABEL_FONT, - Utils.xml_encode(self.get_name()), - ) - #special markups if param is involved in a callback - if hasattr(self.get_parent(), 'get_callbacks') and \ - filter(lambda c: self.get_key() in c, self.get_parent()._callbacks): - name = '<span underline="low">%s</span>'%name - if not self.is_valid(): - self._input.set_markup('<span foreground="red">%s</span>'%name) - tip = 'Error: ' + ' '.join(self.get_error_messages()) - else: - self._input.set_markup(name) - tip = 'Value: %s'%str(self.evaluate()) + self.set_value(self._input.get_text()) + #is param is involved in a callback? #FIXME: messy + has_cb = \ + hasattr(self.get_parent(), 'get_callbacks') and \ + filter(lambda c: self.get_key() in c, self.get_parent()._callbacks) + self._input.set_markup(Utils.parse_template(PARAM_LABEL_MARKUP_TMPL, param=self, has_cb=has_cb)) #hide/show if self.get_hide() == 'all': self._input.hide_all() else: self._input.show_all() @@ -78,30 +88,16 @@ class Param(Element): #set the tooltip if self._input.tp: self._input.tp.set_tip( self._input.entry, - 'Key: %s\nType: %s\n%s'%(self.get_key(), self.get_type(), tip), + Utils.parse_template(TIP_MARKUP_TMPL, param=self).strip(), ) #execute the external callback if self._callback: self._callback(self) - def get_markup(self): - """ - 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 - """ - if self.is_valid(): - 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): """ Create a layout based on the current markup. @return the pango layout """ layout = gtk.DrawingArea().create_pango_layout('') - layout.set_markup(self.get_markup()) - desc = pango.FontDescription(PARAM_FONT) - layout.set_font_description(desc) + layout.set_markup(Utils.parse_template(PARAM_MARKUP_TMPL, param=self)) return layout |