diff --git a/openlp/core/common/registry.py b/openlp/core/common/registry.py index b904d627c..85fca6912 100644 --- a/openlp/core/common/registry.py +++ b/openlp/core/common/registry.py @@ -55,6 +55,7 @@ class Registry(object): registry = cls() registry.service_list = {} registry.functions_list = {} + registry.working_flags = {} # Allow the tests to remove Registry entries but not the live system registry.running_under_test = 'nose' in sys.argv[0] registry.initialising = True @@ -90,8 +91,7 @@ class Registry(object): def remove(self, key): """ - Removes the registry value from the list based on the key passed in (Only valid and active for testing - framework). + Removes the registry value from the list based on the key passed in. :param key: The service to be deleted. """ @@ -145,3 +145,34 @@ class Registry(object): trace_error_handler(log) log.error("Event {event} called but not registered".format(event=event)) return results + + def get_flag(self, key): + """ + Extracts the working_flag value from the list based on the key passed in + + :param key: The flag to be retrieved. + """ + if key in self.working_flags: + return self.working_flags[key] + else: + trace_error_handler(log) + log.error('Working Flag {key} not found in list'.format(key=key)) + raise KeyError('Working Flag {key} not found in list'.format(key=key)) + + def set_flag(self, key, reference): + """ + Sets a working_flag based on the key passed in. + + :param key: The working_flag to be created this is usually a major class like "renderer" or "main_window" . + :param reference: The data to be saved. + """ + self.working_flags[key] = reference + + def remove_flag(self, key): + """ + Removes the working flags value from the list based on the key passed. + + :param key: The working_flag to be deleted. + """ + if key in self.working_flags: + del self.working_flags[key] diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 59053e283..a7e01bd24 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -24,13 +24,12 @@ The :mod:`lib` module contains most of the components and libraries that make OpenLP work. """ -from distutils.version import LooseVersion import logging import os +from distutils.version import LooseVersion from PyQt5 import QtCore, QtGui, Qt, QtWidgets - from openlp.core.common import translate log = logging.getLogger(__name__ + '.__init__') @@ -342,7 +341,6 @@ from .exceptions import ValidationError from .filedialog import FileDialog from .screen import ScreenList from .formattingtags import FormattingTags -from .spelltextedit import SpellTextEdit from .plugin import PluginStatus, StringContent, Plugin from .pluginmanager import PluginManager from .settingstab import SettingsTab diff --git a/openlp/core/ui/lib/__init__.py b/openlp/core/ui/lib/__init__.py index 6cdeac8a6..ae81b10ad 100644 --- a/openlp/core/ui/lib/__init__.py +++ b/openlp/core/ui/lib/__init__.py @@ -28,6 +28,7 @@ from .dockwidget import OpenLPDockWidget from .wizard import OpenLPWizard, WizardStrings from .mediadockmanager import MediaDockManager from .listpreviewwidget import ListPreviewWidget +from .spelltextedit import SpellTextEdit __all__ = ['ColorButton', 'ListPreviewWidget', 'ListWidgetWithDnD', 'OpenLPToolbar', 'OpenLPDockWidget', - 'OpenLPWizard', 'WizardStrings', 'MediaDockManager', 'ListPreviewWidget'] + 'OpenLPWizard', 'WizardStrings', 'MediaDockManager', 'ListPreviewWidget', 'SpellTextEdit'] diff --git a/openlp/core/lib/spelltextedit.py b/openlp/core/ui/lib/spelltextedit.py similarity index 99% rename from openlp/core/lib/spelltextedit.py rename to openlp/core/ui/lib/spelltextedit.py index 3b97323af..8b6b552be 100644 --- a/openlp/core/lib/spelltextedit.py +++ b/openlp/core/ui/lib/spelltextedit.py @@ -142,6 +142,7 @@ class SpellTextEdit(QtWidgets.QPlainTextEdit): """ Replaces the selected text with word. """ + tag = tag.replace('&', '') for html in FormattingTags.get_html_tags(): if tag == html['desc']: cursor = self.textCursor() diff --git a/openlp/core/ui/printservicedialog.py b/openlp/core/ui/printservicedialog.py index 93a42e2a8..c658d1496 100644 --- a/openlp/core/ui/printservicedialog.py +++ b/openlp/core/ui/printservicedialog.py @@ -25,7 +25,8 @@ The UI widgets of the print service dialog. from PyQt5 import QtCore, QtWidgets, QtPrintSupport from openlp.core.common import UiStrings, translate -from openlp.core.lib import SpellTextEdit, build_icon +from openlp.core.lib import build_icon +from openlp.core.ui.lib import SpellTextEdit class ZoomSize(object): diff --git a/openlp/core/ui/servicenoteform.py b/openlp/core/ui/servicenoteform.py index e998304f8..383c47048 100644 --- a/openlp/core/ui/servicenoteform.py +++ b/openlp/core/ui/servicenoteform.py @@ -25,7 +25,7 @@ The :mod:`~openlp.core.ui.servicenoteform` module contains the `ServiceNoteForm` from PyQt5 import QtCore, QtWidgets from openlp.core.common import Registry, RegistryProperties, translate -from openlp.core.lib import SpellTextEdit +from openlp.core.ui.lib import SpellTextEdit from openlp.core.lib.ui import create_button_box diff --git a/openlp/plugins/custom/forms/editcustomslidedialog.py b/openlp/plugins/custom/forms/editcustomslidedialog.py index c5212c84e..5f46c6f28 100644 --- a/openlp/plugins/custom/forms/editcustomslidedialog.py +++ b/openlp/plugins/custom/forms/editcustomslidedialog.py @@ -23,8 +23,9 @@ from PyQt5 import QtWidgets from openlp.core.common import UiStrings, translate -from openlp.core.lib import SpellTextEdit, build_icon +from openlp.core.lib import build_icon from openlp.core.lib.ui import create_button, create_button_box +from openlp.core.ui.lib import SpellTextEdit class Ui_CustomSlideEditDialog(object): diff --git a/openlp/plugins/songs/forms/editversedialog.py b/openlp/plugins/songs/forms/editversedialog.py index 144d59efc..6819f3ca6 100644 --- a/openlp/plugins/songs/forms/editversedialog.py +++ b/openlp/plugins/songs/forms/editversedialog.py @@ -22,7 +22,8 @@ from PyQt5 import QtWidgets -from openlp.core.lib import SpellTextEdit, build_icon, translate +from openlp.core.ui.lib import SpellTextEdit +from openlp.core.lib import build_icon, translate from openlp.core.lib.ui import UiStrings, create_button_box from openlp.plugins.songs.lib import VerseType diff --git a/tests/functional/openlp_core_common/test_registry.py b/tests/functional/openlp_core_common/test_registry.py index db46f3239..0642ff93c 100644 --- a/tests/functional/openlp_core_common/test_registry.py +++ b/tests/functional/openlp_core_common/test_registry.py @@ -59,7 +59,7 @@ class TestRegistry(TestCase): temp = Registry().get('test2') self.assertEqual(temp, None, 'None should have been returned for missing service') - # WHEN I try to replace a component I should be allowed (testing only) + # WHEN I try to replace a component I should be allowed Registry().remove('test1') # THEN I will get an exception temp = Registry().get('test1') @@ -93,6 +93,43 @@ class TestRegistry(TestCase): # THEN: I expect then function to have been called and a return given self.assertEqual(return_value[0], 'function_2', 'A return value is provided and matches') + def registry_working_flags_test(self): + """ + Test the registry working flags creation and its usage + """ + # GIVEN: A new registry + Registry.create() + + # WHEN: I add a working flag it should save it + my_data = 'Lamas' + my_data2 = 'More Lamas' + Registry().set_flag('test1', my_data) + + # THEN: we should be able retrieve the saved component + temp = Registry().get_flag('test1') + self.assertEquals(temp, my_data, 'The value should have been saved') + + # WHEN: I add a component for the second time I am not mad. + # THEN and I will not get an exception + Registry().set_flag('test1', my_data2) + temp = Registry().get_flag('test1') + self.assertEquals(temp, my_data2, 'The value should have been updated') + + # WHEN I try to get back a non existent Working Flag + # THEN I will get an exception + with self.assertRaises(KeyError) as context1: + temp = Registry().get_flag('test2') + self.assertEqual(context1.exception.args[0], 'Working Flag test2 not found in list', + 'KeyError exception should have been thrown for missing working flag') + + # WHEN I try to replace a working flag I should be allowed + Registry().remove_flag('test1') + # THEN I will get an exception + with self.assertRaises(KeyError) as context: + temp = Registry().get_flag('test1') + self.assertEqual(context.exception.args[0], 'Working Flag test1 not found in list', + 'KeyError exception should have been thrown for duplicate working flag') + def remove_function_test(self): """ Test the remove_function() method