Cleanup ServiceManager code

This commit is contained in:
Tim Bentley 2013-01-27 07:36:04 +00:00
parent 183c0c700d
commit bdb9089409
14 changed files with 575 additions and 530 deletions

View File

@ -165,7 +165,7 @@ class Settings(QtCore.QSettings):
u'shortcuts/importBibleItem': [], u'shortcuts/importBibleItem': [],
u'shortcuts/modeDefaultItem': [], u'shortcuts/modeDefaultItem': [],
u'shortcuts/modeLiveItem': [], u'shortcuts/modeLiveItem': [],
u'shortcuts/makeLive': [QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return], u'shortcuts/make_live': [QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return],
u'shortcuts/moveUp': [QtCore.Qt.Key_PageUp], u'shortcuts/moveUp': [QtCore.Qt.Key_PageUp],
u'shortcuts/moveTop': [QtCore.Qt.Key_Home], u'shortcuts/moveTop': [QtCore.Qt.Key_Home],
u'shortcuts/modeSetupItem': [], u'shortcuts/modeSetupItem': [],

View File

@ -174,25 +174,25 @@ class Ui_MainWindow(object):
icon=u':/general/general_new.png', icon=u':/general/general_new.png',
shortcuts=[QtGui.QKeySequence(u'Ctrl+N')], shortcuts=[QtGui.QKeySequence(u'Ctrl+N')],
category=UiStrings().File, category=UiStrings().File,
triggers=self.serviceManagerContents.onNewServiceClicked) triggers=self.serviceManagerContents.on_new_service_clicked)
self.fileOpenItem = create_action(mainWindow, u'fileOpenItem', self.fileOpenItem = create_action(mainWindow, u'fileOpenItem',
icon=u':/general/general_open.png', icon=u':/general/general_open.png',
shortcuts=[QtGui.QKeySequence(u'Ctrl+O')], shortcuts=[QtGui.QKeySequence(u'Ctrl+O')],
category=UiStrings().File, category=UiStrings().File,
triggers=self.serviceManagerContents.onLoadServiceClicked) triggers=self.serviceManagerContents.on_load_service_clicked)
self.fileSaveItem = create_action(mainWindow, u'fileSaveItem', self.fileSaveItem = create_action(mainWindow, u'fileSaveItem',
icon=u':/general/general_save.png', icon=u':/general/general_save.png',
shortcuts=[QtGui.QKeySequence(u'Ctrl+S')], shortcuts=[QtGui.QKeySequence(u'Ctrl+S')],
category=UiStrings().File, category=UiStrings().File,
triggers=self.serviceManagerContents.saveFile) triggers=self.serviceManagerContents.save_file)
self.fileSaveAsItem = create_action(mainWindow, u'fileSaveAsItem', self.fileSaveAsItem = create_action(mainWindow, u'fileSaveAsItem',
shortcuts=[QtGui.QKeySequence(u'Ctrl+Shift+S')], shortcuts=[QtGui.QKeySequence(u'Ctrl+Shift+S')],
category=UiStrings().File, category=UiStrings().File,
triggers=self.serviceManagerContents.saveFileAs) triggers=self.serviceManagerContents.save_file_as)
self.printServiceOrderItem = create_action(mainWindow, self.printServiceOrderItem = create_action(mainWindow,
u'printServiceItem', shortcuts=[QtGui.QKeySequence(u'Ctrl+P')], u'printServiceItem', shortcuts=[QtGui.QKeySequence(u'Ctrl+P')],
category=UiStrings().File, category=UiStrings().File,
triggers=self.serviceManagerContents.printServiceOrder) triggers=self.serviceManagerContents.print_service_order)
self.fileExitItem = create_action(mainWindow, u'fileExitItem', self.fileExitItem = create_action(mainWindow, u'fileExitItem',
icon=u':/system/system_exit.png', icon=u':/system/system_exit.png',
shortcuts=[QtGui.QKeySequence(u'Alt+F4')], shortcuts=[QtGui.QKeySequence(u'Alt+F4')],
@ -528,7 +528,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'live_display_blank_check'), self.blankCheck) 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'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'mainwindow_status_text'), self.showStatusMessage)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'cleanup'), self.cleanUp) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'cleanup'), self.clean_up)
# Media Manager # Media Manager
QtCore.QObject.connect(self.mediaToolBox, QtCore.SIGNAL(u'currentChanged(int)'), self.onMediaToolBoxChanged) QtCore.QObject.connect(self.mediaToolBox, QtCore.SIGNAL(u'currentChanged(int)'), self.onMediaToolBoxChanged)
Receiver.send_message(u'cursor_busy') Receiver.send_message(u'cursor_busy')
@ -618,9 +618,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
filename = args[0] filename = args[0]
if not isinstance(filename, unicode): if not isinstance(filename, unicode):
filename = unicode(filename, sys.getfilesystemencoding()) filename = unicode(filename, sys.getfilesystemencoding())
self.serviceManagerContents.loadFile(filename) self.serviceManagerContents.load_file(filename)
elif Settings().value(self.generalSettingsSection + u'/auto open'): elif Settings().value(self.generalSettingsSection + u'/auto open'):
self.serviceManagerContents.loadLastFile() self.serviceManagerContents.load_Last_file()
view_mode = Settings().value(u'%s/view mode' % self.generalSettingsSection) view_mode = Settings().value(u'%s/view mode' % self.generalSettingsSection)
if view_mode == u'default': if view_mode == u'default':
self.modeDefaultItem.setChecked(True) self.modeDefaultItem.setChecked(True)
@ -866,7 +866,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
'be applied the next time you start OpenLP.'), 'be applied the next time you start OpenLP.'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
self.settingsImported = True self.settingsImported = True
self.cleanUp() self.clean_up()
QtCore.QCoreApplication.exit() QtCore.QCoreApplication.exit()
def onSettingsExportItemClicked(self): def onSettingsExportItemClicked(self):
@ -999,18 +999,18 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
return return
# If we just did a settings import, close without saving changes. # If we just did a settings import, close without saving changes.
if self.settingsImported: if self.settingsImported:
self.cleanUp(False) self.clean_up(False)
event.accept() event.accept()
if self.serviceManagerContents.isModified(): if self.serviceManagerContents.is_modified():
ret = self.serviceManagerContents.saveModifiedService() ret = self.serviceManagerContents.save_modified_service()
if ret == QtGui.QMessageBox.Save: if ret == QtGui.QMessageBox.Save:
if self.serviceManagerContents.decideSaveMethod(): if self.serviceManagerContents.decide_save_method():
self.cleanUp() self.clean_up()
event.accept() event.accept()
else: else:
event.ignore() event.ignore()
elif ret == QtGui.QMessageBox.Discard: elif ret == QtGui.QMessageBox.Discard:
self.cleanUp() self.clean_up()
event.accept() event.accept()
else: else:
event.ignore() event.ignore()
@ -1021,15 +1021,15 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
QtGui.QMessageBox.Yes) QtGui.QMessageBox.Yes)
if ret == QtGui.QMessageBox.Yes: if ret == QtGui.QMessageBox.Yes:
self.cleanUp() self.clean_up()
event.accept() event.accept()
else: else:
event.ignore() event.ignore()
else: else:
self.cleanUp() self.clean_up()
event.accept() event.accept()
def cleanUp(self, save_settings=True): def clean_up(self, save_settings=True):
""" """
Runs all the cleanup code before OpenLP shuts down. Runs all the cleanup code before OpenLP shuts down.
@ -1223,7 +1223,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
action = create_action(self, u'', action = create_action(self, u'',
text=u'&%d %s' % (fileId + 1, os.path.splitext(os.path.basename( text=u'&%d %s' % (fileId + 1, os.path.splitext(os.path.basename(
unicode(filename)))[0]), data=filename, unicode(filename)))[0]), data=filename,
triggers=self.serviceManagerContents.onRecentServiceClicked) triggers=self.serviceManagerContents.on_recent_service_clicked)
self.recentFilesMenu.addAction(action) self.recentFilesMenu.addAction(action)
clearRecentFilesAction = create_action(self, u'', clearRecentFilesAction = create_action(self, u'',
text=translate('OpenLP.MainWindow', 'Clear List', 'Clear List of recent files'), text=translate('OpenLP.MainWindow', 'Clear List', 'Clear List of recent files'),

View File

@ -131,14 +131,14 @@ class MediaController(object):
for item in player.audio_extensions_list: for item in player.audio_extensions_list:
if not item in self.audio_extensions_list: if not item in self.audio_extensions_list:
self.audio_extensions_list.append(item) self.audio_extensions_list.append(item)
self.service_manager.supportedSuffixes(item[2:]) self.service_manager.supported_suffixes(item[2:])
self.video_extensions_list = [] self.video_extensions_list = []
for player in self.mediaPlayers.values(): for player in self.mediaPlayers.values():
if player.isActive: if player.isActive:
for item in player.video_extensions_list: for item in player.video_extensions_list:
if item not in self.video_extensions_list: if item not in self.video_extensions_list:
self.video_extensions_list.extend(item) self.video_extensions_list.extend(item)
self.service_manager.supportedSuffixes(item[2:]) self.service_manager.supported_suffixes(item[2:])
def register_players(self, player): def register_players(self, player):
""" """

View File

@ -194,7 +194,7 @@ class PlayerTab(SettingsTab):
set_media_players(self.usedPlayers, override_player) set_media_players(self.usedPlayers, override_player)
player_string_changed = True player_string_changed = True
if player_string_changed: if player_string_changed:
self.parent.resetSupportedSuffixes() self.parent.reset_supported_suffixes()
Receiver.send_message(u'mediaitem_media_rebuild') Receiver.send_message(u'mediaitem_media_rebuild')
Receiver.send_message(u'config_screen_changed') Receiver.send_message(u'config_screen_changed')

View File

@ -138,7 +138,8 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
QtCore.QObject.connect(self.zoomComboBox, QtCore.SIGNAL(u'currentIndexChanged(int)'), self.displaySizeChanged) QtCore.QObject.connect(self.zoomComboBox, QtCore.SIGNAL(u'currentIndexChanged(int)'), self.displaySizeChanged)
QtCore.QObject.connect(self.plainCopy, QtCore.SIGNAL(u'triggered()'), self.copyText) QtCore.QObject.connect(self.plainCopy, QtCore.SIGNAL(u'triggered()'), self.copyText)
QtCore.QObject.connect(self.htmlCopy, QtCore.SIGNAL(u'triggered()'), self.copyHtmlText) QtCore.QObject.connect(self.htmlCopy, QtCore.SIGNAL(u'triggered()'), self.copyHtmlText)
QtCore.QObject.connect(self.slideTextCheckBox, QtCore.SIGNAL(u'stateChanged(int)'), self.onSlideTextCheckBoxChanged) QtCore.QObject.connect(self.slideTextCheckBox, QtCore.SIGNAL(u'stateChanged(int)'),
self.onSlideTextCheckBoxChanged)
self.updatePreviewText() self.updatePreviewText()
def toggleOptions(self, checked): def toggleOptions(self, checked):

View File

@ -28,6 +28,7 @@
############################################################################### ###############################################################################
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import Registry
from serviceitemeditdialog import Ui_ServiceItemEditDialog from serviceitemeditdialog import Ui_ServiceItemEditDialog
@ -35,11 +36,11 @@ class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog):
""" """
This is the form that is used to edit the verses of the song. This is the form that is used to edit the verses of the song.
""" """
def __init__(self, parent=None): def __init__(self):
""" """
Constructor Constructor
""" """
QtGui.QDialog.__init__(self, parent) QtGui.QDialog.__init__(self, self.main_window)
self.setupUi(self) self.setupUi(self)
self.itemList = [] self.itemList = []
QtCore.QObject.connect(self.listWidget, QtCore.SIGNAL(u'currentRowChanged(int)'), self.onCurrentRowChanged) QtCore.QObject.connect(self.listWidget, QtCore.SIGNAL(u'currentRowChanged(int)'), self.onCurrentRowChanged)
@ -143,3 +144,13 @@ class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog):
else: else:
self.upButton.setEnabled(True) self.upButton.setEnabled(True)
self.deleteButton.setEnabled(True) self.deleteButton.setEnabled(True)
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)

