Ejemplo n.º 1
0
    def __load_plugins(self):

        wx.BeginBusyCursor()

        # get plugin list
        plugins2load_by_name = gmPlugin.GetPluginLoadList(
            option='horstspace.notebook.plugin_load_order',
            plugin_dir='gui',
            defaults=['gmProviderInboxPlugin'])

        _log.debug('plugin load order: %s', plugins2load_by_name)

        nr_plugins = len(plugins2load_by_name)
        failed_plugins = []

        #  set up a progress bar
        progress_bar = gmPlugin.cLoadProgressBar(nr_plugins)

        #  and load them
        prev_plugin = ""
        first_plugin = None
        plugin = None
        result = -1
        for idx in range(nr_plugins):
            curr_plugin = plugins2load_by_name[idx]
            progress_bar.Update(result, curr_plugin)
            try:
                plugin = gmPlugin.instantiate_plugin('gui', curr_plugin)
                if plugin:
                    plugin.register()
                    result = 1
                else:
                    _log.error("plugin [%s] not loaded, see errors above",
                               curr_plugin)
                    failed_plugins.append(curr_plugin)
                    result = 1
            except:
                _log.exception('failed to load plugin %s', curr_plugin)
                failed_plugins.append(curr_plugin)
                result = 0

            if first_plugin is None:
                first_plugin = plugin
            prev_plugin = curr_plugin

        _log.debug('failed plugins: %s', failed_plugins)
        progress_bar.DestroyLater()
        wx.EndBusyCursor()

        # force-refresh first notebook page
        page = self.nb.GetPage(0)
        page.Refresh()

        return True
Ejemplo n.º 2
0
    def _on_right_click(self, evt):
        evt.Skip()
        return

        load_menu = wx.Menu()
        any_loadable = 0
        plugin_list = gmPlugin.GetPluginLoadList('gui')
        plugin = None
        for plugin_name in plugin_list:
            try:
                plugin = gmPlugin.instantiate_plugin('gui', plugin_name)
            except Exception:
                continue
            # not a plugin
            if not isinstance(plugin, gmPlugin.cNotebookPlugin):
                plugin = None
                continue
            # already loaded ?
            if plugin.__class__.__name__ in self.guibroker[
                    'horstspace.notebook.gui'].keys():
                plugin = None
                continue
            # add to load menu
            nid = wx.NewId()
            load_menu.AppendItem(wx.MenuItem(load_menu, nid, plugin.name()))
            wx.EVT_MENU(load_menu, nid, plugin.on_load)
            any_loadable = 1
        # make menus
        menu = wx.Menu()
        ID_LOAD = wx.NewId()
        ID_DROP = wx.NewId()
        if any_loadable:
            menu.AppendMenu(ID_LOAD, _('add plugin ...'), load_menu)
        plugins = self.guibroker['horstspace.notebook.gui']
        raised_plugin = plugins[self.nb.GetSelection()].name()
        menu.AppendItem(wx.MenuItem(menu, ID_DROP,
                                    "drop [%s]" % raised_plugin))
        wx.EVT_MENU(menu, ID_DROP, self._on_drop_plugin)
        self.PopupMenu(menu, evt.GetPosition())
        menu.Destroy()
        evt.Skip()