From 1ea5d72d1e9da7e5f7805ad889042a7f0bf302f5 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 21 May 2016 06:02:31 +0100 Subject: [PATCH 1/5] fix formatting tags and move SpellText Edit --- openlp/core/lib/__init__.py | 4 +- openlp/core/lib/spelltextedit.py | 203 ------------------ openlp/core/ui/lib/__init__.py | 3 +- openlp/core/ui/printservicedialog.py | 3 +- openlp/core/ui/servicenoteform.py | 2 +- .../custom/forms/editcustomslidedialog.py | 3 +- openlp/plugins/songs/forms/editversedialog.py | 3 +- 7 files changed, 10 insertions(+), 211 deletions(-) delete mode 100644 openlp/core/lib/spelltextedit.py 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/lib/spelltextedit.py b/openlp/core/lib/spelltextedit.py deleted file mode 100644 index 3b97323af..000000000 --- a/openlp/core/lib/spelltextedit.py +++ /dev/null @@ -1,203 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2016 OpenLP Developers # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### -""" -The :mod:`~openlp.core.lib.spelltextedit` module contains a classes to add spell checking to an edit widget. -""" - -import logging -import re - -try: - import enchant - from enchant import DictNotFoundError - from enchant.errors import Error - ENCHANT_AVAILABLE = True -except ImportError: - ENCHANT_AVAILABLE = False - -# based on code from http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check - -from PyQt5 import QtCore, QtGui, QtWidgets - -from openlp.core.lib import translate, FormattingTags -from openlp.core.lib.ui import create_action - -log = logging.getLogger(__name__) - - -class SpellTextEdit(QtWidgets.QPlainTextEdit): - """ - Spell checking widget based on QPlanTextEdit. - """ - def __init__(self, parent=None, formatting_tags_allowed=True): - """ - Constructor. - """ - global ENCHANT_AVAILABLE - super(SpellTextEdit, self).__init__(parent) - self.formatting_tags_allowed = formatting_tags_allowed - # Default dictionary based on the current locale. - if ENCHANT_AVAILABLE: - try: - self.dictionary = enchant.Dict() - self.highlighter = Highlighter(self.document()) - self.highlighter.spelling_dictionary = self.dictionary - except (Error, DictNotFoundError): - ENCHANT_AVAILABLE = False - log.debug('Could not load default dictionary') - - def mousePressEvent(self, event): - """ - Handle mouse clicks within the text edit region. - """ - if event.button() == QtCore.Qt.RightButton: - # Rewrite the mouse event to a left button event so the cursor is moved to the location of the pointer. - event = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, - event.pos(), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier) - QtWidgets.QPlainTextEdit.mousePressEvent(self, event) - - def contextMenuEvent(self, event): - """ - Provide the context menu for the text edit region. - """ - popup_menu = self.createStandardContextMenu() - # Select the word under the cursor. - cursor = self.textCursor() - # only select text if not already selected - if not cursor.hasSelection(): - cursor.select(QtGui.QTextCursor.WordUnderCursor) - self.setTextCursor(cursor) - # Add menu with available languages. - if ENCHANT_AVAILABLE: - lang_menu = QtWidgets.QMenu(translate('OpenLP.SpellTextEdit', 'Language:')) - for lang in enchant.list_languages(): - action = create_action(lang_menu, lang, text=lang, checked=lang == self.dictionary.tag) - lang_menu.addAction(action) - popup_menu.insertSeparator(popup_menu.actions()[0]) - popup_menu.insertMenu(popup_menu.actions()[0], lang_menu) - lang_menu.triggered.connect(self.set_language) - # Check if the selected word is misspelled and offer spelling suggestions if it is. - if ENCHANT_AVAILABLE and self.textCursor().hasSelection(): - text = self.textCursor().selectedText() - if not self.dictionary.check(text): - spell_menu = QtWidgets.QMenu(translate('OpenLP.SpellTextEdit', 'Spelling Suggestions')) - for word in self.dictionary.suggest(text): - action = SpellAction(word, spell_menu) - action.correct.connect(self.correct_word) - spell_menu.addAction(action) - # Only add the spelling suggests to the menu if there are suggestions. - if spell_menu.actions(): - popup_menu.insertMenu(popup_menu.actions()[0], spell_menu) - tag_menu = QtWidgets.QMenu(translate('OpenLP.SpellTextEdit', 'Formatting Tags')) - if self.formatting_tags_allowed: - for html in FormattingTags.get_html_tags(): - action = SpellAction(html['desc'], tag_menu) - action.correct.connect(self.html_tag) - tag_menu.addAction(action) - popup_menu.insertSeparator(popup_menu.actions()[0]) - popup_menu.insertMenu(popup_menu.actions()[0], tag_menu) - popup_menu.exec(event.globalPos()) - - def set_language(self, action): - """ - Changes the language for this spelltextedit. - - :param action: The action. - """ - self.dictionary = enchant.Dict(action.text()) - self.highlighter.spelling_dictionary = self.dictionary - self.highlighter.highlightBlock(self.toPlainText()) - self.highlighter.rehighlight() - - def correct_word(self, word): - """ - Replaces the selected text with word. - """ - cursor = self.textCursor() - cursor.beginEditBlock() - cursor.removeSelectedText() - cursor.insertText(word) - cursor.endEditBlock() - - def html_tag(self, tag): - """ - Replaces the selected text with word. - """ - for html in FormattingTags.get_html_tags(): - if tag == html['desc']: - cursor = self.textCursor() - if self.textCursor().hasSelection(): - text = cursor.selectedText() - cursor.beginEditBlock() - cursor.removeSelectedText() - cursor.insertText(html['start tag']) - cursor.insertText(text) - cursor.insertText(html['end tag']) - cursor.endEditBlock() - else: - cursor = self.textCursor() - cursor.insertText(html['start tag']) - cursor.insertText(html['end tag']) - - -class Highlighter(QtGui.QSyntaxHighlighter): - """ - Provides a text highlighter for pointing out spelling errors in text. - """ - WORDS = '(?iu)[\w\']+' - - def __init__(self, *args): - """ - Constructor - """ - super(Highlighter, self).__init__(*args) - self.spelling_dictionary = None - - def highlightBlock(self, text): - """ - Highlight mis spelt words in a block of text. - - Note, this is a Qt hook. - """ - if not self.spelling_dictionary: - return - text = str(text) - char_format = QtGui.QTextCharFormat() - char_format.setUnderlineColor(QtCore.Qt.red) - char_format.setUnderlineStyle(QtGui.QTextCharFormat.SpellCheckUnderline) - for word_object in re.finditer(self.WORDS, text): - if not self.spelling_dictionary.check(word_object.group()): - self.setFormat(word_object.start(), word_object.end() - word_object.start(), char_format) - - -class SpellAction(QtWidgets.QAction): - """ - A special QAction that returns the text in a signal. - """ - correct = QtCore.pyqtSignal(str) - - def __init__(self, *args): - """ - Constructor - """ - super(SpellAction, self).__init__(*args) - self.triggered.connect(lambda x: self.correct.emit(self.text())) 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/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 From d0f6d21774e8b6f0f7b00699cd8b4f22584e18d9 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 21 May 2016 06:24:05 +0100 Subject: [PATCH 2/5] Add Working flags --- openlp/core/common/registry.py | 41 +++- openlp/core/ui/lib/spelltextedit.py | 204 ++++++++++++++++++ .../openlp_core_common/test_registry.py | 38 +++- 3 files changed, 280 insertions(+), 3 deletions(-) create mode 100644 openlp/core/ui/lib/spelltextedit.py diff --git a/openlp/core/common/registry.py b/openlp/core/common/registry.py index b904d627c..65547819a 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,40 @@ 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. + """ + if key in self.working_flags: + trace_error_handler(log) + log.error('Duplicate Working Flag exception {key}'.format(key=key)) + raise KeyError('Duplicate Working Flag exception {key}'.format(key=key)) + else: + 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/ui/lib/spelltextedit.py b/openlp/core/ui/lib/spelltextedit.py new file mode 100644 index 000000000..c16bd0bca --- /dev/null +++ b/openlp/core/ui/lib/spelltextedit.py @@ -0,0 +1,204 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2016 OpenLP Developers # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +The :mod:`~openlp.core.lib.spelltextedit` module contains a classes to add spell checking to an edit widget. +""" + +import logging +import re + +try: + import enchant + from enchant import DictNotFoundError + from enchant.errors import Error + ENCHANT_AVAILABLE = True +except ImportError: + ENCHANT_AVAILABLE = False + +# based on code from http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check + +from PyQt5 import QtCore, QtGui, QtWidgets + +from openlp.core.lib import translate, FormattingTags +from openlp.core.lib.ui import create_action + +log = logging.getLogger(__name__) + + +class SpellTextEdit(QtWidgets.QPlainTextEdit): + """ + Spell checking widget based on QPlanTextEdit. + """ + def __init__(self, parent=None, formatting_tags_allowed=True): + """ + Constructor. + """ + global ENCHANT_AVAILABLE + super(SpellTextEdit, self).__init__(parent) + self.formatting_tags_allowed = formatting_tags_allowed + # Default dictionary based on the current locale. + if ENCHANT_AVAILABLE: + try: + self.dictionary = enchant.Dict() + self.highlighter = Highlighter(self.document()) + self.highlighter.spelling_dictionary = self.dictionary + except (Error, DictNotFoundError): + ENCHANT_AVAILABLE = False + log.debug('Could not load default dictionary') + + def mousePressEvent(self, event): + """ + Handle mouse clicks within the text edit region. + """ + if event.button() == QtCore.Qt.RightButton: + # Rewrite the mouse event to a left button event so the cursor is moved to the location of the pointer. + event = QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, + event.pos(), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier) + QtWidgets.QPlainTextEdit.mousePressEvent(self, event) + + def contextMenuEvent(self, event): + """ + Provide the context menu for the text edit region. + """ + popup_menu = self.createStandardContextMenu() + # Select the word under the cursor. + cursor = self.textCursor() + # only select text if not already selected + if not cursor.hasSelection(): + cursor.select(QtGui.QTextCursor.WordUnderCursor) + self.setTextCursor(cursor) + # Add menu with available languages. + if ENCHANT_AVAILABLE: + lang_menu = QtWidgets.QMenu(translate('OpenLP.SpellTextEdit', 'Language:')) + for lang in enchant.list_languages(): + action = create_action(lang_menu, lang, text=lang, checked=lang == self.dictionary.tag) + lang_menu.addAction(action) + popup_menu.insertSeparator(popup_menu.actions()[0]) + popup_menu.insertMenu(popup_menu.actions()[0], lang_menu) + lang_menu.triggered.connect(self.set_language) + # Check if the selected word is misspelled and offer spelling suggestions if it is. + if ENCHANT_AVAILABLE and self.textCursor().hasSelection(): + text = self.textCursor().selectedText() + if not self.dictionary.check(text): + spell_menu = QtWidgets.QMenu(translate('OpenLP.SpellTextEdit', 'Spelling Suggestions')) + for word in self.dictionary.suggest(text): + action = SpellAction(word, spell_menu) + action.correct.connect(self.correct_word) + spell_menu.addAction(action) + # Only add the spelling suggests to the menu if there are suggestions. + if spell_menu.actions(): + popup_menu.insertMenu(popup_menu.actions()[0], spell_menu) + tag_menu = QtWidgets.QMenu(translate('OpenLP.SpellTextEdit', 'Formatting Tags')) + if self.formatting_tags_allowed: + for html in FormattingTags.get_html_tags(): + action = SpellAction(html['desc'], tag_menu) + action.correct.connect(self.html_tag) + tag_menu.addAction(action) + popup_menu.insertSeparator(popup_menu.actions()[0]) + popup_menu.insertMenu(popup_menu.actions()[0], tag_menu) + popup_menu.exec(event.globalPos()) + + def set_language(self, action): + """ + Changes the language for this spelltextedit. + + :param action: The action. + """ + self.dictionary = enchant.Dict(action.text()) + self.highlighter.spelling_dictionary = self.dictionary + self.highlighter.highlightBlock(self.toPlainText()) + self.highlighter.rehighlight() + + def correct_word(self, word): + """ + Replaces the selected text with word. + """ + cursor = self.textCursor() + cursor.beginEditBlock() + cursor.removeSelectedText() + cursor.insertText(word) + cursor.endEditBlock() + + def html_tag(self, tag): + """ + Replaces the selected text with word. + """ + for html in FormattingTags.get_html_tags(): + tag = tag.replace('&', '') + if tag == html['desc']: + cursor = self.textCursor() + if self.textCursor().hasSelection(): + text = cursor.selectedText() + cursor.beginEditBlock() + cursor.removeSelectedText() + cursor.insertText(html['start tag']) + cursor.insertText(text) + cursor.insertText(html['end tag']) + cursor.endEditBlock() + else: + cursor = self.textCursor() + cursor.insertText(html['start tag']) + cursor.insertText(html['end tag']) + + +class Highlighter(QtGui.QSyntaxHighlighter): + """ + Provides a text highlighter for pointing out spelling errors in text. + """ + WORDS = '(?iu)[\w\']+' + + def __init__(self, *args): + """ + Constructor + """ + super(Highlighter, self).__init__(*args) + self.spelling_dictionary = None + + def highlightBlock(self, text): + """ + Highlight mis spelt words in a block of text. + + Note, this is a Qt hook. + """ + if not self.spelling_dictionary: + return + text = str(text) + char_format = QtGui.QTextCharFormat() + char_format.setUnderlineColor(QtCore.Qt.red) + char_format.setUnderlineStyle(QtGui.QTextCharFormat.SpellCheckUnderline) + for word_object in re.finditer(self.WORDS, text): + if not self.spelling_dictionary.check(word_object.group()): + self.setFormat(word_object.start(), word_object.end() - word_object.start(), char_format) + + +class SpellAction(QtWidgets.QAction): + """ + A special QAction that returns the text in a signal. + """ + correct = QtCore.pyqtSignal(str) + + def __init__(self, *args): + """ + Constructor + """ + super(SpellAction, self).__init__(*args) + self.triggered.connect(lambda x: self.correct.emit(self.text())) diff --git a/tests/functional/openlp_core_common/test_registry.py b/tests/functional/openlp_core_common/test_registry.py index db46f3239..0cac19bcd 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,42 @@ 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' + Registry().set_flag('test1', my_data) + + # THEN: we should be able retrieve the saved component + assert Registry().get_flag('test1') == my_data, 'The working flag can be retrieved and matches' + + # WHEN: I add a component for the second time I am mad. + # THEN and I will get an exception + with self.assertRaises(KeyError) as context: + Registry().set_flag('test1', my_data) + self.assertEqual(context.exception.args[0], 'Duplicate Working Flag exception test1', + 'KeyError exception should have been thrown for duplicate working flag') + + # 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 From af36dc4c41eeb1f36c3bbec27e4daa0a350442e3 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 21 May 2016 06:28:13 +0100 Subject: [PATCH 3/5] pep8 --- openlp/core/common/registry.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/core/common/registry.py b/openlp/core/common/registry.py index 65547819a..ee322d87d 100644 --- a/openlp/core/common/registry.py +++ b/openlp/core/common/registry.py @@ -181,4 +181,3 @@ class Registry(object): """ if key in self.working_flags: del self.working_flags[key] - From 6d3ad3af3f54bab10651c182f0509929d97d07de Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 21 May 2016 20:01:50 +0100 Subject: [PATCH 4/5] Improve performance --- openlp/core/ui/lib/spelltextedit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/lib/spelltextedit.py b/openlp/core/ui/lib/spelltextedit.py index c16bd0bca..8b6b552be 100644 --- a/openlp/core/ui/lib/spelltextedit.py +++ b/openlp/core/ui/lib/spelltextedit.py @@ -142,8 +142,8 @@ class SpellTextEdit(QtWidgets.QPlainTextEdit): """ Replaces the selected text with word. """ + tag = tag.replace('&', '') for html in FormattingTags.get_html_tags(): - tag = tag.replace('&', '') if tag == html['desc']: cursor = self.textCursor() if self.textCursor().hasSelection(): From 32ef88f8074df58fce1a343011ae15c05c669289 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 24 May 2016 17:28:11 +0100 Subject: [PATCH 5/5] Fix set_value and adjust tests --- openlp/core/common/registry.py | 7 +------ .../openlp_core_common/test_registry.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/openlp/core/common/registry.py b/openlp/core/common/registry.py index ee322d87d..85fca6912 100644 --- a/openlp/core/common/registry.py +++ b/openlp/core/common/registry.py @@ -166,12 +166,7 @@ class Registry(object): :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. """ - if key in self.working_flags: - trace_error_handler(log) - log.error('Duplicate Working Flag exception {key}'.format(key=key)) - raise KeyError('Duplicate Working Flag exception {key}'.format(key=key)) - else: - self.working_flags[key] = reference + self.working_flags[key] = reference def remove_flag(self, key): """ diff --git a/tests/functional/openlp_core_common/test_registry.py b/tests/functional/openlp_core_common/test_registry.py index 0cac19bcd..0642ff93c 100644 --- a/tests/functional/openlp_core_common/test_registry.py +++ b/tests/functional/openlp_core_common/test_registry.py @@ -102,17 +102,18 @@ class TestRegistry(TestCase): # 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 - assert Registry().get_flag('test1') == my_data, 'The working flag can be retrieved and matches' + 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 mad. - # THEN and I will get an exception - with self.assertRaises(KeyError) as context: - Registry().set_flag('test1', my_data) - self.assertEqual(context.exception.args[0], 'Duplicate Working Flag exception test1', - 'KeyError exception should have been thrown for duplicate working flag') + # 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