commit d640992c3c499ffdcfee9d5002da8f6930e59f14 Author: Kamran Riaz Khan krkhan@inspirated.com Date: Thu Jul 28 16:35:25 2011 +0500
Use spinbutton for value and combobox for units of data size confs. --- src/gui/configPanel.py | 18 ++++++++++----- src/util/gtkTools.py | 54 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 10 deletions(-)
diff --git a/src/gui/configPanel.py b/src/gui/configPanel.py index 7b1ea42..c5b631a 100644 --- a/src/gui/configPanel.py +++ b/src/gui/configPanel.py @@ -13,13 +13,17 @@ from cli.configPanel import (ConfigPanel as CliConfigPanel, Field, State) from util import connections, gtkTools, sysTools, torTools, uiTools from TorCtl import TorCtl
-def inputConfValueText(option): +def input_conf_value_size(option): prompt = "Enter value for %s" % option - return gtkTools.inputText(prompt) + return gtkTools.input_size(prompt)
-def inputConfValueBoolean(option): +def input_conf_value_text(option): + prompt = "Enter value for %s" % option + return gtkTools.input_text(prompt) + +def input_conf_value_boolean(option): prompt = "Select value for %s" % option - return "1" if gtkTools.inputBoolean(prompt) else "0" + return "1" if gtkTools.input_boolean(prompt) else "0"
class ConfContents(gtkTools.ListWrapper): def _create_row_from_value(self, entry): @@ -80,9 +84,11 @@ class ConfigPanel(object, CliConfigPanel): newValue = None
if configType == 'DataSize': - newValue = inputConfValueText(configOption) + newValue = input_conf_value_size(configOption) elif configType == 'Boolean': - newValue = inputConfValueBoolean(configOption) + newValue = input_conf_value_boolean(configOption) + else: + newValue = input_conf_value_text(configOption)
if newValue: try: diff --git a/src/util/gtkTools.py b/src/util/gtkTools.py index cc2d361..860a587 100644 --- a/src/util/gtkTools.py +++ b/src/util/gtkTools.py @@ -100,10 +100,56 @@ class TreeWrapper(ListWrapper): row = self._create_row_from_value(value) self.model.append(None, row)
-def responseToDialog(entry, dialog, response): +def response_to_dialog(entry, dialog, response): dialog.response(response)
-def inputText(prompt): +def input_size(prompt): + dialog = gtk.MessageDialog(None, + gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, + gtk.MESSAGE_QUESTION, + gtk.BUTTONS_OK_CANCEL, + None) + + dialog.set_markup(prompt) + + hBox = gtk.HBox() + + dialog.vbox.pack_end(hBox, True, True, 0) + + spinButton = gtk.SpinButton(None) + spinButton.connect("activate", response_to_dialog, dialog, gtk.RESPONSE_OK) + + spinButton.set_increments(1, 10) + spinButton.set_range(0, 1024) + + hBox.pack_start(spinButton, True, True, 0) + + comboBox = gtk.combo_box_new_text() + + comboBox.append_text("B") + comboBox.append_text("KB") + comboBox.append_text("MB") + comboBox.append_text("GB") + comboBox.append_text("TB") + comboBox.append_text("PB") + comboBox.set_active(0) + + hBox.pack_end(comboBox, False, False, 0) + + dialog.show_all() + response = dialog.run() + + value = spinButton.get_value_as_int() + + model = comboBox.get_model() + active = comboBox.get_active() + (units,) = model[active] + + dialog.destroy() + + return "%d %s" % (value, units) if response == gtk.RESPONSE_OK else None + +def input_text(prompt): dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, @@ -113,7 +159,7 @@ def inputText(prompt): dialog.set_markup(prompt)
entry = gtk.Entry() - entry.connect("activate", responseToDialog, dialog, gtk.RESPONSE_OK) + entry.connect("activate", response_to_dialog, dialog, gtk.RESPONSE_OK)
dialog.vbox.pack_end(entry, True, True, 0)
@@ -125,7 +171,7 @@ def inputText(prompt):
return text if response == gtk.RESPONSE_OK else None
-def inputBoolean(prompt): +def input_boolean(prompt): dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION,