00001 """
00002 Copyright 2007 Free Software Foundation, Inc.
00003 This file is part of GNU Radio
00004
00005 GNU Radio Companion is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009
00010 GNU Radio Companion is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00018 """
00019
00020
00021
00022
00023 import pygtk
00024 pygtk.require('2.0')
00025 import gtk
00026
00027 from Dialogs import TextDisplay
00028 from grc.Constants import MIN_DIALOG_WIDTH,MIN_DIALOG_HEIGHT
00029
00030 def get_title_label(title):
00031 """!
00032 Get a title label for the params window.
00033 The title will be bold, underlined, and left justified.
00034 @param title the text of the title
00035 @return a gtk object
00036 """
00037 label = gtk.Label()
00038 label.set_markup('\n<b><span underline="low">%s</span>:</b>\n'%title)
00039 hbox = gtk.HBox()
00040 hbox.pack_start(label, False, False, padding=11)
00041 return hbox
00042
00043 class ParamsDialog(gtk.Dialog):
00044 """A dialog box to set block parameters."""
00045
00046 def __init__(self, block):
00047 """!
00048 SignalBlockParamsDialog contructor.
00049 @param block the signal block
00050 """
00051 gtk.Dialog.__init__(self, buttons=('gtk-close', gtk.RESPONSE_CLOSE))
00052 self.block = block
00053 self.set_title('Properties: %s'%block.get_name())
00054 self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
00055 vbox = gtk.VBox()
00056
00057 vbox.pack_start(get_title_label('Parameters'), False)
00058
00059 scrolled_window = gtk.ScrolledWindow()
00060 scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
00061 scrolled_window.add_with_viewport(vbox)
00062 self.vbox.pack_start(scrolled_window, True)
00063
00064 self._error_messages_box = err_box = gtk.VBox()
00065 self._error_messages_text_display = TextDisplay('')
00066 err_box.pack_start(gtk.Label(''), False, False, 7)
00067 err_box.pack_start(get_title_label('Error Messages'), False)
00068 err_box.pack_start(self._error_messages_text_display, False)
00069
00070 for param in self.block.get_params():
00071 vbox.pack_start(param.get_input_object(self._handle_changed), False)
00072 vbox.pack_start(err_box, False)
00073
00074 if self.block.get_doc():
00075 vbox.pack_start(gtk.Label(''), False, False, 7)
00076 vbox.pack_start(get_title_label('Documentation'), False)
00077
00078 vbox.pack_start(TextDisplay(self.block.get_doc()), False)
00079 self.connect('key_press_event', self._handle_key_press)
00080 self.show_all()
00081
00082 for param in self.block.get_params(): param.update()
00083 self._update_error_messages()
00084
00085 def _update_error_messages(self):
00086 """
00087 Update the error messages in the error messages box.
00088 Hide the box if there are no errors.
00089 """
00090 if self.block.is_valid(): self._error_messages_box.hide()
00091 else: self._error_messages_box.show()
00092 messages = '\n'.join(self.block.get_error_messages())
00093 self._error_messages_text_display.set_text(messages)
00094
00095 def _handle_key_press(self, widget, event):
00096 """!
00097 Handle key presses from the keyboard.
00098 Call the ok response when enter is pressed.
00099 @return false to forward the keypress
00100 """
00101 keyname = gtk.gdk.keyval_name(event.keyval)
00102 if keyname == 'Return': self.response(gtk.RESPONSE_OK)
00103 return False
00104
00105 def _handle_changed(self, param):
00106 """!
00107 A change occured, update any dependent parameters:
00108 The enum inside the variable type may have changed and,
00109 the variable param will need an external update.
00110 @param param the graphical parameter that initiated the callback
00111 """
00112 self._update_error_messages()
00113
00114 if param.is_enum():
00115 for other_param in param.get_parent().get_params():
00116 if param.get_key() is not other_param.get_key() and (
00117 param.get_key() in other_param._type or \
00118 param.get_key() in other_param._hide): other_param.update()
00119 return True
00120
00121 def run(self):
00122 """!
00123 Call run().
00124 @return true if a change occured.
00125 """
00126 original_data = list()
00127 for param in self.block.get_params():
00128 original_data.append(param.get_value())
00129 gtk.Dialog.run(self)
00130 self.destroy()
00131 new_data = list()
00132 for param in self.block.get_params():
00133 new_data.append(param.get_value())
00134 return original_data != new_data
00135