From 05b78d2a5c4101e552954645df018b21aa32b8fb Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Tue, 24 Aug 2010 16:17:10 +0200 Subject: Improve the user experience - Expert tab is hidden by default - Config dialog checks the format of entered values - Example plugin for dialogs updated --- frontend/firstaidkit.glade | 36 ++++++++++++++++++++++++++++++++---- frontend/frontend_gtk.py | 26 ++++++++++++++++++++++++-- frontend/gtk-list.xml | 6 ++++++ plugins/plugin_examples/dialogue.py | 6 +++--- pyfirstaidkit/plugins.py | 3 ++- pyfirstaidkit/reporting.py | 7 +++++-- 6 files changed, 72 insertions(+), 12 deletions(-) diff --git a/frontend/firstaidkit.glade b/frontend/firstaidkit.glade index 1d16cf6..869eba8 100644 --- a/frontend/firstaidkit.glade +++ b/frontend/firstaidkit.glade @@ -9,6 +9,8 @@ GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False + 640 + 480 True False True @@ -65,11 +67,37 @@ - + + True + Expert mode + True + + + + + True + gtk-properties + 1 + 0.5 + 0.5 + 0 + 0 + + + + + + + + True + + + + + True gtk-quit True - @@ -118,6 +146,7 @@ + 3 True False 0 @@ -297,8 +326,7 @@ - - True + False 0 diff --git a/frontend/frontend_gtk.py b/frontend/frontend_gtk.py index 86b6ed0..cbb113c 100644 --- a/frontend/frontend_gtk.py +++ b/frontend/frontend_gtk.py @@ -129,6 +129,11 @@ class CallbacksMainWindow(object): dir = os.path.dirname(self._glade.relative_file("."))) return True + def on_mainmenu_expert_activate(self, widget, *args): + self._glade.get_widget("expert_page").show() + self._data.pages.set_current_page(1) + return True + #advanced mode callbacks def on_b_StartAdvanced_activate(self, widget, *args): print("on_b_StartAdvanced_activate") @@ -317,10 +322,16 @@ class ListDialog(object): gtkb.add_from_file(os.path.join(dir, "gtk-list.xml")) self._dialog = gtkb.get_object("listdialog") self._dialog.set_title(title) - self._store = gtkb.get_object("store") + self._store = gtk.ListStore(gobject.TYPE_STRING, + gobject.TYPE_STRING, + gobject.TYPE_STRING, + gobject.TYPE_STRING, + gobject.TYPE_PYOBJECT, + gobject.TYPE_STRING) self._label = gtkb.get_object("label") self._label.set_text(description) self._view = gtkb.get_object("view") + self._view.set_model(self._store) rend_text = gtk.CellRendererText() rend_text_edit = gtk.CellRendererText() @@ -328,7 +339,11 @@ class ListDialog(object): rend_text_edit.connect('edited', self.edited_cb, self._store) col_0 = gtk.TreeViewColumn('Key', rend_text, text = 1) + col_0.set_resizable(True) + col_0.set_expand(False) col_1 = gtk.TreeViewColumn('Value', rend_text_edit, text = 2) + col_1.set_resizable(True) + col_1.set_expand(True) self._view.append_column(col_0) self._view.append_column(col_1) @@ -345,7 +360,14 @@ class ListDialog(object): return self._dialog.run() def edited_cb(self, cell, path, new_data, store): - store[path][2] = new_data + res = store[path][4].match(new_data) + if res is not None: + store[path][2] = new_data + else: + err = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK) + err.set_property("text", store[path][5]) + err.run() + err.destroy() def destroy(self): self._dialog.destroy() diff --git a/frontend/gtk-list.xml b/frontend/gtk-list.xml index bde40e6..427652f 100644 --- a/frontend/gtk-list.xml +++ b/frontend/gtk-list.xml @@ -12,10 +12,16 @@ + + + + 5 + 640 + 480 normal False diff --git a/plugins/plugin_examples/dialogue.py b/plugins/plugin_examples/dialogue.py index bcc5a00..d5c1857 100644 --- a/plugins/plugin_examples/dialogue.py +++ b/plugins/plugin_examples/dialogue.py @@ -78,9 +78,9 @@ class DialoguePlugin(Plugin): level = PLUGIN) config_options = [ - ("id:1", "PL", "5", "Password length"), - ("id:2", "PS", "C", "Password strength"), - ("id:3", "PL", "aA0.", "Password chars"), + ("id:1", "PL", "5", "Password length", "[1-9][0-9]*", "The length must be a valid number bigger than 0."), + ("id:2", "PS", "C", "Password strength", "[A-F]", "Use strength indicator A, B, C, D, E or F"), + ("id:3", "PL", "aA0.", "Password chars", ".*", "Any allowed characters.."), ] s = self._reporting.config_question_wait("Setup choices", diff --git a/pyfirstaidkit/plugins.py b/pyfirstaidkit/plugins.py index 303cfc9..c0f1361 100644 --- a/pyfirstaidkit/plugins.py +++ b/pyfirstaidkit/plugins.py @@ -280,7 +280,8 @@ class Plugin(object): message = func+" raised "+str(e)) self._reporting.stop(level = TASK, origin = self, message = func) - pass + if self._interpret._config.system.debug: + raise return (self._state, self._result) diff --git a/pyfirstaidkit/reporting.py b/pyfirstaidkit/reporting.py index 9151db9..21a4b45 100644 --- a/pyfirstaidkit/reporting.py +++ b/pyfirstaidkit/reporting.py @@ -19,6 +19,7 @@ import Queue import logging import thread import weakref +import re from errors import * @@ -77,14 +78,16 @@ class Question(object): class ConfigQuestion(Question): """A question that allows list of configurable variables - Each item is a tuple (id, title, value, tooltip)""" + Each item is a tuple (id, title, value, + tooltip, regexp_validator, validator_error_msg)""" def __init__(self, title, description, items): super(ConfigQuestion, self).__init__(title) assert len(items) > 0 self.title = title self.description = description - self.items = items + self.items = map(lambda x: (x[0], x[1], x[2], x[3], + re.compile("^"+x[4]+"$"), x[5]), items) class ChoiceQuestion(Question): """A question that offers multiple options. -- cgit