File diff suppressed because it is too large Load Diff

View File

@ -29,18 +29,18 @@
from PyQt4 import QtGui from PyQt4 import QtGui
from openlp.core.lib import translate, SpellTextEdit from openlp.core.lib import translate, SpellTextEdit, Registry
from openlp.core.lib.ui import create_button_box from openlp.core.lib.ui import create_button_box
class ServiceNoteForm(QtGui.QDialog): class ServiceNoteForm(QtGui.QDialog):
""" """
This is the form that is used to edit the verses of the song. This is the form that is used to edit the verses of the song.
""" """
def __init__(self, parent=None): def __init__(self):
""" """
Constructor Constructor
""" """
QtGui.QDialog.__init__(self, parent) QtGui.QDialog.__init__(self, self.main_window)
self.setupUi() self.setupUi()
self.retranslateUi() self.retranslateUi()
@ -62,3 +62,13 @@ class ServiceNoteForm(QtGui.QDialog):
def retranslateUi(self): def retranslateUi(self):
self.setWindowTitle(translate('OpenLP.ServiceNoteForm', 'Service Item Notes')) self.setWindowTitle(translate('OpenLP.ServiceNoteForm', 'Service Item Notes'))
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

@ -140,7 +140,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
per save. per save.
""" """
if self.resetSuffixes: if self.resetSuffixes:
self.service_manager.resetSupportedSuffixes() self.service_manager.reset_supported_suffixes()
self.resetSuffixes = False self.resetSuffixes = False
def _get_main_window(self): def _get_main_window(self):

