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
24 from Dialogs import TextDisplay
25 from Constants import MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT
27 def get_title_label(title):
29 Get a title label for the params window.
30 The title will be bold, underlined, and left justified.
31 @param title the text of the title
35 label.set_markup('\n<b><span underline="low">%s</span>:</b>\n'%title)
37 hbox.pack_start(label, False, False, padding=11)
40 class ParamsDialog(gtk.Dialog):
41 """A dialog box to set block parameters."""
43 def __init__(self, block):
45 SignalBlockParamsDialog contructor.
46 @param block the signal block
48 gtk.Dialog.__init__(self,
49 title='Properties: %s'%block.get_name(),
50 buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE),
53 self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
56 vbox.pack_start(get_title_label('Parameters'), False)
57 #Create the scrolled window to hold all the parameters
58 scrolled_window = gtk.ScrolledWindow()
59 scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
60 scrolled_window.add_with_viewport(vbox)
61 self.vbox.pack_start(scrolled_window, True)
62 #Error Messages for the block
63 self._error_box = gtk.VBox()
64 self._error_messages_text_display = TextDisplay()
65 self._error_box.pack_start(gtk.Label(), False, False, 7) #spacing
66 self._error_box.pack_start(get_title_label('Error Messages'), False)
67 self._error_box.pack_start(self._error_messages_text_display, False)
69 self._docs_box = err_box = gtk.VBox()
70 self._docs_text_display = TextDisplay()
71 self._docs_box.pack_start(gtk.Label(), False, False, 7) #spacing
72 self._docs_box.pack_start(get_title_label('Documentation'), False)
73 self._docs_box.pack_start(self._docs_text_display, False)
74 #Add all the parameters
75 for param in self.block.get_params():
76 vbox.pack_start(param.get_input_object(self._handle_changed), False)
77 #Add the error and docs box
78 vbox.pack_start(self._error_box, False)
79 vbox.pack_start(self._docs_box, False)
81 self.connect('key_press_event', self._handle_key_press)
84 for param in self.block.get_params(): param.update()
89 Update the error messages box.
90 Hide the box if there are no errors.
91 Update the documentation block.
92 Hide the box if there are no docs.
95 #update the errors box
96 if self.block.is_valid(): self._error_box.hide()
97 else: self._error_box.show()
98 messages = '\n\n'.join(self.block.get_error_messages())
99 self._error_messages_text_display.set_text(messages)
101 if self.block.get_doc(): self._docs_box.show()
102 else: self._docs_box.hide()
103 self._docs_text_display.set_text(self.block.get_doc())
105 def _handle_key_press(self, widget, event):
107 Handle key presses from the keyboard.
108 Call the ok response when enter is pressed.
109 @return false to forward the keypress
111 keyname = gtk.gdk.keyval_name(event.keyval)
112 if keyname == 'Return': self.response(gtk.RESPONSE_OK)
113 return False #forward the keypress
115 def _handle_changed(self, param):
117 A change occured, update any dependent parameters:
118 The enum inside the variable type may have changed and,
119 the variable param will need an external update.
120 @param param the graphical parameter that initiated the callback
122 #update dependent params
124 for other_param in param.get_parent().get_params():
125 if param.get_key() is not other_param.get_key() and (
126 param.get_key() in other_param._type or \
127 param.get_key() in other_param._hide): other_param.update()
135 @return true if a change occured.
137 original_data = list()
138 for param in self.block.get_params():
139 original_data.append(param.get_value())
143 for param in self.block.get_params():
144 new_data.append(param.get_value())
145 return original_data != new_data