commit e98ab90082947021af9ca4ae7416b35b5e6f1bee Author: Kamran Riaz Khan krkhan@inspirated.com Date: Wed Jul 27 05:54:16 2011 +0500
Implement config value edits for string values.
Catches TorCtl exceptions and shows them in an error dialog. --- src/gui/configPanel.py | 29 +++++++++++++++++++++++++++-- src/util/gtkTools.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/src/gui/configPanel.py b/src/gui/configPanel.py index 433d612..a1d1daa 100644 --- a/src/gui/configPanel.py +++ b/src/gui/configPanel.py @@ -13,6 +13,10 @@ from cli.configPanel import (ConfigPanel as CliConfigPanel, Field, State) from util import connections, gtkTools, sysTools, torTools, uiTools from TorCtl import TorCtl
+def inputConfValueText(option): + prompt = "Enter value for %s" % option + return gtkTools.inputText(prompt) + class ConfContents(gtkTools.ListWrapper): def _create_row_from_value(self, entry): option = entry.get(Field.OPTION) @@ -50,10 +54,12 @@ class ConfigPanel(object, CliConfigPanel):
def pack_widgets(self): treeView = self.builder.get_object('treeview_config') + treeView.connect('cursor-changed', self.on_treeview_config_cursor_changed) + treeView.connect('row-activated', self.on_treeview_config_row_activated)
- def on_treeview_config_cursor_changed(self, widget, data=None): - treeSelection = widget.get_selection() + def on_treeview_config_cursor_changed(self, treeView, data=None): + treeSelection = treeView.get_selection()
(model, iter) = treeSelection.get_selected() desc = model.get_value(iter, 4) @@ -61,3 +67,22 @@ class ConfigPanel(object, CliConfigPanel): textBuffer = self.builder.get_object('textbuffer_config_desc') textBuffer.set_text(desc)
+ def on_treeview_config_row_activated(self, treeView, path, column): + (index,) = path + + entry = self._wrappedConfImportantContents[index] + configOption = entry.fields[Field.OPTION] + configType = entry.fields[Field.TYPE] + newValue = None + + if configType == 'DataSize': + newValue = inputConfValueText(configOption) + + if newValue: + try: + torTools.getConn().setOption(configOption, newValue) + except TorCtl.ErrorReply, err: + gtkTools.showError(str(err)) + + self._wrappedConfImportantContents[index] = entry + diff --git a/src/util/gtkTools.py b/src/util/gtkTools.py index c1b14dd..5180e82 100644 --- a/src/util/gtkTools.py +++ b/src/util/gtkTools.py @@ -100,3 +100,38 @@ class TreeWrapper(ListWrapper): row = self._create_row_from_value(value) self.model.append(None, row)
+def responseToDialog(entry, dialog, response): + dialog.response(response) + +def inputText(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) + + entry = gtk.Entry() + entry.connect("activate", responseToDialog, dialog, gtk.RESPONSE_OK) + + dialog.vbox.pack_end(entry, True, True, 0) + + dialog.show_all() + response = dialog.run() + + text = entry.get_text() + dialog.destroy() + + return text if response == gtk.RESPONSE_OK else None + +def showError(msg): + dialog = gtk.MessageDialog(None, + gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, + gtk.MESSAGE_ERROR, + gtk.BUTTONS_OK, + msg) + + dialog.run() + dialog.destroy() +