Fix up registry for Application exit. Remove FormattingTags pickle , Other minor cleanups

bzr-revno: 2264
This commit is contained in:
Tim Bentley 2013-06-30 20:18:21 +01:00
commit 988fca86a1
21 changed files with 180 additions and 102 deletions

View File

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

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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.'))

View File

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

View File

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

View File

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

View File

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