summaryrefslogtreecommitdiff
path: root/portato/plugin.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2009-04-24 18:11:53 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2009-04-24 18:11:53 +0200
commit9a9e90bf28509147eedb5a2ebe5fc110c6244a34 (patch)
treef488c2394b770b1121b72905c935ed072cdd89b2 /portato/plugin.py
parent62725d63688631950d21a6a03a1cecfccf78f4e3 (diff)
downloadportato-9a9e90bf28509147eedb5a2ebe5fc110c6244a34.tar.gz
portato-9a9e90bf28509147eedb5a2ebe5fc110c6244a34.tar.bz2
portato-9a9e90bf28509147eedb5a2ebe5fc110c6244a34.zip
Should add widgets now
Diffstat (limited to 'portato/plugin.py')
-rw-r--r--portato/plugin.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/portato/plugin.py b/portato/plugin.py
index 45305b0..9efe396 100644
--- a/portato/plugin.py
+++ b/portato/plugin.py
@@ -98,21 +98,37 @@ class WidgetSlot (object):
name : string
The slot's name.
+ init : function
+ Function to call, iff there is at least one widget for that slot.
+
+ add : function(`Widget`)
+ Function to call, if a widget is added.
+
max : int
The maximum number of widgets which can be registered. -1 means unlimited.
"""
slots = {}
- __slots__ = ("widget", "name", "max")
-
- def __init__ (self, widget, name, max = -1):
+
+ def __init__ (self, widget, name, add = None, init = None, max = -1):
self.widget = widget
self.name = name
self.max = max
+ self.init = init
+ self.add = add
+ self._inited = False
WidgetSlot.slots[name] = self
+ def add_widget (self, w):
+ if not self._inited:
+ if self.init is not None:
+ self.init()
+ self._inited = True
+
+ self.add(w)
+
class Widget (object):
"""
Fills a WidgetSlot.
@@ -127,6 +143,8 @@ class Widget (object):
"""
+ __slots__ = ("slot", "widget")
+
def __init__ (self, slot, widget):
self.slot = slot
self.widget = widget
@@ -230,7 +248,7 @@ class Plugin (object):
return getattr(self, "__name__", self.__class__.__name__)
@property
- def widget (self):
+ def widgets (self):
"""
Returns an iterator over the widgets for this plugin.
@@ -389,6 +407,10 @@ class PluginQueue (object):
self._organize()
+ for p in self.plugins:
+ for w in p.widgets:
+ WidgetSlot[w.slot].add_widget(w)
+
def add (self, plugin, disable = False):
"""
Adds a plugin to the internal list.
@@ -536,7 +558,6 @@ class PluginQueue (object):
for hook, calls in star_after.iteritems():
self.hooks[hook].after.extend(calls) # append the list
-
def _resolve_unresolved (self, before, after):
def resolve(hook, list, type, add):
if not list: