summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2010-08-27 14:19:55 +0200
committerMartin Sivak <msivak@redhat.com>2010-08-30 14:37:55 +0200
commitf5f4a7896222cea3dd942cdc0d79af75dbc74bca (patch)
tree0fca9fae9f0b640eea4e0e5c400fded382d42a07
parent3125442cbf151eaa9b7a843e9750eb6329ddf825 (diff)
downloadfirstaidkit-f5f4a7896222cea3dd942cdc0d79af75dbc74bca.zip
firstaidkit-f5f4a7896222cea3dd942cdc0d79af75dbc74bca.tar.gz
firstaidkit-f5f4a7896222cea3dd942cdc0d79af75dbc74bca.tar.xz
Add checkbox mode to the Config dialog
-rw-r--r--frontend/frontend_gtk.py39
-rw-r--r--plugins/openscap_plugin.py11
-rw-r--r--pyfirstaidkit/reporting.py7
3 files changed, 42 insertions, 15 deletions
diff --git a/frontend/frontend_gtk.py b/frontend/frontend_gtk.py
index 7bdfc31..408f41d 100644
--- a/frontend/frontend_gtk.py
+++ b/frontend/frontend_gtk.py
@@ -317,31 +317,52 @@ class CallbacksFlagList(object):
return True
class ListDialog(object):
- def __init__(self, title, description, items, dir=""):
+ def __init__(self, title, description, items, dir="", mode = 0):
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)
- self._store = gtk.ListStore(gobject.TYPE_STRING,
+
+ 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)
+ 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)
+
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()
- rend_text_edit.set_property("editable", True)
- rend_text_edit.connect('edited', self.edited_cb, self._store)
+
+ 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)
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)
+
+ 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)
col_1.set_resizable(True)
col_1.set_expand(True)
self._view.append_column(col_0)
@@ -369,6 +390,9 @@ class ListDialog(object):
err.run()
err.destroy()
+ def toggled_cb(self, cell, path, store):
+ store[path][2] = not store[path][2]
+
def destroy(self):
self._dialog.destroy()
@@ -797,7 +821,8 @@ class MainWindow(object):
dlg = ListDialog(title = question.title,
description = question.description,
items = question.items,
- dir = os.path.dirname(self._glade.relative_file("."))
+ dir = os.path.dirname(self._glade.relative_file(".")),
+ mode = question.mode
)
res = dlg.run()
diff --git a/plugins/openscap_plugin.py b/plugins/openscap_plugin.py
index dc28792..82efa30 100644
--- a/plugins/openscap_plugin.py
+++ b/plugins/openscap_plugin.py
@@ -64,19 +64,20 @@ class OpenSCAPPlugin(Plugin):
all_rules = self._policy.get_rules()
preprocess_rules = lambda x: (x.item,
self._policy.model.benchmark.get_item(x.item).title[0].text,
- x.selected and 1 or 0,
+ x.selected and True,
self._policy.model.benchmark.get_item(x.item).description[0].text,
- "0|1",
- "Use 0 or 1 to disable or enable rule"
+ "",
+ "Use checkbox disable or enable rule"
)
all_rules = map(preprocess_rules, all_rules)
s = self._reporting.config_question_wait("Setup OpenScap rules",
"Enable or disable rules and press OK",
- all_rules, origin = self,
+ all_rules, mode = 1,
+ origin = self,
level = PLUGIN)
enabled_rules = []
for r in s:
- if r[1] == "1":
+ if r[1]:
enabled_rules.append(r[0])
self._reporting.info("Enabled rules: %s" % repr(enabled_rules), origin = self,
level = PLUGIN)
diff --git a/pyfirstaidkit/reporting.py b/pyfirstaidkit/reporting.py
index ea133a1..67f2269 100644
--- a/pyfirstaidkit/reporting.py
+++ b/pyfirstaidkit/reporting.py
@@ -82,11 +82,12 @@ class ConfigQuestion(Question):
Each item is a tuple (id, title, value,
tooltip, regexp_validator, validator_error_msg)"""
- def __init__(self, title, description, items):
+ def __init__(self, title, description, items, mode = 0):
super(ConfigQuestion, self).__init__(title)
assert len(items) > 0
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)
@@ -345,8 +346,8 @@ class Reports(object):
return self.__blocking_question(self.filename_question, args, kwargs)
def config_question(self, reply_mb, title, description, items, origin, level = PLUGIN,
- importance = logging.ERROR):
- q = ConfigQuestion(title, description, items)
+ importance = logging.ERROR, mode = 0):
+ q = ConfigQuestion(title, description, items, mode = mode)
self.put(q, origin, level, CONFIG_QUESTION, importance = importance,
reply = reply_mb)
return q