From 26fdf4359a97e1a96a890b46c6c000dab9d0bfa9 Mon Sep 17 00:00:00 2001
From: necoro <>
Date: Wed, 4 Jul 2007 22:46:41 +0000
Subject: first approach of allowing the disabling of plugins (only gtk)
---
portato/gui/gtk/windows.py | 28 ++-
portato/gui/templates/portato.glade | 395 ++++++++++++++++++------------------
portato/plugin.py | 35 +++-
3 files changed, 247 insertions(+), 211 deletions(-)
(limited to 'portato')
diff --git a/portato/gui/gtk/windows.py b/portato/gui/gtk/windows.py
index 6303179..580447b 100644
--- a/portato/gui/gtk/windows.py
+++ b/portato/gui/gtk/windows.py
@@ -123,10 +123,12 @@ Copyright (C) 2006-2007 René 'Necoro' Neumann <necoro@necoro.net>
Icon created by P4R4D0X
""")
+ self.plugins = plugins
+
view = self.tree.get_widget("pluginList")
- store = gtk.ListStore(str,str)
+ self.store = gtk.ListStore(str,str,bool)
- view.set_model(store)
+ view.set_model(self.store)
cell = gtk.CellRendererText()
col = gtk.TreeViewColumn("Plugin", cell, markup = 0)
@@ -135,11 +137,22 @@ Icon created by P4R4D0X
col = gtk.TreeViewColumn("Authors", cell, text = 1)
view.append_column(col)
- for p in [(""+n+"",a) for n,a in plugins]:
- store.append(p)
+ bcell = gtk.CellRendererToggle()
+ bcell.connect("toggled", self.cb_plugin_toggled)
+ col = gtk.TreeViewColumn("Enabled", bcell, active = 2)
+ view.append_column(col)
+
+ for p in [(""+p.name+"", p.author, p.is_enabled()) for p in plugins]:
+ self.store.append(p)
self.window.show_all()
+ def cb_plugin_toggled (self, cell, path):
+ path = int(path)
+ self.store[path][2] = not self.store[path][2]
+
+ self.plugins[path].set_enabled(self.store[path][2])
+
class UpdateWindow (AbstractDialog):
def __init__ (self, parent, packages, queue, jump_to):
@@ -854,7 +867,7 @@ class MainWindow (Window):
# set plugins and plugin-menu
plugin.load_plugins("gtk")
- menus = plugin.get_plugins().get_plugin_menus()
+ menus = plugin.get_plugin_queue().get_plugin_menus()
if menus:
self.tree.get_widget("pluginMenuItem").set_no_show_all(False)
pluginMenu = self.tree.get_widget("pluginMenu")
@@ -1202,11 +1215,10 @@ class MainWindow (Window):
return True
def cb_about_clicked (self, button):
- queue = plugin.get_plugins()
+ queue = plugin.get_plugin_queue().get_plugins()
if queue is None:
queue = []
- else:
- queue = queue.get_plugin_data()
+
AboutWindow(self.window, queue)
return True
diff --git a/portato/gui/templates/portato.glade b/portato/gui/templates/portato.glade
index c25298a..26519a3 100644
--- a/portato/gui/templates/portato.glade
+++ b/portato/gui/templates/portato.glade
@@ -417,73 +417,51 @@
4
2
-
+
True
- False
- GTK_POLICY_AUTOMATIC
- GTK_POLICY_AUTOMATIC
+ 1
+ True
-
+
True
+ True
+ Installed
+ 0
+ True
+
+
+ False
+
-
-
- 2
- 2
- 3
- 5
- 5
-
-
-
-
- True
-
+
+ True
+ True
+ Masked
+ 0
+ True
+
+
+
+ False
+ 1
+
+
+
+
+ True
+ True
+ Testing
+ 0
+ True
+
+
+
+ False
+ 2
+
-
-
- 1
- 2
- GTK_FILL
- 5
-
-
-
-
- True
- GTK_JUSTIFY_CENTER
- True
-
-
- 2
- GTK_FILL
-
- 10
-
-
-
-
- True
- True
- <span foreground='red'><b>MISSING KEYWORD</b></span>
- True
-
-
- 1
- 2
- 1
- 2
- GTK_FILL
-
-
-
-
- True
- True
- <b>Installed, but not in portage anymore</b>
- True
1
@@ -552,58 +530,80 @@
-
+
+ True
+ True
+ <b>Installed, but not in portage anymore</b>
+ True
+
+
+ 1
+ 2
+ 1
+ 2
+ GTK_FILL
+
+
+
+
+ True
+ True
+ <span foreground='red'><b>MISSING KEYWORD</b></span>
+ True
+
+
+ 1
+ 2
+ 1
+ 2
+ GTK_FILL
+
+
+
+
+ True
+ GTK_JUSTIFY_CENTER
+ True
+
+
+ 2
+ GTK_FILL
+
+ 10
+
+
+
+
True
- 1
- True
-
-
- True
- True
- Installed
- 0
- True
-
-
-
- False
-
-
-
- True
- True
- Masked
- 0
- True
-
-
-
- False
- 1
-
+
+
+
+ 1
+ 2
+ GTK_FILL
+ 5
+
+
+
+
+ True
+ False
+ GTK_POLICY_AUTOMATIC
+ GTK_POLICY_AUTOMATIC
-
+
True
- True
- Testing
- 0
- True
-
-
- False
- 2
-
- 1
2
- 1
- 2
- GTK_FILL
+ 2
+ 3
+ 5
+ 5
@@ -784,7 +784,6 @@
About
- False
True
GTK_WIN_POS_CENTER_ON_PARENT
1
@@ -851,7 +850,7 @@
True
False
- GTK_POLICY_AUTOMATIC
+ GTK_POLICY_NEVER
GTK_POLICY_AUTOMATIC
@@ -1093,189 +1092,189 @@
-
+
True
+ 0
+ 5
+ <u><i>Masking Keywords</i></u>
+ True
+ True
- 1
- 2
- 3
- 4
+ 7
+ 8
+ 5
-
+
True
0
- File name to use, if package.use is a directory:
+ 5
+ <u><i>Testing Keywords</i></u>
+ True
True
- 3
- 4
+ 4
+ 5
+ 5
-
+
True
- Add only exact version to package.use
- 0
- True
+ 0
+ 5
+ <u><i>Use-Flags</i></u>
+ True
+ True
+
+
+ 1
+ 2
+ 6
+
+
+
+
+ True
+
+
+ True
+ 0
+ GTK_SHADOW_OUT
+
+
+ True
+ 0
+ <u>You may use the following placeholders:</u>
+
+<i>$(cat)</i>: category
+<i>$(pkg)</i>: package name
+<i>$(cat-1)/$(cat-2)</i>: first/second part of the category
+ True
+
+
+
+
+
+ label_item
+
+
+
+
2
- 2
- 3
-
+
True
- Add only exact version to package.keywords
+ Add only exact version to package.mask/package.unmask
0
True
2
- 5
- 6
+ 8
+ 9
-
+
True
0
- File name to use, if package.keywords is a directory:
+ File name to use, if package.mask/package.unmask is a directory:
True
- 6
- 7
+ 9
+ 10
-
+
True
1
2
- 6
- 7
+ 9
+ 10
-
+
True
1
2
- 9
- 10
+ 6
+ 7
-
+
True
0
- File name to use, if package.mask/package.unmask is a directory:
+ File name to use, if package.keywords is a directory:
True
- 9
- 10
+ 6
+ 7
-
+
True
- Add only exact version to package.mask/package.unmask
+ Add only exact version to package.keywords
0
True
2
- 8
- 9
+ 5
+ 6
-
+
True
-
-
- True
- 0
- GTK_SHADOW_OUT
-
-
- True
- 0
- <u>You may use the following placeholders:</u>
-
-<i>$(cat)</i>: category
-<i>$(pkg)</i>: package name
-<i>$(cat-1)/$(cat-2)</i>: first/second part of the category
- True
-
-
-
-
-
- label_item
-
-
-
-
+ Add only exact version to package.use
+ 0
+ True
2
+ 2
+ 3
-
- True
- 0
- 5
- <u><i>Use-Flags</i></u>
- True
- True
-
-
- 1
- 2
- 6
-
-
-
-
+
True
0
- 5
- <u><i>Testing Keywords</i></u>
- True
+ File name to use, if package.use is a directory:
True
- 4
- 5
- 5
+ 3
+ 4
-
+
True
- 0
- 5
- <u><i>Masking Keywords</i></u>
- True
- True
- 7
- 8
- 5
+ 1
+ 2
+ 3
+ 4
diff --git a/portato/plugin.py b/portato/plugin.py
index e6ceb89..da1e883 100644
--- a/portato/plugin.py
+++ b/portato/plugin.py
@@ -170,6 +170,7 @@ class Plugin:
self._import = None
self.hooks = []
self.menus = []
+ self.enabled = True
def parse_hooks (self, hooks):
"""Gets a list of -elements and parses them.
@@ -236,6 +237,16 @@ class Plugin:
@rtype: string"""
return self._import
+ def set_disabled (self, nodes):
+ if nodes:
+ self.set_enabled(False)
+
+ def is_enabled (self):
+ return self.enabled
+
+ def set_enabled (self, e):
+ self.enabled = e
+
class PluginQueue:
"""Class managing and loading the plugins."""
@@ -253,11 +264,14 @@ class PluginQueue:
if load:
self._load()
- def get_plugin_data (self):
- return [(x.name, x.author) for x in self.list]
+ def get_plugins (self, list_disabled = True):
+ return [x for x in self.list if (x.is_enabled() or list_disabled)]
+
+ def get_plugin_data (self, list_disabled = False):
+ return [(x.name, x.author) for x in self.list if (x.is_enabled() or list_disabled)]
- def get_plugin_menus (self):
- return flatten([x.menus for x in self.list])
+ def get_plugin_menus (self, list_disabled = False):
+ return flatten([x.menus for x in self.list if (x.is_enabled() or list_disabled)])
def hook (self, hook, *hargs, **hkwargs):
"""This is a method taking care of calling the plugins.
@@ -303,11 +317,21 @@ class PluginQueue:
def hook_decorator (func):
"""This is the real decorator."""
+
if hook in self.hooks:
list = self.hooks[hook]
else:
list = ([],[],[])
+ # remove disabled
+ _list = ([],[],[])
+ for i in range(len(list)):
+ for cmd in list[i]:
+ if cmd.hook.plugin.is_enabled():
+ _list[i].append(cmd)
+
+ list = _list
+
def wrapper (*args, **kwargs):
ret = None
@@ -372,6 +396,7 @@ class PluginQueue:
plugin.parse_hooks(elem.getElementsByTagName("hook"))
plugin.set_import(elem.getElementsByTagName("import"))
plugin.parse_menus(elem.getElementsByTagName("menu"))
+ plugin.set_disabled(elem.getElementsByTagName("disabled"))
self.list.append(plugin)
@@ -465,7 +490,7 @@ def load_plugins(frontend):
if __plugins is None or __plugins.frontend != frontend:
__plugins = PluginQueue(frontend)
-def get_plugins():
+def get_plugin_queue():
return __plugins
def hook(hook, *args, **kwargs):
--
cgit v1.2.3