View File

@ -31,15 +31,15 @@ from PyQt4 import QtGui
from starttimedialog import Ui_StartTimeDialog from starttimedialog import Ui_StartTimeDialog
from openlp.core.lib import translate, UiStrings from openlp.core.lib import translate, UiStrings, Registry
from openlp.core.lib.ui import critical_error_message_box from openlp.core.lib.ui import critical_error_message_box
class StartTimeForm(QtGui.QDialog, Ui_StartTimeDialog): class StartTimeForm(QtGui.QDialog, Ui_StartTimeDialog):
""" """
The exception dialog The exception dialog
""" """
def __init__(self, parent): def __init__(self):
QtGui.QDialog.__init__(self, parent) QtGui.QDialog.__init__(self, self.main_window)
self.setupUi(self) self.setupUi(self)
def exec_(self): def exec_(self):
@ -84,3 +84,13 @@ class StartTimeForm(QtGui.QDialog, Ui_StartTimeDialog):
minutes = seconds / 60 minutes = seconds / 60
seconds -= 60 * minutes seconds -= 60 * minutes
return hours, minutes, seconds return hours, minutes, seconds
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

@ -85,6 +85,6 @@ class MediaTab(SettingsTab):
if Settings().value(setting_key) != self.autoStartCheckBox.checkState(): if Settings().value(setting_key) != self.autoStartCheckBox.checkState():
Settings().setValue(setting_key, self.autoStartCheckBox.checkState()) Settings().setValue(setting_key, self.autoStartCheckBox.checkState())
if override_changed: if override_changed:
self.parent.resetSupportedSuffixes() self.parent.reset_supported_suffixes()
Receiver.send_message(u'mediaitem_media_rebuild') Receiver.send_message(u'mediaitem_media_rebuild')
Receiver.send_message(u'mediaitem_suffixes') Receiver.send_message(u'mediaitem_suffixes')

