From cfc82e740703a0f0215f35c0963907ac454a17e1 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 7 Oct 2009 06:09:35 +0100 Subject: [PATCH] Cleanup hinding code and move to disable for now --- openlp/core/lib/plugin.py | 22 ++++----------- openlp/core/lib/pluginmanager.py | 14 +++++----- openlp/core/ui/__init__.py | 3 ++- openlp/core/ui/mainwindow.py | 11 +++++--- openlp/core/ui/settingsform.py | 37 ++++++++++++++++++-------- openlp/plugins/images/lib/imagetab.py | 2 +- openlp/plugins/remotes/remoteplugin.py | 3 +++ 7 files changed, 51 insertions(+), 41 deletions(-) diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index c2d0e92f9..dba0f5ace 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -119,9 +119,6 @@ class Plugin(object): self.icon = None self.config = PluginConfig(self.name) self.weight = 0 - self.media_id = -1 - self.settings_id = -1 - self.media_active = False self.status = PluginStatus.Inactive # Set up logging self.log = logging.getLogger(self.name) @@ -130,7 +127,7 @@ class Plugin(object): self.render_manager = plugin_helpers[u'render'] self.service_manager = plugin_helpers[u'service'] self.settings = plugin_helpers[u'settings'] - self.mediatoolbox = plugin_helpers[u'toolbox'] + self.mediadock = plugin_helpers[u'toolbox'] QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_add_service_item'% self.name), self.process_add_service_event) @@ -253,21 +250,12 @@ class Plugin(object): """ Called by the plugin to remove toolbar """ - if self.media_id is not -1: - self.mediatoolbox.removeItem(self.media_id) - if self.settings_id is not -1: - self.settings.removeTab(self.settings_id) - self.media_active = False + self.mediadock.removeDock(self.name) + self.settings.removeTab(self.name) def insert_toolbox_item(self): """ Called by plugin to replace toolbar """ - if not self.media_active: - if self.media_id is not -1: - self.mediatoolbox.insertItem( - self.media_id, self.media_item, self.icon, self.media_item.title) - if self.settings_id is not -1: - self.settings.insertTab( - self.settings_id, self.settings_tab) - self.media_active = True + self.mediadock.insertDock(self.name) + self.settings.insertTab(self.name) diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 905d34a09..c99bbc934 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -125,7 +125,7 @@ class PluginManager(object): """ return cmp(x.weight, y.weight) - def hook_media_manager(self, mediatoolbox): + def hook_media_manager(self, mediadock): """ Loop through all the plugins. If a plugin has a valid media manager item, add it to the media manager. @@ -139,9 +139,8 @@ class PluginManager(object): if plugin.media_item is not None: log.debug(u'Inserting media manager item from %s' % \ plugin.name) - plugin.media_id = mediatoolbox.addItem( - plugin.media_item, plugin.icon, plugin.media_item.title) - plugin.media_active = True + mediadock.addDock(plugin.name, + plugin.media_item, plugin.icon) def hook_settings_tabs(self, settingsform=None): """ @@ -157,7 +156,7 @@ class PluginManager(object): plugin.settings_tab = plugin.get_settings_tab() if plugin.settings_tab is not None: log.debug(u'Inserting settings tab item from %s' % plugin.name) - plugin.settings_id = settingsform.addTab(plugin.settings_tab) + settingsform.addTab(plugin.name, plugin.settings_tab) else: log.debug(u'No tab settings in %s' % plugin.name) @@ -202,11 +201,12 @@ class PluginManager(object): Loop through all the plugins and give them an opportunity to initialise themselves. """ - log.info(u'initialising plugins') for plugin in self.plugins: + log.info(u'initialising plugins %s in a %s state' + % (plugin.name, plugin.is_active())) if plugin.is_active(): plugin.initialise() - if plugin.media_item is not None and not plugin.is_active(): + if not plugin.is_active(): plugin.remove_toolbox_item() def finalise_plugins(self): diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index 7ffb77463..909fc5f3f 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -34,10 +34,11 @@ from about import AboutForm from alertform import AlertForm from plugindialoglistform import PluginForm from settingsform import SettingsForm +from mediadockmanager import MediaDockManager from servicemanager import ServiceManager from thememanager import ThemeManager from mainwindow import MainWindow __all__ = ['SplashScreen', 'AboutForm', 'SettingsForm', 'MainWindow', 'MainDisplay', 'SlideController', 'ServiceManager', 'ThemeManager', - 'AmendThemeForm'] + 'AmendThemeForm', 'MediaDockManager'] diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index d06a78a53..af30313cf 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -29,9 +29,10 @@ from PyQt4 import QtCore, QtGui from openlp.core.ui import AboutForm, SettingsForm, AlertForm, \ ServiceManager, ThemeManager, MainDisplay, SlideController, \ - PluginForm + PluginForm, MediaDockManager from openlp.core.lib import translate, RenderManager, PluginConfig, \ - OpenLPDockWidget, SettingsManager, PluginManager, Receiver, buildIcon + OpenLPDockWidget, SettingsManager, PluginManager, Receiver, \ + buildIcon class Ui_MainWindow(object): @@ -489,6 +490,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): #ThemeManager needs to call RenderManager self.RenderManager = RenderManager(self.ThemeManagerContents, self.screenList, self.getMonitorNumber()) + #Define the media Dock Manager + self.mediaDockManager = MediaDockManager(self.MediaToolBox) log.info(u'Load Plugins') #make the controllers available to the plugins self.plugin_helpers[u'preview'] = self.PreviewController @@ -496,7 +499,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.plugin_helpers[u'render'] = self.RenderManager self.plugin_helpers[u'service'] = self.ServiceManagerContents self.plugin_helpers[u'settings'] = self.settingsForm - self.plugin_helpers[u'toolbox'] = self.MediaToolBox + self.plugin_helpers[u'toolbox'] = self.mediaDockManager self.plugin_manager.find_plugins(pluginpath, self.plugin_helpers) # hook methods have to happen after find_plugins. Find plugins needs # the controllers hence the hooks have moved from setupUI() to here @@ -505,7 +508,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.plugin_manager.hook_settings_tabs(self.settingsForm) # Find and insert media manager items log.info(u'hook media') - self.plugin_manager.hook_media_manager(self.MediaToolBox) + self.plugin_manager.hook_media_manager(self.mediaDockManager) # Call the hook method to pull in import menus. log.info(u'hook menus') self.plugin_manager.hook_import_menu(self.FileImportMenu) diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 2daaaaab7..02b87736c 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -35,29 +35,44 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): def __init__(self, screen_list, mainWindow, parent=None): QtGui.QDialog.__init__(self, None) + self.tabs = {} self.setupUi(self) # General tab self.GeneralTab = GeneralTab(screen_list) - self.addTab(self.GeneralTab) + self.addTab(u'General', self.GeneralTab) # Themes tab self.ThemesTab = ThemesTab(mainWindow) - self.addTab(self.ThemesTab) + self.addTab(u'Themes', self.ThemesTab) # Alert tab self.AlertsTab = AlertsTab() - self.addTab(self.AlertsTab) + self.addTab(u'Alerts', self.AlertsTab) - def addTab(self, tab): + def addTab(self, name, tab): log.info(u'Adding %s tab' % tab.title()) - return self.SettingsTabWidget.addTab(tab, tab.title()) + id = self.SettingsTabWidget.addTab(tab, tab.title()) + self.tabs[name] = ({u'data': tab, u'id': id, u'active':True}) - def insertTab(self, id, tab): - log.debug(u'Inserting %s tab' % tab.title()) - self.SettingsTabWidget.insertTab(id, tab, tab.title()) + def insertTab(self, name): + log.debug(u'Inserting %s tab' % name) + for tab_index in range(0, self.SettingsTabWidget.count()): + #print self.SettingsTabWidget.widget(tab_index).title() + if self.SettingsTabWidget.widget(tab_index).title() == name: + #print "Insert match" + #print self.SettingsTabWidget.widget(tab_index).isVisible() + self.SettingsTabWidget.widget(tab_index).setEnabled(True) + #print self.SettingsTabWidget.widget(tab_index).isVisible() - def removeTab(self, id): - log.debug(u'remove %s no tab' % unicode(id)) - self.SettingsTabWidget.removeTab(id) + def removeTab(self, name): + log.debug(u'remove %s tab' % name) + #print ">>>>>>>>>>> remove settings" + for tab_index in range(0, self.SettingsTabWidget.count()): + #print self.SettingsTabWidget.widget(tab_index).title(), name + if self.SettingsTabWidget.widget(tab_index).title() == name: + #print "remove match" + #print self.SettingsTabWidget.widget(tab_index).isVisible() + self.SettingsTabWidget.widget(tab_index).setEnabled(False) + #print self.SettingsTabWidget.widget(tab_index).isVisible() def accept(self): for tab_index in range(0, self.SettingsTabWidget.count()): diff --git a/openlp/plugins/images/lib/imagetab.py b/openlp/plugins/images/lib/imagetab.py index ccf6d7571..5c00d826d 100644 --- a/openlp/plugins/images/lib/imagetab.py +++ b/openlp/plugins/images/lib/imagetab.py @@ -31,7 +31,7 @@ class ImageTab(SettingsTab): ImageTab is the Image settings tab in the settings dialog. """ def __init__(self): - SettingsTab.__init__(self, translate(u'ImageTab', u'Image'), u'Image') + SettingsTab.__init__(self, translate(u'ImageTab', u'Images'), u'Image') def setupUi(self): self.setObjectName(u'ImageTab') diff --git a/openlp/plugins/remotes/remoteplugin.py b/openlp/plugins/remotes/remoteplugin.py index 6c56036a0..8b1e3f1b9 100644 --- a/openlp/plugins/remotes/remoteplugin.py +++ b/openlp/plugins/remotes/remoteplugin.py @@ -41,6 +41,8 @@ class RemotesPlugin(Plugin): def initialise(self): log.debug(u'initialise') + Plugin.initialise(self) + self.insert_toolbox_item() self.server = QtNetwork.QUdpSocket() self.server.bind(int(self.config.get_config(u'remote port', 4316))) QtCore.QObject.connect(self.server, @@ -48,6 +50,7 @@ class RemotesPlugin(Plugin): def finalise(self): log.debug(u'finalise') + self.remove_toolbox_item() if self.server is not None: self.server.close()