diff options
-rw-r--r-- | portato/gui/windows/main.py | 20 | ||||
-rw-r--r-- | portato/plugin.py | 60 |
2 files changed, 53 insertions, 27 deletions
diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py index c7f419a..88f7692 100644 --- a/portato/gui/windows/main.py +++ b/portato/gui/windows/main.py @@ -470,6 +470,15 @@ 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")) + + optionsHB = self.tree.get_widget("optionsHB") + slots.WidgetSlot(gtk.CheckButton, "Emerge Options", add = lambda w: optionsHB.pack_end(w.widget)) + + slots.PluginMenuSlot(self.tree) + plugin.load_plugins() splash(_("Building frontend")) # set paned position @@ -555,14 +564,6 @@ 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")) - - optionsHB = self.tree.get_widget("optionsHB") - slots.WidgetSlot(gtk.CheckButton, "Emerge Options", add = lambda w: optionsHB.pack_end(w.widget)) - - slots.PluginMenuSlot(self.tree) - plugin.load_plugins() # session splash(_("Restoring Session")) @@ -574,6 +575,9 @@ class MainWindow (Window): except SessionException, e: warning(str(e)) self.load_session(defaults_only = True) # last ressort + + splash(_("Loading Plugin Widgets")) + plugin.load_plugin_widgets() splash(_("Finishing startup")) diff --git a/portato/plugin.py b/portato/plugin.py index c823ac7..e627eb1 100644 --- a/portato/plugin.py +++ b/portato/plugin.py @@ -189,7 +189,6 @@ class Plugin (object): :param disable: Forcefully disable the plugin :type disable: bool """ - self.__widgets = [] #: List of `Widget` self.__calls = [] #: List of `Call` self._unresolved_deps = False #: Does this plugin has unresolved dependencies? @@ -258,15 +257,6 @@ class Plugin (object): return getattr(self, "__name__", self.__class__.__name__) @property - def widgets (self): - """ - Returns an iterator over the widgets for this plugin. - - :rtype: iter<`Widget`> - """ - return iter(self.__widgets) - - @property def calls (self): """ Returns an iterator over the registered calls for this plugin. @@ -298,6 +288,27 @@ class Plugin (object): """ return (self.status in (self.STAT_ENABLED, self.STAT_TEMP_ENABLED)) + def add_call (self, hook, callable, type = "before", dep = None): + """ + Adds a new call for this plugin. + + :see: `Call` + """ + self.__calls.append(Call(self, hook, callable, type, dep)) + +class WidgetPlugin (Plugin): + + def __init__ (self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) + self.__widgets = [] #: List of `Widget` + + def _widget_init (self): + if self.status == self.STAT_ENABLED and not self._unresolved_deps: + self.widget_init() + + def widget_init (self): + debug("No widgets to initialize. Wrong class used for plugin?") + def add_widget (self, slot, widget): """ Adds a new widget for this plugin. @@ -340,15 +351,15 @@ class Plugin (object): w.connect(k, v) self.add_widget(slot, w) - - def add_call (self, hook, callable, type = "before", dep = None): + + @property + def widgets (self): """ - Adds a new call for this plugin. + Returns an iterator over the widgets for this plugin. - :see: `Call` + :rtype: iter<`Widget`> """ - self.__calls.append(Call(self, hook, callable, type, dep)) - + return iter(self.__widgets) class PluginQueue (object): """ @@ -411,6 +422,7 @@ class PluginQueue (object): plugin_module.__path__.insert(0, PLUGIN_DIR.rstrip("/")) # make the plugins loadable as "portato.plugins.name" # add Plugin and register to the builtins, so the plugins always have the correct version :) plugin_module.__builtins__["Plugin"] = Plugin + plugin_module.__builtins__["WidgetPlugin"] = WidgetPlugin plugin_module.__builtins__["register"] = register for p in plugins: # import them @@ -424,9 +436,12 @@ class PluginQueue (object): self._organize() + def load_widgets(self): for p in self.plugins: - for w in p.widgets: - WidgetSlot.slots[w.slot].add_widget(w) + if isinstance(p, WidgetPlugin): + p._widget_init() + for w in p.widgets: + WidgetSlot.slots[w.slot].add_widget(w) def add (self, plugin, disable = False): """ @@ -443,7 +458,7 @@ class PluginQueue (object): :raise PluginLoadException: passed plugin is not of class `Plugin` """ - if callable(plugin) and Plugin in plugin.__bases__: + if callable(plugin) and issubclass(plugin, Plugin): p = plugin(disable = disable) # need an instance and not the class elif isinstance(plugin, Plugin): p = plugin @@ -617,6 +632,13 @@ def load_plugins(): __plugins.load() +def load_plugin_widgets(): + """ + Loads the widgets of the plugins. + """ + if __plugins is not None: + __plugins.load_widgets() + def get_plugin_queue(): """ Returns the actual `PluginQueue`. If it is ``None``, they are not being loaded yet. |