summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2010-08-27 15:15:15 +0200
committerMartin Sivak <msivak@redhat.com>2010-08-30 14:37:55 +0200
commit4ac2ac721a139325a35f48a631e2ff8b994eb2f6 (patch)
treeb6db8f7d849abaadaad27b3d3eabf9191754383b
parentf5f4a7896222cea3dd942cdc0d79af75dbc74bca (diff)
downloadfirstaidkit-4ac2ac721a139325a35f48a631e2ff8b994eb2f6.zip
firstaidkit-4ac2ac721a139325a35f48a631e2ff8b994eb2f6.tar.gz
firstaidkit-4ac2ac721a139325a35f48a631e2ff8b994eb2f6.tar.xz
Add Combo mode to ConfigDialog
-rw-r--r--frontend/frontend_gtk.py74
-rw-r--r--plugins/openscap_plugin.py15
-rw-r--r--pyfirstaidkit/reporting.py13
3 files changed, 80 insertions, 22 deletions
diff --git a/frontend/frontend_gtk.py b/frontend/frontend_gtk.py
index 408f41d..0eab401 100644
--- a/frontend/frontend_gtk.py
+++ b/frontend/frontend_gtk.py
@@ -323,20 +323,64 @@ class ListDialog(object):
self._dialog = gtkb.get_object("listdialog")
self._dialog.set_title(title)
+ # text
if mode == 0:
self._store = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_STRING,
gobject.TYPE_STRING,
gobject.TYPE_STRING,
gobject.TYPE_PYOBJECT,
- gobject.TYPE_STRING)
+ gobject.TYPE_STRING,
+ gobject.TYPE_NONE)
+
+ rend_text_edit = gtk.CellRendererText()
+ rend_text_edit.set_property("editable", True)
+ rend_text_edit.connect('edited', self.edited_cb, self._store)
+
+
+ # checkboxes
elif mode == 1:
self._store = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_STRING,
gobject.TYPE_BOOLEAN,
gobject.TYPE_STRING,
gobject.TYPE_PYOBJECT,
- gobject.TYPE_STRING)
+ gobject.TYPE_STRING,
+ gobject.TYPE_NONE)
+
+ rend_text_check = gtk.CellRendererToggle()
+ rend_text_check.connect('toggled', self.toggled_cb, self._store)
+ rend_text_check.set_property('activatable', True)
+
+ # combo
+ elif mode == 2:
+ self._store = gtk.ListStore(gobject.TYPE_STRING,
+ gobject.TYPE_STRING,
+ gobject.TYPE_STRING,
+ gobject.TYPE_STRING,
+ gobject.TYPE_PYOBJECT,
+ gobject.TYPE_STRING,
+ gtk.ListStore)
+ def _fill(x):
+ model = gtk.ListStore(gobject.TYPE_STRING)
+ for v in x[6]:
+ model.append((v,))
+ return x[:6]+(model,)
+
+ # convert x[6] to list store for combo box
+ items = map(_fill, items)
+
+ rend_text_combo = gtk.CellRendererCombo()
+ rend_text_combo.set_property("editable", True)
+ rend_text_combo.set_property("text-column", 0)
+ rend_text_combo.connect('edited', self.edited_cb, self._store)
+ rend_text_combo.connect('changed', self.changed_cb, self._store)
+ rend_text_combo.set_property('has-entry', True)
+
+
+ # fill the data store
+ map(self._store.append, items)
+
self._label = gtkb.get_object("label")
self._label.set_text(description)
@@ -345,31 +389,26 @@ class ListDialog(object):
rend_text = gtk.CellRendererText()
- if mode == 0:
- rend_text_edit = gtk.CellRendererText()
- rend_text_edit.set_property("editable", True)
- rend_text_edit.connect('edited', self.edited_cb, self._store)
- elif mode == 1:
- rend_text_check = gtk.CellRendererToggle()
- rend_text_check.connect('toggled', self.toggled_cb, self._store)
- rend_text_check.set_property('activatable', True)
-
+ # title column
col_0 = gtk.TreeViewColumn('Key', rend_text, text = 1)
col_0.set_resizable(True)
col_0.set_expand(False)
+ # value column
if mode == 0:
col_1 = gtk.TreeViewColumn('Value', rend_text_edit, text = 2)
elif mode == 1:
col_1 = gtk.TreeViewColumn('Value', rend_text_check)
col_1.add_attribute(rend_text_check, "active", 2)
+ elif mode == 2:
+ col_1 = gtk.TreeViewColumn('Value', rend_text_combo, text = 2)
+ col_1.add_attribute(rend_text_combo, "model", 6)
+
col_1.set_resizable(True)
col_1.set_expand(True)
self._view.append_column(col_0)
self._view.append_column(col_1)
- map(self._store.append, items)
-
gtkb.connect_signals(self)
def items(self):
@@ -393,6 +432,9 @@ class ListDialog(object):
def toggled_cb(self, cell, path, store):
store[path][2] = not store[path][2]
+ def changed_cb(self, combo, path, new, store):
+ store[path][2] = store[path][6][new]
+
def destroy(self):
self._dialog.destroy()
@@ -832,7 +874,11 @@ class MainWindow(object):
elif res==gtk.RESPONSE_CANCEL:
question.send_answer(message, [], origin = self)
else:
- raise Exception("Unknown value %s")
+ raise Exception("Unknown value %s" % (res,))
+
+ except Exception, e:
+ print e
+ raise
finally:
# schedule dialog destroy
diff --git a/plugins/openscap_plugin.py b/plugins/openscap_plugin.py
index 82efa30..34f9ea5 100644
--- a/plugins/openscap_plugin.py
+++ b/plugins/openscap_plugin.py
@@ -86,16 +86,19 @@ class OpenSCAPPlugin(Plugin):
tailor_items = self._policy.get_tailor_items()
preproces_tailor_items = lambda i: (i["id"],
- i["titles"][i["lang"]] or "",
- i["selected"][1] or "",
- i["descs"][i["lang"]] or "",
- i["match"] or ".*",
- "Error setting the value, read the following description and try again:\n\n"+i["descs"][i["lang"]])
+ i["titles"][i["lang"]] or "",
+ i["selected"][1] or "",
+ i["descs"][i["lang"]] or "",
+ i["match"] or ".*",
+ "Error setting the value, read the following description and try again:\n\n"+i["descs"][i["lang"]],
+ [i["selected"][1] or "", "test"]
+ )
tailor_items = map(preproces_tailor_items, tailor_items)
s = self._reporting.config_question_wait("Setup OpenScap policy",
"Set preferred values and press OK",
- tailor_items, origin = self,
+ tailor_items, mode = 2,
+ origin = self,
level = PLUGIN)
preprocess_s = lambda v: {"id": v[0], "value": v[1]}
diff --git a/pyfirstaidkit/reporting.py b/pyfirstaidkit/reporting.py
index 67f2269..88a7114 100644
--- a/pyfirstaidkit/reporting.py
+++ b/pyfirstaidkit/reporting.py
@@ -88,8 +88,17 @@ class ConfigQuestion(Question):
self.title = title
self.description = description
self.mode = mode
- self.items = map(lambda x: (x[0], x[1], x[2], x[3],
- re.compile("^("+x[4]+")$"), x[5]), items)
+
+ def _fillrow(x):
+ if mode == 2:
+ model = x[6]
+ else:
+ model = None
+
+ return (x[0], x[1], x[2], x[3],
+ re.compile("^("+x[4]+")$"), x[5], model)
+
+ self.items = map(_fillrow, items)
class ChoiceQuestion(Question):
"""A question that offers multiple options.