diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index b2d8f6ea7..1984b08ba 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -29,7 +29,7 @@ """ Provide HTML Tag management and Formatting Tag access class """ -import cPickle +import json from openlp.core.lib import Settings, translate @@ -66,7 +66,7 @@ class FormattingTags(object): if isinstance(tag[element], unicode): tag[element] = tag[element].encode('utf8') # Formatting Tags were also known as display tags. - Settings().setValue(u'displayTags/html_tags', cPickle.dumps(tags) if tags else u'') + Settings().setValue(u'formattingTags/html_tags', json.dumps(tags) if tags else u'') @staticmethod def load_tags(): @@ -156,13 +156,10 @@ class FormattingTags(object): u'end html': u'', u'protected': True, u'temporary': False}) FormattingTags.add_html_tags(base_tags) FormattingTags.add_html_tags(temporary_tags) - # Formatting Tags were also known as display tags. - user_expands = Settings().value(u'displayTags/html_tags') - # cPickle only accepts str not unicode strings - user_expands_string = str(user_expands) + user_expands_string = str(Settings().value(u'formattingTags/html_tags')) if user_expands_string: - user_tags = cPickle.loads(user_expands_string) + user_tags = json.loads(user_expands_string) for tag in user_tags: for element in tag: if isinstance(tag[element], str): diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index 412eddd1e..dc535a665 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -1,3 +1,4 @@ + # -*- coding: utf-8 -*- # vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index c3e1fa366..973d457bb 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -728,10 +728,14 @@ class MediaManagerItem(QtGui.QWidget): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index b4f851b24..a79ba850a 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -30,6 +30,7 @@ Provide the generic plugin functionality for OpenLP plugins. """ import logging +import os from PyQt4 import QtCore @@ -424,8 +425,11 @@ class Plugin(QtCore.QObject): """ Adds the openlp to the class dynamically """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/core/lib/registry.py b/openlp/core/lib/registry.py index 7e880f1f9..cee9e0329 100644 --- a/openlp/core/lib/registry.py +++ b/openlp/core/lib/registry.py @@ -103,9 +103,6 @@ class Registry(object): ``key`` The service to be deleted. """ - if self.running_under_test is False: - log.error(u'Invalid Method call for key %s' % key) - raise KeyError(u'Invalid Method call for key %s' % key) if key in self.service_list: del self.service_list[key] diff --git a/openlp/core/lib/settings.py b/openlp/core/lib/settings.py index 5e73ffc1d..a20e3e1a8 100644 --- a/openlp/core/lib/settings.py +++ b/openlp/core/lib/settings.py @@ -115,7 +115,7 @@ class Settings(QtCore.QSettings): u'advanced/single click preview': False, u'advanced/x11 bypass wm': X11_BYPASS_DEFAULT, u'crashreport/last directory': u'', - u'displayTags/html_tags': u'', + u'formattingTags/html_tags': u'', u'core/audio repeat list': False, u'core/auto open': False, u'core/auto preview': False, diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 0f3f3cc18..f06b02a9a 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -484,10 +484,14 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 7069cb9b7..eab89cb7d 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -38,6 +38,7 @@ Some of the code for this form is based on the examples at: from __future__ import division import cgi import logging +import os import sys from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL @@ -494,11 +495,15 @@ class MainDisplay(Display): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 4607c441f..c14a50d69 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -1064,6 +1064,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): if self.live_controller.display: self.live_controller.display.close() self.live_controller.display = None + if os.name == u'nt': + # Needed for Windows to stop crashes on exit + Registry().remove(u'application') def service_changed(self, reset=False, serviceName=None): """ @@ -1374,10 +1377,14 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/core/ui/media/mediaplayer.py b/openlp/core/ui/media/mediaplayer.py index c1f060f60..5d9e3663f 100644 --- a/openlp/core/ui/media/mediaplayer.py +++ b/openlp/core/ui/media/mediaplayer.py @@ -29,6 +29,8 @@ """ The :mod:`~openlp.core.ui.media.mediaplayer` module contains the MediaPlayer class. """ +import os + from openlp.core.lib import Registry from openlp.core.ui.media import MediaState @@ -153,10 +155,14 @@ class MediaPlayer(object): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) \ No newline at end of file diff --git a/openlp/core/ui/pluginform.py b/openlp/core/ui/pluginform.py index dd497bd68..4f4824fb7 100644 --- a/openlp/core/ui/pluginform.py +++ b/openlp/core/ui/pluginform.py @@ -30,6 +30,7 @@ The actual plugin view form """ import logging +import os from PyQt4 import QtGui @@ -166,10 +167,14 @@ class PluginForm(QtGui.QDialog, Ui_PluginViewDialog): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 444edc814..9ef1269ba 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -1588,10 +1588,14 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index be0e3bfa1..58f29cab6 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -836,10 +836,14 @@ class ThemeManager(QtGui.QWidget): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/core/ui/wizard.py b/openlp/core/ui/wizard.py index 0b142b459..ca89808ff 100644 --- a/openlp/core/ui/wizard.py +++ b/openlp/core/ui/wizard.py @@ -320,10 +320,14 @@ class OpenLPWizard(QtGui.QWizard): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/plugins/bibles/forms/editbibleform.py b/openlp/plugins/bibles/forms/editbibleform.py index b05fb68fb..4e0a5a7c0 100644 --- a/openlp/plugins/bibles/forms/editbibleform.py +++ b/openlp/plugins/bibles/forms/editbibleform.py @@ -28,6 +28,7 @@ ############################################################################### import logging +import os import re from PyQt4 import QtGui @@ -191,10 +192,14 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 837dbec38..69ec72ee5 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -544,11 +544,15 @@ class BibleDB(QtCore.QObject, Manager): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index efab9106b..de48b2617 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -29,6 +29,7 @@ """ The :mod:`http` module enables OpenLP to retrieve scripture from bible websites. """ +import os import logging import re import socket @@ -301,11 +302,15 @@ class BGExtract(object): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) @@ -362,8 +367,8 @@ class BSExtract(object): The version of the Bible like NIV for New International Version """ log.debug(u'BSExtract.get_books_from_http("%s")', version) - urlversion = urllib.quote(version.encode("utf-8")) - chapter_url = u'http://m.bibleserver.com/overlay/selectBook?translation=%s' % (urlversion) + url_version = urllib.quote(version.encode("utf-8")) + chapter_url = u'http://m.bibleserver.com/overlay/selectBook?translation=%s' % (url_version) soup = get_soup_for_bible_ref(chapter_url) if not soup: return None @@ -377,11 +382,15 @@ class BSExtract(object): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) @@ -477,11 +486,15 @@ class CWExtract(object): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) @@ -598,9 +611,8 @@ class HTTPBible(BibleDB): if show_error: critical_error_message_box( translate('BiblesPlugin', 'No Book Found'), - translate('BiblesPlugin', 'No matching ' - 'book could be found in this Bible. Check that you ' - 'have spelled the name of the book correctly.')) + translate('BiblesPlugin', 'No matching book could be found in this Bible. Check that you have ' + 'spelled the name of the book correctly.')) return [] book = db_book.name if BibleDB.get_verse_count(self, book_id, reference[1]) == 0: @@ -667,14 +679,19 @@ class HTTPBible(BibleDB): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) + def get_soup_for_bible_ref(reference_url, header=None, pre_parse_regex=None, pre_parse_substitute=None): """ Gets a webpage and returns a parsed and optionally cleaned soup or None. @@ -724,13 +741,10 @@ def send_error_message(error_type): if error_type == u'download': critical_error_message_box( translate('BiblesPlugin.HTTPBible', 'Download Error'), - translate('BiblesPlugin.HTTPBible', 'There was a ' - 'problem downloading your verse selection. Please check your ' - 'Internet connection, and if this error continues to occur ' - 'please consider reporting a bug.')) + translate('BiblesPlugin.HTTPBible', 'There was a problem downloading your verse selection. Please check ' + 'your Internet connection, and if this error continues to occur please consider reporting a bug.')) elif error_type == u'parse': critical_error_message_box( translate('BiblesPlugin.HTTPBible', 'Parse Error'), - translate('BiblesPlugin.HTTPBible', 'There was a ' - 'problem extracting your verse selection. If this error continues ' - 'to occur please consider reporting a bug.')) + translate('BiblesPlugin.HTTPBible', 'There was a problem extracting your verse selection. If this error ' + 'continues to occur please consider reporting a bug.')) diff --git a/openlp/plugins/songs/forms/duplicatesongremovalform.py b/openlp/plugins/songs/forms/duplicatesongremovalform.py index d612a5627..4427bbb31 100644 --- a/openlp/plugins/songs/forms/duplicatesongremovalform.py +++ b/openlp/plugins/songs/forms/duplicatesongremovalform.py @@ -349,10 +349,14 @@ class DuplicateSongRemovalForm(OpenLPWizard): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) \ No newline at end of file diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 9f003b2a0..2eb895a9a 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -27,6 +27,7 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### import logging +import os from PyQt4 import QtGui, QtCore from sqlalchemy.sql import and_ @@ -525,10 +526,14 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): def _get_application(self): """ - Adds the application to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/openlp/plugins/songs/lib/openlyricsexport.py b/openlp/plugins/songs/lib/openlyricsexport.py index f9ac6ebb3..35a9a29ec 100644 --- a/openlp/plugins/songs/lib/openlyricsexport.py +++ b/openlp/plugins/songs/lib/openlyricsexport.py @@ -84,10 +84,14 @@ class OpenLyricsExport(object): def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the openlp to the class dynamically. + Windows needs to access the application in a dynamic manner. """ - if not hasattr(self, u'_application'): - self._application = Registry().get(u'application') - return self._application + if os.name == u'nt': + return Registry().get(u'application') + else: + if not hasattr(self, u'_application'): + self._application = Registry().get(u'application') + return self._application application = property(_get_application) diff --git a/tests/functional/openlp_core_lib/test_formattingtags.py b/tests/functional/openlp_core_lib/test_formattingtags.py index 26d87f466..326dde5c8 100644 --- a/tests/functional/openlp_core_lib/test_formattingtags.py +++ b/tests/functional/openlp_core_lib/test_formattingtags.py @@ -33,11 +33,11 @@ class TestFormattingTags(TestCase): """ with patch(u'openlp.core.lib.translate') as mocked_translate, \ patch(u'openlp.core.lib.settings') as mocked_settings, \ - patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: + patch(u'openlp.core.lib.formattingtags.json') as mocked_json: # GIVEN: Our mocked modules and functions. mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate mocked_settings.value.return_value = u'' - mocked_cPickle.load.return_value = [] + mocked_json.load.return_value = [] # WHEN: Get the display tags. FormattingTags.load_tags() @@ -54,11 +54,11 @@ class TestFormattingTags(TestCase): """ with patch(u'openlp.core.lib.translate') as mocked_translate, \ patch(u'openlp.core.lib.settings') as mocked_settings, \ - patch(u'openlp.core.lib.formattingtags.cPickle') as mocked_cPickle: + patch(u'openlp.core.lib.formattingtags.json') as mocked_json: # GIVEN: Our mocked modules and functions. mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate mocked_settings.value.return_value = u'' - mocked_cPickle.loads.side_effect = [[], [TAG]] + mocked_json.loads.side_effect = [[], [TAG]] # WHEN: Get the display tags. FormattingTags.load_tags()