View File

@ -85,7 +85,7 @@ class PresentationMediaItem(MediaManagerItem):
for type in types: for type in types:
if fileType.find(type) == -1: if fileType.find(type) == -1:
fileType += u'*.%s ' % type fileType += u'*.%s ' % type
self.service_manager.supportedSuffixes(type) self.service_manager.supported_suffixes(type)
self.onNewFileMasks = translate('PresentationPlugin.MediaItem', 'Presentations (%s)') % fileType self.onNewFileMasks = translate('PresentationPlugin.MediaItem', 'Presentations (%s)') % fileType
def requiredIcons(self): def requiredIcons(self):

View File

@ -129,7 +129,7 @@ class PresentationTab(SettingsTab):
Settings().setValue(setting_key, self.OverrideAppCheckBox.checkState()) Settings().setValue(setting_key, self.OverrideAppCheckBox.checkState())
changed = True changed = True
if changed: if changed:
self.parent.resetSupportedSuffixes() self.parent.reset_supported_suffixes()
Receiver.send_message(u'mediaitem_presentation_rebuild') Receiver.send_message(u'mediaitem_presentation_rebuild')
Receiver.send_message(u'mediaitem_suffixes') Receiver.send_message(u'mediaitem_suffixes')

View File

@ -5,6 +5,7 @@ import sys
from unittest import TestCase from unittest import TestCase
from mock import MagicMock, patch from mock import MagicMock, patch
from openlp.core.lib import Registry
from openlp.core.ui import starttimeform from openlp.core.ui import starttimeform
from PyQt4 import QtCore, QtGui, QtTest from PyQt4 import QtCore, QtGui, QtTest
@ -14,21 +15,23 @@ class TestStartTimeDialog(TestCase):
""" """
Create the UI Create the UI
""" """
registry = Registry.create()
self.app = QtGui.QApplication([]) self.app = QtGui.QApplication([])
self.window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
self.form = starttimeform.StartTimeForm(self.window) Registry().register(u'main_window', self.main_window)
self.form = starttimeform.StartTimeForm()
def tearDown(self): def tearDown(self):
""" """
Delete all the C++ objects at the end so that we don't have a segfault Delete all the C++ objects at the end so that we don't have a segfault
""" """
del self.form del self.form
del self.window del self.main_window
del self.app del self.app
def ui_defaults_test(self): def ui_defaults_test(self):
""" """
Test StartTimeDialog defaults Test StartTimeDialog are defaults correct
""" """
self.assertEqual(self.form.hourSpinBox.minimum(), 0) self.assertEqual(self.form.hourSpinBox.minimum(), 0)
self.assertEqual(self.form.hourSpinBox.maximum(), 4) self.assertEqual(self.form.hourSpinBox.maximum(), 4)