2 Copyright 2007 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
19 ##@package grc.gui.ParamsDialog
20 #A dialog for editing a block's parameters.
27 from Dialogs import TextDisplay
28 from grc.Constants import MIN_DIALOG_WIDTH,MIN_DIALOG_HEIGHT
30 def get_title_label(title):
32 Get a title label for the params window.
33 The title will be bold, underlined, and left justified.
34 @param title the text of the title
38 label.set_markup('\n<b><span underline="low">%s</span>:</b>\n'%title)
40 hbox.pack_start(label, False, False, padding=11)
43 class ParamsDialog(gtk.Dialog):
44 """A dialog box to set block parameters."""
46 def __init__(self, block):
48 SignalBlockParamsDialog contructor.
49 @param block the signal block
51 gtk.Dialog.__init__(self, buttons=('gtk-close', gtk.RESPONSE_CLOSE))
53 self.set_title('Properties: %s'%block.get_name())
54 self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
57 vbox.pack_start(get_title_label('Parameters'), False)
58 #Create the scrolled window to hold all the parameters
59 scrolled_window = gtk.ScrolledWindow()
60 scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
61 scrolled_window.add_with_viewport(vbox)
62 self.vbox.pack_start(scrolled_window, True)
63 #Error Messages for the block
64 self._error_messages_box = err_box = gtk.VBox()
65 self._error_messages_text_display = TextDisplay('')
66 err_box.pack_start(gtk.Label(''), False, False, 7) #spacing
67 err_box.pack_start(get_title_label('Error Messages'), False)
68 err_box.pack_start(self._error_messages_text_display, False)
69 #Add all the parameters
70 for param in self.block.get_params():
71 vbox.pack_start(param.get_input_object(self._handle_changed), False)
72 vbox.pack_start(err_box, False)
73 #Done adding parameters
74 if self.block.get_doc():
75 vbox.pack_start(gtk.Label(''), False, False, 7) #spacing
76 vbox.pack_start(get_title_label('Documentation'), False)
77 #Create the text box to display notes about the block
78 vbox.pack_start(TextDisplay(self.block.get_doc()), False)
79 self.connect('key_press_event', self._handle_key_press)
82 for param in self.block.get_params(): param.update()
83 self._update_error_messages()
85 def _update_error_messages(self):
87 Update the error messages in the error messages box.
88 Hide the box if there are no errors.
90 if self.block.is_valid(): self._error_messages_box.hide()
91 else: self._error_messages_box.show()
92 messages = '\n'.join(self.block.get_error_messages())
93 self._error_messages_text_display.set_text(messages)
95 def _handle_key_press(self, widget, event):
97 Handle key presses from the keyboard.
98 Call the ok response when enter is pressed.
99 @return false to forward the keypress
101 keyname = gtk.gdk.keyval_name(event.keyval)
102 if keyname == 'Return': self.response(gtk.RESPONSE_OK)
103 return False #forward the keypress
105 def _handle_changed(self, param):
107 A change occured, update any dependent parameters:
108 The enum inside the variable type may have changed and,
109 the variable param will need an external update.
110 @param param the graphical parameter that initiated the callback
112 self._update_error_messages()
113 #update dependent params
115 for other_param in param.get_parent().get_params():
116 if param.get_key() is not other_param.get_key() and (
117 param.get_key() in other_param._type or \
118 param.get_key() in other_param._hide): other_param.update()
124 @return true if a change occured.
126 original_data = list()
127 for param in self.block.get_params():
128 original_data.append(param.get_value())
132 for param in self.block.get_params():
133 new_data.append(param.get_value())
134 return original_data != new_data