From ab69d8ac22a4548a55d3fbb4f5d8e7aff77df293 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Fri, 24 Apr 2009 18:13:05 +0200 Subject: Load plugins later in the startup process. No menu magic anymore --- portato/gui/windows/main.py | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) (limited to 'portato/gui/windows/main.py') diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py index a0127e0..6a65d2e 100644 --- a/portato/gui/windows/main.py +++ b/portato/gui/windows/main.py @@ -472,31 +472,6 @@ class MainWindow (Window): # package db splash(_("Creating Database")) self.db = Database(self.cfg.get("type", section = "DATABASE")) - - # set plugins and plugin-menu - splash(_("Loading Plugins")) - - plugin.load_plugins() - menus = [p.menus for p in plugin.get_plugin_queue().get_plugins()] - if menus: - uim = self.tree.get_widget("uimanager") - ag = self.tree.get_widget("pluginActionGroup") - - ctr = 0 - for m in itt.chain(*menus): - - # create action - aname = "plugin%d" % ctr - a = gtk.Action(aname, m.label, None, None) - a.connect("activate", m.call) - ag.add_action(a) - - # add to UI - mid = uim.new_merge_id() - uim.add_ui(mid, "ui/menubar/pluginMenu", aname, aname, gtk.UI_MANAGER_MENUITEM, False) - - ctr += 1 - splash(_("Building frontend")) # set paned position @@ -581,6 +556,11 @@ class MainWindow (Window): self.queueTree = GtkTree(self.queueList.get_model()) self.queue = EmergeQueue(console = self.console, tree = self.queueTree, db = self.db, title_update = self.title_update, threadClass = GtkThread) + # set plugins and plugin-menu + splash(_("Loading Plugins")) + + plugin.load_plugins() + # session splash(_("Restoring Session")) try: -- cgit v1.2.3-54-g00ecf From 4c1d61cb71a396f09969ed264c91ebfff29145c1 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Fri, 24 Apr 2009 18:34:21 +0200 Subject: Create PluginMenuSlot --- portato/gui/windows/main.py | 22 ++++++++++++++++++++++ portato/plugin.py | 1 + 2 files changed, 23 insertions(+) (limited to 'portato/gui/windows/main.py') diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py index 6a65d2e..cb463c8 100644 --- a/portato/gui/windows/main.py +++ b/portato/gui/windows/main.py @@ -50,6 +50,27 @@ from .preference import PreferenceWindow from .search import SearchWindow from .update import UpdateWindow +class PluginMenuSlot (plugin.WidgetSlot): + + def __init__ (self, tree): + plugin.WidgetSlot.__init__(self, self.create_action, "Plugin Menu") + + self.ctr = 0 # counter for the plugin actions + self.uim = tree.get_widget("uimanager") + self.ag = tree.get_widget("pluginActionGroup") + + def create_action (self, label): + aname = "plugin%d" % self.ctr + a = gtk.Action(aname, label, None, None) + self.ctr += 1 + + def add (self, action): + 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) + class PackageTable: """A window with data about a specfic package.""" @@ -559,6 +580,7 @@ class MainWindow (Window): # set plugins and plugin-menu splash(_("Loading Plugins")) + PluginMenuSlot(self.tree) plugin.load_plugins() # session diff --git a/portato/plugin.py b/portato/plugin.py index 9efe396..50cc29f 100644 --- a/portato/plugin.py +++ b/portato/plugin.py @@ -119,6 +119,7 @@ class WidgetSlot (object): self.add = add self._inited = False + debug("Registering new WidgetSlot '%s'.", name) WidgetSlot.slots[name] = self def add_widget (self, w): -- cgit v1.2.3-54-g00ecf From 785e1f2cb2fcd32426931d47fbca72c23ccc06ea Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Fri, 24 Apr 2009 19:11:04 +0200 Subject: Make the new widget structure work. At least for the Plugin Menu --- plugins/exception.py | 2 +- portato/gui/templates/MainWindow.ui | 1 + portato/gui/windows/main.py | 7 ++++++- portato/plugin.py | 26 +++++++++++++++++++++----- 4 files changed, 29 insertions(+), 7 deletions(-) (limited to 'portato/gui/windows/main.py') 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 @@ pluginMenuAction Plu_gins + True 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): """ -- cgit v1.2.3-54-g00ecf From 1091a8192ba7a5ccdc6a3c31d87864939fe4adb6 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Sat, 25 Apr 2009 11:15:52 +0200 Subject: Add emerge options slot --- portato/gui/templates/MainWindow.ui | 2 +- portato/gui/windows/main.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'portato/gui/windows/main.py') diff --git a/portato/gui/templates/MainWindow.ui b/portato/gui/templates/MainWindow.ui index 383011e..b0a9f18 100644 --- a/portato/gui/templates/MainWindow.ui +++ b/portato/gui/templates/MainWindow.ui @@ -963,7 +963,7 @@ - + True True diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py index 0259fc7..290fe6a 100644 --- a/portato/gui/windows/main.py +++ b/portato/gui/windows/main.py @@ -585,6 +585,9 @@ class MainWindow (Window): # set plugins and plugin-menu splash(_("Loading Plugins")) + optionsHB = self.tree.get_widget("optionsHB") + plugin.WidgetSlot(gtk.CheckButton, "Emerge Options", add = lambda w: optionsHB.pack_end(w.widget)) + PluginMenuSlot(self.tree) plugin.load_plugins() -- cgit v1.2.3-54-g00ecf From a6a43af88f97e8cd4684e220dc97d3037d92a068 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Fri, 15 May 2009 17:36:04 +0200 Subject: Introduced extra slots module. --- portato/gui/slots.py | 42 ++++++++++++++++++++++++++++++++++++++++++ portato/gui/windows/main.py | 36 +++++++----------------------------- 2 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 portato/gui/slots.py (limited to 'portato/gui/windows/main.py') diff --git a/portato/gui/slots.py b/portato/gui/slots.py new file mode 100644 index 0000000..2ad4c01 --- /dev/null +++ b/portato/gui/slots.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# +# File: portato/gui/slots.py +# This file is part of the Portato-Project, a graphical portage-frontend. +# +# Copyright (C) 2006-2009 René 'Necoro' Neumann +# This is free software. You may redistribute copies of it under the terms of +# the GNU General Public License version 2. +# There is NO WARRANTY, to the extent permitted by law. +# +# Written by René 'Necoro' Neumann + +from __future__ import absolute_import, with_statement + +import gtk +from ...plugin import WidgetSlot # other modules might import WidgetSlot from here + +class PluginMenuSlot (WidgetSlot): + + def __init__ (self, tree): + WidgetSlot.__init__(self, self.create_action, "Plugin Menu") + + self.ctr = 0 # counter for the plugin actions + self.uim = tree.get_widget("uimanager") + self.ag = tree.get_widget("pluginActionGroup") + + def create_action (self, label): + aname = "plugin%d" % self.ctr + a = gtk.Action(aname, label, None, None) + self.ctr += 1 + + return a + + 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() diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py index 290fe6a..1758033 100644 --- a/portato/gui/windows/main.py +++ b/portato/gui/windows/main.py @@ -23,13 +23,17 @@ from collections import defaultdict # our backend stuff from ...backend import flags, system # must be the first to avoid circular deps -from ... import get_listener, plugin +from ... import get_listener from ...helper import debug, warning, error, info from ...session import Session from ...db import Database from ...constants import CONFIG_LOCATION, VERSION, APP_ICON from ...backend.exceptions import PackageNotFoundException, BlockedException, VersionsNotFoundException +# plugin stuff +from ... import plugin +from .. import slots + # more GUI stuff from ..utils import Config, GtkThread, get_color from ..queue import EmergeQueue @@ -50,32 +54,6 @@ from .preference import PreferenceWindow from .search import SearchWindow from .update import UpdateWindow -class PluginMenuSlot (plugin.WidgetSlot): - - def __init__ (self, tree): - plugin.WidgetSlot.__init__(self, self.create_action, "Plugin Menu") - - self.ctr = 0 # counter for the plugin actions - self.uim = tree.get_widget("uimanager") - self.ag = tree.get_widget("pluginActionGroup") - - def create_action (self, label): - aname = "plugin%d" % self.ctr - a = gtk.Action(aname, label, None, None) - self.ctr += 1 - - return a - - 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.""" @@ -586,9 +564,9 @@ class MainWindow (Window): splash(_("Loading Plugins")) optionsHB = self.tree.get_widget("optionsHB") - plugin.WidgetSlot(gtk.CheckButton, "Emerge Options", add = lambda w: optionsHB.pack_end(w.widget)) + slots.WidgetSlot(gtk.CheckButton, "Emerge Options", add = lambda w: optionsHB.pack_end(w.widget)) - PluginMenuSlot(self.tree) + slots.PluginMenuSlot(self.tree) plugin.load_plugins() # session -- cgit v1.2.3-54-g00ecf