summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2010-08-30 14:32:55 +0200
committerMartin Sivak <msivak@redhat.com>2010-08-30 14:37:55 +0200
commit4c968e83624b037837636f6a0064874a3dbeb0b3 (patch)
tree62f1c7e5c1f46459eed2901c85e5cf930388b154
parent4e5d2fef9599b38fb12b7c403c85651af4545b49 (diff)
downloadfirstaidkit-4c968e83624b037837636f6a0064874a3dbeb0b3.zip
firstaidkit-4c968e83624b037837636f6a0064874a3dbeb0b3.tar.gz
firstaidkit-4c968e83624b037837636f6a0064874a3dbeb0b3.tar.xz
Standardize option passing in Questions and add Back & Abort buttons to Config question. Also add radio button mode to Config question.
-rw-r--r--frontend/frontend_gtk.py29
-rw-r--r--frontend/gtk-list.xml55
-rw-r--r--pyfirstaidkit/reporting.py48
3 files changed, 96 insertions, 36 deletions
diff --git a/frontend/frontend_gtk.py b/frontend/frontend_gtk.py
index 0eab401..665f830 100644
--- a/frontend/frontend_gtk.py
+++ b/frontend/frontend_gtk.py
@@ -25,6 +25,7 @@ import gobject #we need gobject.idle_add
import copy
import logging
from pyfirstaidkit import reporting
+from pyfirstaidkit.returns import *
import pprint
import os.path
import thread
@@ -317,12 +318,14 @@ class CallbacksFlagList(object):
return True
class ListDialog(object):
- def __init__(self, title, description, items, dir="", mode = 0):
+ def __init__(self, title, description, items, dir="", options = {}):
gtkb = gtk.Builder()
gtkb.add_from_file(os.path.join(dir, "gtk-list.xml"))
self._dialog = gtkb.get_object("listdialog")
self._dialog.set_title(title)
+ mode = options.get("mode", 0)
+
# text
if mode == 0:
self._store = gtk.ListStore(gobject.TYPE_STRING,
@@ -339,7 +342,7 @@ class ListDialog(object):
# checkboxes
- elif mode == 1:
+ elif mode == 1 or mode == 3:
self._store = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_STRING,
gobject.TYPE_BOOLEAN,
@@ -349,6 +352,7 @@ class ListDialog(object):
gobject.TYPE_NONE)
rend_text_check = gtk.CellRendererToggle()
+ rend_text_check.set_radio(mode == 3)
rend_text_check.connect('toggled', self.toggled_cb, self._store)
rend_text_check.set_property('activatable', True)
@@ -397,7 +401,7 @@ class ListDialog(object):
# value column
if mode == 0:
col_1 = gtk.TreeViewColumn('Value', rend_text_edit, text = 2)
- elif mode == 1:
+ elif mode == 1 or mode == 3:
col_1 = gtk.TreeViewColumn('Value', rend_text_check)
col_1.add_attribute(rend_text_check, "active", 2)
elif mode == 2:
@@ -430,7 +434,14 @@ class ListDialog(object):
err.destroy()
def toggled_cb(self, cell, path, store):
- store[path][2] = not store[path][2]
+ new = not store[path][2]
+ if cell.get_radio():
+ i = store.get_iter_first()
+ while i:
+ store[i][2] = False
+ i = store.iter_next(i)
+
+ store[path][2] = new
def changed_cb(self, combo, path, new, store):
store[path][2] = store[path][6][new]
@@ -788,7 +799,7 @@ class MainWindow(object):
vbox = glade.get_widget("choice_question_vbox")
radio_map = {}
group = None
- for (value, name) in question.options:
+ for (value, name) in question.choices:
r = gtk.RadioButton(group, name, False)
radio_map[r] = value
r.show()
@@ -864,7 +875,7 @@ class MainWindow(object):
description = question.description,
items = question.items,
dir = os.path.dirname(self._glade.relative_file(".")),
- mode = question.mode
+ options = question.options
)
res = dlg.run()
@@ -873,6 +884,12 @@ class MainWindow(object):
question.send_answer(message, dlg.items(), origin = self)
elif res==gtk.RESPONSE_CANCEL:
question.send_answer(message, [], origin = self)
+ elif res==gtk.RESPONSE_DELETE_EVENT:
+ question.send_answer(message, [], origin = self)
+ elif res==2:
+ question.send_answer(message, ReturnBack, origin = self)
+ elif res==1:
+ question.send_answer(message, ReturnAbort, origin = self)
else:
raise Exception("Unknown value %s" % (res,))
diff --git a/frontend/gtk-list.xml b/frontend/gtk-list.xml
index 0a71aee..22b5674 100644
--- a/frontend/gtk-list.xml
+++ b/frontend/gtk-list.xml
@@ -65,13 +65,12 @@
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
- <object class="GtkButton" id="ok_button">
- <property name="label" translatable="yes">Save and continue</property>
+ <object class="GtkButton" id="button1">
+ <property name="label">gtk-go-back</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <signal name="clicked" handler="cb_ok"/>
- <signal name="activate" handler="cb_ok"/>
+ <property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
@@ -80,8 +79,33 @@
</packing>
</child>
<child>
+ <object class="GtkButton" id="button2">
+ <property name="label">gtk-stop</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVSeparator" id="vseparator1">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkButton" id="cancel_button">
- <property name="label" translatable="yes">Use defaults and continue</property>
+ <property name="label" translatable="yes">Use defaults</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -91,7 +115,22 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">1</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="ok_button">
+ <property name="label" translatable="yes">OK</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="cb_ok"/>
+ <signal name="activate" handler="cb_ok"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">4</property>
</packing>
</child>
</object>
@@ -104,8 +143,10 @@
</object>
</child>
<action-widgets>
- <action-widget response="0">ok_button</action-widget>
+ <action-widget response="2">button1</action-widget>
+ <action-widget response="1">button2</action-widget>
<action-widget response="0">cancel_button</action-widget>
+ <action-widget response="0">ok_button</action-widget>
</action-widgets>
</object>
</interface>
diff --git a/pyfirstaidkit/reporting.py b/pyfirstaidkit/reporting.py
index 88a7114..ec14b13 100644
--- a/pyfirstaidkit/reporting.py
+++ b/pyfirstaidkit/reporting.py
@@ -66,8 +66,9 @@ class Question(object):
Object identity is used to match questions and replies."""
- def __init__(self, prompt):
+ def __init__(self, prompt, options = {}):
self.prompt = prompt
+ self.options = options
def send_answer(self, question_message, answer, origin = None):
assert question_message["message"] is self
@@ -82,15 +83,15 @@ class ConfigQuestion(Question):
Each item is a tuple (id, title, value,
tooltip, regexp_validator, validator_error_msg)"""
- def __init__(self, title, description, items, mode = 0):
- super(ConfigQuestion, self).__init__(title)
+ def __init__(self, title, description, items, options = {}):
+ super(ConfigQuestion, self).__init__(title, options)
assert len(items) > 0
self.title = title
self.description = description
- self.mode = mode
+ self.mode = options.get("mode", 1)
def _fillrow(x):
- if mode == 2:
+ if self.mode == 2:
model = x[6]
else:
model = None
@@ -105,10 +106,10 @@ class ChoiceQuestion(Question):
Each option is a tuple of (return value, description)."""
- def __init__(self, prompt, options):
- super(ChoiceQuestion, self).__init__(prompt)
- assert len(options) > 0
- self.options = options
+ def __init__(self, prompt, choices, options = {}):
+ super(ChoiceQuestion, self).__init__(prompt, options)
+ assert len(choices) > 0
+ self.choices = choices
class TextQuestion(Question):
"""A question that asks for a string."""
@@ -121,8 +122,8 @@ class FilenameQuestion(TextQuestion):
class PasswordQuestion(Question):
"""A question that asks for a password."""
- def __init__(self, prompt, confirm):
- super(PasswordQuestion, self).__init__(prompt)
+ def __init__(self, prompt, confirm, options = {}):
+ super(PasswordQuestion, self).__init__(prompt, options)
self.confirm = confirm
class Reports(object):
@@ -314,9 +315,9 @@ class Reports(object):
mb.closeMailbox()
return answer
- def choice_question(self, reply_mb, prompt, options, origin, level = PLUGIN,
- importance = logging.ERROR):
- q = ChoiceQuestion(prompt, options)
+ def choice_question(self, reply_mb, prompt, choices, origin, level = PLUGIN,
+ importance = logging.ERROR, options = {}):
+ q = ChoiceQuestion(prompt, choices, options)
self.put(q, origin, level, CHOICE_QUESTION, importance = importance,
reply = reply_mb)
return q
@@ -325,8 +326,8 @@ class Reports(object):
return self.__blocking_question(self.choice_question, args, kwargs)
def text_question(self, reply_mb, prompt, origin, level = PLUGIN,
- importance = logging.ERROR):
- q = TextQuestion(prompt)
+ importance = logging.ERROR, options = {}):
+ q = TextQuestion(prompt, options)
self.put(q, origin, level, TEXT_QUESTION, importance = importance,
reply = reply_mb)
return q
@@ -335,8 +336,8 @@ class Reports(object):
return self.__blocking_question(self.text_question, args, kwargs)
def password_question(self, reply_mb, prompt, origin, level = PLUGIN,
- importance = logging.ERROR, confirm = False):
- q = PasswordQuestion(prompt, confirm)
+ importance = logging.ERROR, confirm = False, options = {}):
+ q = PasswordQuestion(prompt, confirm, options)
self.put(q, origin, level, PASSWORD_QUESTION, importance = importance,
reply = reply_mb)
return q
@@ -345,8 +346,8 @@ class Reports(object):
return self.__blocking_question(self.password_question, args, kwargs)
def filename_question(self, reply_mb, prompt, origin, level = PLUGIN,
- importance = logging.ERROR):
- q = FilenameQuestion(prompt)
+ importance = logging.ERROR, options = {}):
+ q = FilenameQuestion(prompt, options)
self.put(q, origin, level, FILENAME_QUESTION, importance = importance,
reply = reply_mb)
return q
@@ -354,9 +355,10 @@ class Reports(object):
def filename_question_wait(self, *args, **kwargs):
return self.__blocking_question(self.filename_question, args, kwargs)
- def config_question(self, reply_mb, title, description, items, origin, level = PLUGIN,
- importance = logging.ERROR, mode = 0):
- q = ConfigQuestion(title, description, items, mode = mode)
+ def config_question(self, reply_mb, title, description,
+ items, origin, level = PLUGIN,
+ importance = logging.ERROR, options = {}):
+ q = ConfigQuestion(title, description, items, options = options)
self.put(q, origin, level, CONFIG_QUESTION, importance = importance,
reply = reply_mb)
return q