Add test idea for the registry

This commit is contained in:
Tim Bentley 2013-02-03 21:46:56 +00:00
parent a9a4c7938e
commit ca5e46a2b1
9 changed files with 56 additions and 24 deletions

View File

@ -154,12 +154,6 @@ class OpenLP(QtGui.QApplication):
self.main_window.app_startup()
return self.exec_()
def close_splash_screen(self):
"""
Close the splash screen when requested.
"""
self.splash.close()
def is_already_running(self):
"""
Look to see if OpenLP is already running and ask if a 2nd copy

View File

@ -44,9 +44,6 @@ class EventReceiver(QtCore.QObject):
**Mainwindow related and generic signals**
``mainwindow_status_text``
Changes the bottom status bar text on the mainwindow.
``openlp_error_message``
Displays a standalone Error Message.

View File

@ -59,6 +59,7 @@ class Registry(object):
log.info(u'Registry Initialising')
registry = cls()
registry.service_list = {}
registry.functions_list = {}
registry.running_under_test = False
# Allow the tests to remove Registry entries but not the live system
if u'nosetest' in sys.argv[0]:
@ -96,3 +97,33 @@ class Registry(object):
return
if key in self.service_list:
del self.service_list[key]
def register_function(self, occasion, function):
"""
Register a function and a handler to be called later
"""
if self.functions_list.has_key(occasion) == 0:
self.functions_list[occasion] = [function]
else:
self.functions_list[occasion].append(function)
def remove_function(self, occasion, function):
"""
Register a function and a handler to be called later
"""
if self.running_under_test is False:
log.error(u'Invalid Method call for key %s' % occasion)
raise KeyError(u'Invalid Method call for key %s' % occasion)
return
if self.functions_list.has_key(occasion):
self.functions_list[occasion].remove(function)
def execute(self, occasion, data):
"""
Execute all the handlers registered passing the data to the handler
"""
print self.functions_list, self.functions_list.has_key(occasion)
if self.functions_list.has_key(occasion):
for function in self.functions_list[occasion]:
function(data)

View File

@ -532,8 +532,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'openlp_version_check'), self.versionNotice)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'live_display_blank_check'), self.blankCheck)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_screen_changed'), self.screenChanged)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'mainwindow_status_text'),
self.showStatusMessage)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'cleanup'), self.clean_up)
# Media Manager
QtCore.QObject.connect(self.mediaToolBox, QtCore.SIGNAL(u'currentChanged(int)'), self.onMediaToolBoxChanged)
@ -722,21 +720,21 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
"""
Display an error message
"""
self.application.close_splash_screen()
self.application.splash.close()
QtGui.QMessageBox.critical(self, data[u'title'], data[u'message'])
def warning_message(self, message):
"""
Display a warning message
"""
self.application.close_splash_screen()
self.application.splash.close()
QtGui.QMessageBox.warning(self, message[u'title'], message[u'message'])
def onInformationMessage(self, data):
"""
Display an informational message
"""
self.application.close_splash_screen()
self.application.splash.close()
QtGui.QMessageBox.information(self, data[u'title'], data[u'message'])
def onHelpWebSiteClicked(self):
@ -1122,7 +1120,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
title = u'%s - %s' % (self.mainTitle, fileName)
self.setWindowTitle(title)
def showStatusMessage(self, message):
def show_status_message(self, message):
"""
Show a message in the status bar
"""

View File

@ -238,6 +238,7 @@ class ThemeManager(QtGui.QWidget):
self.theme_list_widget.item(count).setText(name)
Settings().setValue(self.settingsSection + u'/global theme', self.global_theme)
Receiver.send_message(u'theme_update_global', self.global_theme)
Registry().execute(u'theme_update_global', self.global_theme)
self._push_themes()
def onAddTheme(self):
@ -465,6 +466,7 @@ class ThemeManager(QtGui.QWidget):
Notify listeners that the theme list has been updated
"""
Receiver.send_message(u'theme_update_list', self.get_themes())
Registry().execute(u'theme_update_list', self.get_themes())
def get_themes(self):
"""

View File

@ -35,7 +35,7 @@ import logging
from PyQt4 import QtCore
from openlp.core.lib import Receiver, translate
from openlp.core.lib import Registry, Receiver, translate
log = logging.getLogger(__name__)
@ -72,10 +72,10 @@ class AlertsManager(QtCore.QObject):
if text:
self.alertList.append(text)
if self.timer_id != 0:
Receiver.send_message(u'mainwindow_status_text',
self.main_window.show_status_message(
translate('AlertsPlugin.AlertsManager', 'Alert message created and displayed.'))
return
Receiver.send_message(u'mainwindow_status_text', u'')
self.main_window.show_status_message(u'')
self.generateAlert()
def generateAlert(self):
@ -107,3 +107,13 @@ class AlertsManager(QtCore.QObject):
self.killTimer(self.timer_id)
self.timer_id = 0
self.generateAlert()
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)

View File

@ -31,9 +31,8 @@ import logging
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver, translate
from openlp.core.lib.ui import critical_error_message_box, \
find_and_set_in_combo_box
from openlp.core.lib import Receiver, Registry, translate
from openlp.core.lib.ui import critical_error_message_box, find_and_set_in_combo_box
from openlp.plugins.custom.lib import CustomXMLBuilder, CustomXMLParser
from openlp.plugins.custom.lib.db import CustomSlide
from editcustomdialog import Ui_CustomEditDialog
@ -66,6 +65,7 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog):
self.slideListView.currentRowChanged.connect(self.on_current_row_changed)
self.slideListView.doubleClicked.connect(self.on_edit_button_clicked)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'theme_update_list'), self.loadThemes)
Registry().register_function(u'theme_update_list', self.loadThemes)
def loadThemes(self, theme_list):
"""

View File

@ -37,8 +37,7 @@ from PyQt4 import QtCore
from openlp.core.lib import Plugin, StringContent, build_icon, translate
from openlp.core.utils import AppLocation
from openlp.plugins.presentations.lib import PresentationController, \
PresentationMediaItem, PresentationTab
from openlp.plugins.presentations.lib import PresentationController, PresentationMediaItem, PresentationTab
log = logging.getLogger(__name__)

View File

@ -39,7 +39,7 @@ import shutil
from PyQt4 import QtCore, QtGui
from openlp.core.lib import PluginStatus, Receiver, MediaType, translate, create_separated_list, \
check_directory_exists, Registry, UiStrings
check_directory_exists, Registry, UiStrings, Registry
from openlp.core.lib.ui import UiStrings, set_case_insensitive_completer, critical_error_message_box, \
find_and_set_in_combo_box
from openlp.core.utils import AppLocation
@ -98,6 +98,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
QtCore.QObject.connect(self.audioRemoveAllButton, QtCore.SIGNAL(u'clicked()'),
self.onAudioRemoveAllButtonClicked)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'theme_update_list'), self.loadThemes)
Registry().register_function(u'theme_update_list', self.loadThemes)
self.previewButton = QtGui.QPushButton()
self.previewButton.setObjectName(u'previewButton')
self.previewButton.setText(UiStrings().SaveAndPreview)