diff options
Diffstat (limited to 'portato')
-rw-r--r-- | portato/config_parser.py | 14 | ||||
-rw-r--r-- | portato/gui/gtk/dialogs.py | 3 | ||||
-rw-r--r-- | portato/gui/gtk/windows.py | 65 | ||||
-rw-r--r-- | portato/plugin.py | 8 | ||||
-rw-r--r-- | portato/session.py | 4 |
5 files changed, 73 insertions, 21 deletions
diff --git a/portato/config_parser.py b/portato/config_parser.py index b2b47a6..30d5d28 100644 --- a/portato/config_parser.py +++ b/portato/config_parser.py @@ -43,8 +43,8 @@ COMMENT = [";","#"] # precompiled expressions TRUE = re.compile("((true)|(1)|(on)|(wahr)|(ja)|(yes))", re.I) FALSE = re.compile("((false)|(0)|(off)|(falsch)|(nein)|(no))", re.I) -SECTION = re.compile("\s*\[(\w+)\]\s*") -EXPRESSION = re.compile(r"\s*(\w+)\s*[:=]\s*(.*)\s*") +SECTION = re.compile("\s*\[(?P<name>\w(\w|[-_])*)\]\s*") +EXPRESSION = re.compile(r"\s*(?P<key>\w(\w|[-_])*)\s*[:=]\s*(?P<value>.*)\s*") class Value (object): """Class defining a value of a key. @@ -187,7 +187,7 @@ class ConfigParser: # look for a section match = SECTION.search(line) if match: - sec = match.group(1).upper() + sec = match.group("name").upper() self.sections[sec] = count if sec != section: self.vars[sec] = {} @@ -197,7 +197,7 @@ class ConfigParser: # look for an expression match = EXPRESSION.search(line) if match: - val = match.group(2) + val = match.group("value") # find the boolean value bool = None @@ -207,9 +207,9 @@ class ConfigParser: bool = False # insert - key = match.group(1).lower() + key = match.group("key").lower() self.vars[section][key] = Value(val, count, bool = bool) - self.pos[count] = match.span(2) + self.pos[count] = match.span("value") else: # neither comment nor empty nor expression nor section => error error(_("Unrecognized line in configuration: %s"), line) @@ -252,7 +252,7 @@ class ConfigParser: if val.is_bool(): return val.boolean - raise ValueError, "\"%s\" is not a boolean." % key + raise ValueError, "\"%s\" is not a boolean. (%s)" % (key, val.value) def set (self, key, value = "", section = "MAIN"): """Sets a new value of a given key in a section. diff --git a/portato/gui/gtk/dialogs.py b/portato/gui/gtk/dialogs.py index a176a17..7bea2b8 100644 --- a/portato/gui/gtk/dialogs.py +++ b/portato/gui/gtk/dialogs.py @@ -15,7 +15,8 @@ from gettext import lgettext as _ def queue_not_empty_dialog(): dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_NONE, _("There are some packages in the emerge queue and/or an emerge process is running.\nDo you really want to quit?")) - dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_YES, gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) + #dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_YES, gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) + dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) ret = dialog.run() dialog.destroy() return ret diff --git a/portato/gui/gtk/windows.py b/portato/gui/gtk/windows.py index 485f123..7ec6157 100644 --- a/portato/gui/gtk/windows.py +++ b/portato/gui/gtk/windows.py @@ -23,7 +23,7 @@ from gettext import lgettext as _ # our backend stuff from ... import get_listener, plugin -from ...helper import debug, warning, error, unique_array +from ...helper import debug, warning, error, unique_array, N_ from ...session import Session from ...constants import CONFIG_LOCATION, VERSION, APP_ICON from ...backend import flags, system @@ -56,6 +56,11 @@ class AboutWindow (AbstractDialog): class PluginWindow (AbstractDialog): + statsStore = gtk.ListStore(str) + + for s in (_("Disabled"), _("Temporarily enabled"), _("Enabled"), _("Temporarily disabled")): + statsStore.append([s]) + def __init__ (self, parent, plugins): """Constructor. @@ -67,7 +72,7 @@ class PluginWindow (AbstractDialog): self.changedPlugins = {} view = self.tree.get_widget("pluginList") - self.store = gtk.ListStore(str,str,bool) + self.store = gtk.ListStore(str,str,str) view.set_model(self.store) @@ -78,25 +83,40 @@ class PluginWindow (AbstractDialog): col = gtk.TreeViewColumn(_("Authors"), cell, text = 1) view.append_column(col) - bcell = gtk.CellRendererToggle() - bcell.connect("toggled", self.cb_plugin_toggled) - col = gtk.TreeViewColumn(_("Enabled"), bcell, active = 2) + ccell = gtk.CellRendererCombo() + ccell.set_property("model", self.statsStore) + ccell.set_property("text-column", 0) + ccell.set_property("has-entry", False) + ccell.set_property("editable", True) + ccell.connect("edited", self.cb_status_changed) + col = gtk.TreeViewColumn(_("Status"), ccell, markup = 2) view.append_column(col) - for p in (("<b>"+p.name+"</b>", p.author, p.is_enabled()) for p in plugins): + for p in (("<b>"+p.name+"</b>", p.author, _(self.statsStore[p.status][0])) for p in plugins): self.store.append(p) self.window.show_all() - def cb_plugin_toggled (self, cell, path): + def cb_status_changed (self, cell, path, new_text): path = int(path) - self.store[path][2] = not self.store[path][2] + + self.store[path][2] = "<b>%s</b>" % new_text + + # convert string to constant + const = None + for num, val in enumerate(self.statsStore): + if val[0] == new_text: + const = num + break - self.changedPlugins.update({self.plugins[path] : self.store[path][2]}) + assert (const is not None) + + self.changedPlugins.update({self.plugins[path] : const}) + debug("new changed plugins: %s => %d", self.plugins[path].name, const) def cb_ok_clicked (self, btn): for plugin, val in self.changedPlugins.iteritems(): - plugin.set_option("disabled", not val) + plugin.status = val self.close() return True @@ -1053,6 +1073,31 @@ class MainWindow (Window): ([("merge", "queue"), ("unmerge", "queue"), ("oneshot", "queue")], load_queue, save_queue) ]) + def save_plugin (p): + def _save (): + stat_on = p.status >= p.STAT_ENABLED + hard_on = not p.get_option("disabled") + + if stat_on != hard_on: + return int(stat_on) + else: + return "" + return _save + + def load_plugin (p): + def _load(val): + if val: + p.status = int(val)*2 + + return _load + + queue = plugin.get_plugin_queue().get_plugins() + if queue is None: + queue = [] + + for p in queue: + self.session.add_handler(([(p.name.replace(" ","_"), "plugins")], load_plugin(p), save_plugin(p))) + self.session.load() def jump_to (self, cp, version = None): diff --git a/portato/plugin.py b/portato/plugin.py index 09f2dea..b081ecd 100644 --- a/portato/plugin.py +++ b/portato/plugin.py @@ -155,6 +155,8 @@ class Hook: class Plugin: """A complete plugin.""" + (STAT_DISABLED, STAT_TEMP_ENABLED, STAT_ENABLED, STAT_TEMP_DISABLED) = range(4) + def __init__ (self, file, name, author): """Constructor. @@ -173,6 +175,8 @@ class Plugin: self.menus = [] self.options = Options() + self.status = self.STAT_ENABLED + def parse_hooks (self, hooks): """Gets an <hooks>-elements and parses it. @@ -199,6 +203,8 @@ class Plugin: if options: for o in options: self.options.parse(o.getElementsByTagName("option")) + + self.status = self.STAT_DISABLED if self.options.get("disabled") else self.STAT_ENABLED def set_import (self, imports): """This gets a list of imports and parses them - setting the import needed to call the plugin. @@ -234,7 +240,7 @@ class Plugin: return self.options.set(name, value) def is_enabled (self): - return not self.get_option("disabled") + return (self.status in (self.STAT_ENABLED, self.STAT_TEMP_ENABLED)) class PluginQueue: """Class managing and loading the plugins.""" diff --git a/portato/session.py b/portato/session.py index 2a049d1..0a61181 100644 --- a/portato/session.py +++ b/portato/session.py @@ -77,9 +77,9 @@ class Session (object): for options, lfn, sfn in self._handlers: vals = sfn() - # map into tuple if necessairy + # map into list if necessairy if not hasattr(vals, "__iter__"): - vals = (vals,) + vals = [vals] debug("Saving %s with values %s", options, vals) for value, (option, section) in zip(vals, options): |