"Fix formatting tags

Move SpellTextEdit as missed
Add working flags API's to registry


lp:~trb143/openlp/may_fixes (revision 2673)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1574/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1485/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1423/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/1202/
[SUCCESS] https://ci.openlp.io/job/Branch-04b-Windows_Interface_Tests/792/
[SUCCESS] https://ci.o..."

bzr-revno: 2669
This commit is contained in:
tim.bentley@gmail.com 2016-05-31 16:03:48 +02:00 committed by Raoul Snyman
commit e841e0fbdc
9 changed files with 82 additions and 11 deletions

View File

@ -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]

View File

@ -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

View File

@ -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']

View File

@ -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()

View File

@ -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):

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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