From 1e3590a1528f1a351791db4256b99405c8bd9883 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 24 Jan 2013 06:00:51 +0000 Subject: [PATCH] Clean up complete for now --- openlp/core/ui/mainwindow.py | 3 ++- openlp/core/ui/servicemanager.py | 9 ++++---- openlp/core/ui/thememanager.py | 21 +++++++++++++------ .../openlp_core_lib/test_registry.py | 16 ++++++++++---- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 701a35ed6..b5f069854 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -163,7 +163,7 @@ class Ui_MainWindow(object): mainWindow.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.serviceManagerDock) # Create the theme manager self.themeManagerDock = OpenLPDockWidget(mainWindow, u'themeManagerDock', u':/system/system_thememanager.png') - self.themeManagerContents = ThemeManager(mainWindow, self.themeManagerDock) + self.themeManagerContents = ThemeManager(self.themeManagerDock) self.themeManagerContents.setObjectName(u'themeManagerContents') self.themeManagerDock.setWidget(self.themeManagerContents) mainWindow.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.themeManagerDock) @@ -1330,3 +1330,4 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Check if the new data path is our default. if self.newDataPath == AppLocation.get_directory(AppLocation.DataDir): settings.remove(u'advanced/data path') + diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 73c3920a1..1880bf41f 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -48,9 +48,6 @@ from openlp.core.ui.printserviceform import PrintServiceForm from openlp.core.utils import AppLocation, delete_file, split_filename, format_time from openlp.core.utils.actions import ActionList, CategoryOrder -ACTIVE = build_icon(QtGui.QImage(u':/media/auto-start_active.png')) -INACTIVE = build_icon(QtGui.QImage(u':/media/auto-start_inactive.png')) - class ServiceManagerList(QtGui.QTreeWidget): """ Set up key bindings and mouse behaviour for the service list @@ -106,6 +103,8 @@ class ServiceManager(QtGui.QWidget): Sets up the service manager, toolbars, list view, et al. """ QtGui.QWidget.__init__(self, parent) + self.active = build_icon(QtGui.QImage(u':/media/auto-start_active.png')) + self.inactive = build_icon(QtGui.QImage(u':/media/auto-start_inactive.png')) Registry().register(u'service_manager', self) self.serviceItems = [] self.suffixes = [] @@ -796,11 +795,11 @@ class ServiceManager(QtGui.QWidget): self.timeAction.setVisible(True) if serviceItem[u'service_item'].is_capable(ItemCapabilities.CanAutoStartForLive): self.autoStartAction.setVisible(True) - self.autoStartAction.setIcon(INACTIVE) + self.autoStartAction.setIcon(self.inactive) self.autoStartAction.setText(translate('OpenLP.ServiceManager','&Auto Start - inactive')) if serviceItem[u'service_item'].will_auto_start: self.autoStartAction.setText(translate('OpenLP.ServiceManager', '&Auto Start - active')) - self.autoStartAction.setIcon(ACTIVE) + self.autoStartAction.setIcon(self.active) if serviceItem[u'service_item'].is_text(): for plugin in self.plugin_manager.plugins: if plugin.name == u'custom' and plugin.status == PluginStatus.Active: diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 15399474f..2a837631e 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -51,10 +51,9 @@ class ThemeManager(QtGui.QWidget): """ Manages the orders of Theme. """ - def __init__(self, mainwindow, parent=None): + def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) Registry().register(u'theme_manager', self) - self.mainwindow = mainwindow self.settingsSection = u'themes' self.themeForm = ThemeForm(self) self.fileRenameForm = FileRenameForm(self) @@ -681,11 +680,11 @@ class ThemeManager(QtGui.QWidget): """ Called to update the themes' preview images. """ - self.mainwindow.displayProgressBar(len(self.themeList)) + self.main_window.displayProgressBar(len(self.themeList)) for theme in self.themeList: - self.mainwindow.incrementProgressBar() + self.main_window.incrementProgressBar() self.generateAndSaveImage(self.path, theme, self.getThemeData(theme)) - self.mainwindow.finishedProgressBar() + self.main_window.finishedProgressBar() self.loadThemes() def generateImage(self, theme_data, forcePage=False): @@ -834,4 +833,14 @@ class ThemeManager(QtGui.QWidget): self._plugin_manager = Registry().get(u'plugin_manager') return self._plugin_manager - plugin_manager = property(_get_plugin_manager) \ No newline at end of file + plugin_manager = property(_get_plugin_manager) + + def _get_main_window(self): + """ + Adds the main window to the class dynamically + """ + if not hasattr(self, u'_main_window'): + self._main_window = Registry().get(u'main_window') + return self._main_window + + main_window = property(_get_main_window) diff --git a/tests/functional/openlp_core_lib/test_registry.py b/tests/functional/openlp_core_lib/test_registry.py index ee5cf794d..b9729ace1 100644 --- a/tests/functional/openlp_core_lib/test_registry.py +++ b/tests/functional/openlp_core_lib/test_registry.py @@ -18,15 +18,23 @@ class TestServiceItem(TestCase): # GIVEN: A new registry registry = Registry.create() - # WHEN:A service item is created (without a plugin) + # WHEN: I add a service it should save it mock_1 = MagicMock() Registry().register(u'test1', mock_1) # THEN: we should be able retrieve the saved object - assert Registry().get(u'test1') == mock_1, u'The saved object can be retrieved' - #assert service_item.missing_frames() is True, u'There should not be any frames in the service item' + assert Registry().get(u'test1') == mock_1, u'The saved service can be retrieved and matches' - # THEN: We should get back a valid service item + # WHEN: I add a service it should save it a second time + # THEN I will get an exception + try: + Registry().register(u'test1', mock_1) + except Exception, e: + pass + + + # WHEN I try to get back a non existent service + # THEN I will get an exception try: assert Registry().get(u'test2') == mock_1, u'This should not be fired' except Exception, e: