2 Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
3 This file is part of GNU Radio
5 GNU Radio Companion is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 GNU Radio Companion is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 from Element import Element
26 PARAM_MARKUP_TMPL="""\
27 #set $foreground = $param.is_valid() and 'black' or 'red'
28 <span foreground="$foreground" font_desc="Sans 7.5"><b>$encode($param.get_name()): </b>$encode(repr($param))</span>"""
30 PARAM_LABEL_MARKUP_TMPL="""\
31 #set $foreground = $param.is_valid() and 'black' or 'red'
32 #set $underline = $has_cb and 'low' or 'none'
33 <span underline="$underline" foreground="$foreground" font_desc="Sans 9">$encode($param.get_name())</span>"""
37 Type: $param.get_type()
39 Value: $param.get_evaluated()
40 #elif len($param.get_error_messages()) == 1
41 Error: $(param.get_error_messages()[0])
44 #for $error_msg in $param.get_error_messages()
50 """The graphical parameter."""
54 Called when an external change occurs.
55 Update the graphical input by calling the change handler.
57 if hasattr(self, '_input'): self._handle_changed()
59 def get_input_object(self, callback=None):
61 Get the graphical gtk object to represent this parameter.
62 Create the input object with this data type and the handle changed method.
63 @param callback a function of one argument(this param) to be called from the change handler
64 @return gtk input object
66 self._callback = callback
67 self._input = self.get_input_class()(self, self._handle_changed)
68 if not self._callback: self.update()
71 def _handle_changed(self, widget=None):
73 When the input changes, write the inputs to the data type.
74 Finish by calling the exteral callback.
76 self.set_value(self._input.get_text())
78 #is param is involved in a callback? #FIXME: messy
80 hasattr(self.get_parent(), 'get_callbacks') and \
81 filter(lambda c: self.get_key() in c, self.get_parent()._callbacks)
82 self._input.set_markup(Utils.parse_template(PARAM_LABEL_MARKUP_TMPL, param=self, has_cb=has_cb))
84 if self.get_hide() == 'all': self._input.hide_all()
85 else: self._input.show_all()
87 self._input.set_color(self.get_color())
89 if self._input.tp: self._input.tp.set_tip(
91 Utils.parse_template(TIP_MARKUP_TMPL, param=self).strip(),
93 #execute the external callback
94 if self._callback: self._callback(self)
98 Create a layout based on the current markup.
99 @return the pango layout
101 layout = gtk.DrawingArea().create_pango_layout('')
102 layout.set_markup(Utils.parse_template(PARAM_MARKUP_TMPL, param=self))