summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2009-04-24 19:11:04 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2009-04-24 19:11:04 +0200
commit785e1f2cb2fcd32426931d47fbca72c23ccc06ea (patch)
treefef77b8af7ceda731f35244914db78a58dcfea00
parent4c1d61cb71a396f09969ed264c91ebfff29145c1 (diff)
downloadportato-785e1f2cb2fcd32426931d47fbca72c23ccc06ea.tar.gz
portato-785e1f2cb2fcd32426931d47fbca72c23ccc06ea.tar.bz2
portato-785e1f2cb2fcd32426931d47fbca72c23ccc06ea.zip
Make the new widget structure work. At least for the Plugin Menu
-rw-r--r--plugins/exception.py2
-rw-r--r--portato/gui/templates/MainWindow.ui1
-rw-r--r--portato/gui/windows/main.py7
-rw-r--r--portato/plugin.py26
4 files changed, 29 insertions, 7 deletions
diff --git a/plugins/exception.py b/plugins/exception.py
index 0dc6105..23065e6 100644
--- a/plugins/exception.py
+++ b/plugins/exception.py
@@ -16,5 +16,5 @@ def throw (*args, **kwargs):
p = Plugin()
p.__name__ = "ExceptionThrower"
p.__author__ = "René 'Necoro' Neumann"
-p.add_menu("Throw exception", throw)
+p.create_widget("Plugin Menu", "Throw exception", activate = throw)
register(p)
diff --git a/portato/gui/templates/MainWindow.ui b/portato/gui/templates/MainWindow.ui
index 383011e..473821d 100644
--- a/portato/gui/templates/MainWindow.ui
+++ b/portato/gui/templates/MainWindow.ui
@@ -8,6 +8,7 @@
<object class="GtkAction" id="pluginMenuAction">
<property name="name">pluginMenuAction</property>
<property name="label" translatable="yes">Plu_gins</property>
+ <property name="is_important">True</property>
</object>
</child>
</object>
diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py
index cb463c8..0259fc7 100644
--- a/portato/gui/windows/main.py
+++ b/portato/gui/windows/main.py
@@ -63,14 +63,19 @@ class PluginMenuSlot (plugin.WidgetSlot):
aname = "plugin%d" % self.ctr
a = gtk.Action(aname, label, None, None)
self.ctr += 1
+
+ return a
- def add (self, action):
+ def add (self, widget):
+ action = widget.widget
self.ag.add_action(action)
# add to UI
mid = self.uim.new_merge_id()
self.uim.add_ui(mid, "ui/menubar/pluginMenu", action.get_name(), action.get_name(), gtk.UI_MANAGER_MENUITEM, False)
+ self.uim.ensure_update()
+
class PackageTable:
"""A window with data about a specfic package."""
diff --git a/portato/plugin.py b/portato/plugin.py
index 50cc29f..4914f25 100644
--- a/portato/plugin.py
+++ b/portato/plugin.py
@@ -115,8 +115,16 @@ class WidgetSlot (object):
self.widget = widget
self.name = name
self.max = max
- self.init = init
- self.add = add
+
+ # we might be subclassed
+ # in this case do not overwrite
+
+ if not hasattr(self, "init"):
+ self.init = init
+
+ if not hasattr(self, "add"):
+ self.add = add
+
self._inited = False
debug("Registering new WidgetSlot '%s'.", name)
@@ -128,7 +136,8 @@ class WidgetSlot (object):
self.init()
self._inited = True
- self.add(w)
+ if self.add is not None:
+ self.add(w)
class Widget (object):
"""
@@ -295,6 +304,10 @@ class Plugin (object):
:see: `Widget`
"""
+
+ if not slot in WidgetSlot.slots:
+ raise PluginLoadException, "Could not find specified widget slot: %s" % slot
+
self.__widgets.append(Widget(slot, widget))
def create_widget (self, slot, args, **kwargs):
@@ -318,7 +331,10 @@ class Plugin (object):
except KeyError:
raise PluginLoadException, "Could not find specified widget slot: %s" % slot
- w = widget(*args)
+ if not hasattr(args, "__iter__"):
+ w = widget(args)
+ else:
+ w = widget(*args)
for k,v in kwargs.iteritems():
w.connect(k, v)
@@ -410,7 +426,7 @@ class PluginQueue (object):
for p in self.plugins:
for w in p.widgets:
- WidgetSlot[w.slot].add_widget(w)
+ WidgetSlot.slots[w.slot].add_widget(w)
def add (self, plugin, disable = False):
"""