From 43fef6cc2bfafb7ce53c34b90bd03d2c5b30b5ba Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Fri, 2 Aug 2013 22:51:39 +0100 Subject: [PATCH 01/46] fixed 1184869 by checking that the anchor tag actually has some text --- openlp/plugins/bibles/lib/http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index de48b2617..cb410dbaa 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -378,7 +378,7 @@ class BSExtract(object): send_error_message(u'parse') return None content = content.find_all(u'li') - return [book.contents[0].contents[0] for book in content] + return [book.contents[0].contents[0] for book in content if len(book.contents[0].contents)] def _get_application(self): """ From 364fde73c54926ef67c02ee813c5c08ac854d402 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 13 Aug 2013 19:02:04 +0100 Subject: [PATCH 02/46] Fix #120515 by reimplementing QFileDialog.getOpenFileNames --- openlp/core/lib/__init__.py | 1 + openlp/core/lib/filedialog.py | 66 +++++++++++++++++ openlp/core/lib/mediamanageritem.py | 4 +- openlp/core/lib/uistrings.py | 2 + openlp/core/ui/thememanager.py | 7 +- openlp/plugins/songs/forms/editsongform.py | 6 +- openlp/plugins/songs/forms/songimportform.py | 4 +- .../openlp_core_lib/test_file_dialog.py | 71 +++++++++++++++++++ 8 files changed, 151 insertions(+), 10 deletions(-) create mode 100644 openlp/core/lib/filedialog.py create mode 100644 tests/functional/openlp_core_lib/test_file_dialog.py diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index d6c338271..61891c1ef 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -377,6 +377,7 @@ def create_separated_list(stringlist): from registry import Registry from uistrings import UiStrings +from filedialog import FileDialog from screen import ScreenList from settings import Settings from listwidgetwithdnd import ListWidgetWithDnD diff --git a/openlp/core/lib/filedialog.py b/openlp/core/lib/filedialog.py new file mode 100644 index 000000000..b2159b511 --- /dev/null +++ b/openlp/core/lib/filedialog.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### + +""" +Provide a work around for a bug in QFileDialog (#1209515) +""" +import logging +import os +import urllib + +from PyQt4 import QtGui + +from openlp.core.lib import UiStrings + +log = logging.getLogger(__name__) + +class FileDialog(QtGui.QFileDialog): + """ + Inherit form QFileDialog + """ + @staticmethod + def getOpenFileNames(parent, *args, **kwargs): + """ + Reimplement getOpenFileNames to fix the way it returns some file names that url encoded when selecting multiple + files + """ + files = QtGui.QFileDialog.getOpenFileNames(parent, *args, **kwargs) + file_list = [] + for file in files: + file = unicode(file) + if not os.path.exists(file): + log.info(u'File %s not found. Attempting to unquote.') + file = urllib.unquote(unicode(file)) + if not os.path.exists(file): + log.error(u'File %s not found.' % file) + QtGui.QMessageBox.information(parent, UiStrings().FNFT, UiStrings().FNF % file) + continue + log.info(u'File %s found.') + file_list.append(file) + return file_list \ No newline at end of file diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 973d457bb..1aa622b1e 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -35,7 +35,7 @@ import re from PyQt4 import QtCore, QtGui -from openlp.core.lib import OpenLPToolbar, ServiceItem, StringContent, ListWidgetWithDnD, \ +from openlp.core.lib import FileDialog, OpenLPToolbar, ServiceItem, StringContent, ListWidgetWithDnD, \ ServiceItemContext, Settings, Registry, UiStrings, translate from openlp.core.lib.searchedit import SearchEdit from openlp.core.lib.ui import create_widget_action, critical_error_message_box @@ -305,7 +305,7 @@ class MediaManagerItem(QtGui.QWidget): """ Add a file to the list widget to make it available for showing """ - files = QtGui.QFileDialog.getOpenFileNames(self, self.on_new_prompt, + files = FileDialog().getOpenFileNames(self, self.on_new_prompt, Settings().value(self.settings_section + u'/last directory'), self.on_new_file_masks) log.info(u'New files(s) %s', files) if files: diff --git a/openlp/core/lib/uistrings.py b/openlp/core/lib/uistrings.py index 6d4b4d250..26ad63b55 100644 --- a/openlp/core/lib/uistrings.py +++ b/openlp/core/lib/uistrings.py @@ -83,6 +83,8 @@ class UiStrings(object): self.Error = translate('OpenLP.Ui', 'Error') self.Export = translate('OpenLP.Ui', 'Export') self.File = translate('OpenLP.Ui', 'File') + self.FNFT = unicode(translate('OpenLP.Ui', 'File Not Found')) + self.FNF = unicode(translate('OpenLP.Ui', 'File %s not found.\nPlease try selecting it individually.')) self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font pointsize unit') self.Help = translate('OpenLP.Ui', 'Help') self.Hours = translate('OpenLP.Ui', 'h', 'The abbreviated unit for hours') diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 58f29cab6..a1f761d8f 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -38,8 +38,9 @@ import re from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui -from openlp.core.lib import ImageSource, OpenLPToolbar, Registry, Settings, UiStrings, get_text_file_string, \ - build_icon, translate, check_item_selected, check_directory_exists, create_thumb, validate_thumb +from openlp.core.lib import FileDialog, ImageSource, OpenLPToolbar, Registry, Settings, UiStrings, \ + get_text_file_string, build_icon, translate, check_item_selected, check_directory_exists, create_thumb, \ + validate_thumb from openlp.core.lib.theme import ThemeXML, BackgroundType, VerticalType, BackgroundGradientType from openlp.core.lib.ui import critical_error_message_box, create_widget_action from openlp.core.theme import Theme @@ -373,7 +374,7 @@ class ThemeManager(QtGui.QWidget): Opens a file dialog to select the theme file(s) to import before attempting to extract OpenLP themes from those files. This process will load both OpenLP version 1 and version 2 themes. """ - files = QtGui.QFileDialog.getOpenFileNames(self, + files = FileDialog().getOpenFileNames(self, translate('OpenLP.ThemeManager', 'Select Theme Import File'), Settings().value(self.settings_section + u'/last directory import'), translate('OpenLP.ThemeManager', 'OpenLP Themes (*.theme *.otz)')) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 24d0d3024..f73a4468c 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -38,8 +38,8 @@ import shutil from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, PluginStatus, MediaType, UiStrings, translate, create_separated_list, \ - check_directory_exists +from openlp.core.lib import FileDialog, Registry, PluginStatus, MediaType, UiStrings, translate, \ + create_separated_list, check_directory_exists from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box from openlp.core.utils import AppLocation from openlp.plugins.songs.lib import VerseType, clean_song @@ -753,7 +753,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): Loads file(s) from the filesystem. """ filters = u'%s (*)' % UiStrings().AllFiles - filenames = QtGui.QFileDialog.getOpenFileNames(self, + filenames = FileDialog().getOpenFileNames(self, translate('SongsPlugin.EditSongForm', 'Open File(s)'), u'', filters) for filename in filenames: item = QtGui.QListWidgetItem(os.path.split(unicode(filename))[1]) diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index c1aca92ad..bd9acc943 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -35,7 +35,7 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, Settings, UiStrings, translate +from openlp.core.lib import FileDialog, Registry, Settings, UiStrings, translate from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings from openlp.plugins.songs.lib.importer import SongFormat, SongFormatSelect @@ -244,7 +244,7 @@ class SongImportForm(OpenLPWizard): if filters: filters += u';;' filters += u'%s (*)' % UiStrings().AllFiles - filenames = QtGui.QFileDialog.getOpenFileNames(self, title, + filenames = FileDialog().getOpenFileNames(self, title, Settings().value(self.plugin.settings_section + u'/last directory import'), filters) if filenames: listbox.addItems(filenames) diff --git a/tests/functional/openlp_core_lib/test_file_dialog.py b/tests/functional/openlp_core_lib/test_file_dialog.py new file mode 100644 index 000000000..dc704eaef --- /dev/null +++ b/tests/functional/openlp_core_lib/test_file_dialog.py @@ -0,0 +1,71 @@ +""" +Package to test the openlp.core.lib.formattingtags package. +""" +import copy +from unittest import TestCase +from mock import MagicMock, call, patch + +from openlp.core.lib.filedialog import FileDialog +from openlp.core.lib.uistrings import UiStrings + +class TestFileDialog(TestCase): + """ + Test the functions in the :mod:`filedialog` module. + """ + def setUp(self): + self.os_patcher = patch(u'openlp.core.lib.filedialog.os') + self.qt_gui_patcher = patch(u'openlp.core.lib.filedialog.QtGui') + self.ui_strings_patcher = patch(u'openlp.core.lib.filedialog.UiStrings') + self.mocked_os = self.os_patcher.start() + self.mocked_qt_gui = self.qt_gui_patcher.start() + self.mocked_ui_strings = self.ui_strings_patcher.start() + self.mocked_parent = MagicMock() + + def tearDown(self): + self.os_patcher.stop() + self.qt_gui_patcher.stop() + self.ui_strings_patcher.stop() + + def get_open_file_names_canceled_test(self): + """ + Test that FileDialog.getOpenFileNames() returns and empty QStringList when QFileDialog is canceled + (returns an empty QStringList) + """ + self.mocked_os.reset() + + # GIVEN: An empty QStringList as a return value from QFileDialog.getOpenFileNames + self.mocked_qt_gui.QFileDialog.getOpenFileNames.return_value = [] + + # WHEN: FileDialog.getOpenFileNames is called + result = FileDialog.getOpenFileNames(self.mocked_parent) + + # THEN: The returned value should be an empty QStiingList and os.path.exists should not have been called + assert not self.mocked_os.path.exists.called + self.assertEqual(result, [], + u'FileDialog.getOpenFileNames should return and empty list when QFileDialog.getOpenFileNames is canceled') + + def returned_file_list_test(self): + """ + Test that FileDialog.getOpenFileNames handles a list of files properly when QFileList.getOpenFileNames + returns a good file name, a urlencoded file name and a non-existing file + """ + self.mocked_os.rest() + self.mocked_qt_gui.reset() + + # GIVEN: A List of known values as a return value from QFileDialog.getOpenFileNamesand a list of valid + # file names. + self.mocked_qt_gui.QFileDialog.getOpenFileNames.return_value = [ + u'/Valid File', u'/url%20encoded%20file%20%231', u'/non-existing'] + self.mocked_os.path.exists.side_effect = lambda file_name: file_name in [ + u'/Valid File', u'/url encoded file #1'] + + # WHEN: FileDialog.getOpenFileNames is called + result = FileDialog.getOpenFileNames(self.mocked_parent) + + # THEN: os.path.exists should have been called with known args. QmessageBox.information should have been + # called. The returned result should corrilate with the input. + self.mocked_os.path.exists.assert_has_calls([call(u'/Valid File'), call(u'/url%20encoded%20file%20%231'), + call(u'/url encoded file #1'), call(u'/non-existing'), call(u'/non-existing')]) + self.mocked_qt_gui.QmessageBox.information.called_with(self.mocked_parent, UiStrings().FNFT, + UiStrings().FNF % u'/non-existing') + self.assertEqual(result, [u'/Valid File', u'/url encoded file #1'], u'The returned file list is incorrect') \ No newline at end of file From 2ceb165901ff9c7e6cc50eced7fa76f56ff8f215 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Thu, 22 Aug 2013 05:33:19 +0000 Subject: [PATCH 03/46] change string names --- openlp/core/lib/filedialog.py | 7 ++++--- openlp/core/lib/uistrings.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/openlp/core/lib/filedialog.py b/openlp/core/lib/filedialog.py index b2159b511..ea2eba045 100644 --- a/openlp/core/lib/filedialog.py +++ b/openlp/core/lib/filedialog.py @@ -28,7 +28,7 @@ ############################################################################### """ -Provide a work around for a bug in QFileDialog (#1209515) +Provide a work around for a bug in QFileDialog """ import logging import os @@ -42,7 +42,7 @@ log = logging.getLogger(__name__) class FileDialog(QtGui.QFileDialog): """ - Inherit form QFileDialog + Subclass QFileDialog to work round a bug """ @staticmethod def getOpenFileNames(parent, *args, **kwargs): @@ -59,7 +59,8 @@ class FileDialog(QtGui.QFileDialog): file = urllib.unquote(unicode(file)) if not os.path.exists(file): log.error(u'File %s not found.' % file) - QtGui.QMessageBox.information(parent, UiStrings().FNFT, UiStrings().FNF % file) + QtGui.QMessageBox.information(parent, UiStrings().FileNotFound, + UiStrings().FileNotFoundMessage % file) continue log.info(u'File %s found.') file_list.append(file) diff --git a/openlp/core/lib/uistrings.py b/openlp/core/lib/uistrings.py index 26ad63b55..faab77a49 100644 --- a/openlp/core/lib/uistrings.py +++ b/openlp/core/lib/uistrings.py @@ -83,8 +83,8 @@ class UiStrings(object): self.Error = translate('OpenLP.Ui', 'Error') self.Export = translate('OpenLP.Ui', 'Export') self.File = translate('OpenLP.Ui', 'File') - self.FNFT = unicode(translate('OpenLP.Ui', 'File Not Found')) - self.FNF = unicode(translate('OpenLP.Ui', 'File %s not found.\nPlease try selecting it individually.')) + self.FileNotFound = unicode(translate('OpenLP.Ui', 'File Not Found')) + self.FileNotFoundMessage = unicode(translate('OpenLP.Ui', 'File %s not found.\nPlease try selecting it individually.')) self.FontSizePtUnit = translate('OpenLP.Ui', 'pt', 'Abbreviated font pointsize unit') self.Help = translate('OpenLP.Ui', 'Help') self.Hours = translate('OpenLP.Ui', 'h', 'The abbreviated unit for hours') From 49c9663dcfb0b49c744da3141916ca6568fbd4b0 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Thu, 22 Aug 2013 20:20:02 +0000 Subject: [PATCH 04/46] renamed var, removed some uneeded ()'s --- openlp/core/lib/mediamanageritem.py | 2 +- openlp/core/ui/thememanager.py | 2 +- openlp/plugins/songs/forms/editsongform.py | 2 +- openlp/plugins/songs/forms/songimportform.py | 2 +- tests/functional/openlp_core_lib/test_file_dialog.py | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 1aa622b1e..018c6801f 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -305,7 +305,7 @@ class MediaManagerItem(QtGui.QWidget): """ Add a file to the list widget to make it available for showing """ - files = FileDialog().getOpenFileNames(self, self.on_new_prompt, + files = FileDialog.getOpenFileNames(self, self.on_new_prompt, Settings().value(self.settings_section + u'/last directory'), self.on_new_file_masks) log.info(u'New files(s) %s', files) if files: diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index a1f761d8f..1f64acbf7 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -374,7 +374,7 @@ class ThemeManager(QtGui.QWidget): Opens a file dialog to select the theme file(s) to import before attempting to extract OpenLP themes from those files. This process will load both OpenLP version 1 and version 2 themes. """ - files = FileDialog().getOpenFileNames(self, + files = FileDialog.getOpenFileNames(self, translate('OpenLP.ThemeManager', 'Select Theme Import File'), Settings().value(self.settings_section + u'/last directory import'), translate('OpenLP.ThemeManager', 'OpenLP Themes (*.theme *.otz)')) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index f73a4468c..153a96e14 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -753,7 +753,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): Loads file(s) from the filesystem. """ filters = u'%s (*)' % UiStrings().AllFiles - filenames = FileDialog().getOpenFileNames(self, + filenames = FileDialog.getOpenFileNames(self, translate('SongsPlugin.EditSongForm', 'Open File(s)'), u'', filters) for filename in filenames: item = QtGui.QListWidgetItem(os.path.split(unicode(filename))[1]) diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index bd9acc943..d0378cd45 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -244,7 +244,7 @@ class SongImportForm(OpenLPWizard): if filters: filters += u';;' filters += u'%s (*)' % UiStrings().AllFiles - filenames = FileDialog().getOpenFileNames(self, title, + filenames = FileDialog.getOpenFileNames(self, title, Settings().value(self.plugin.settings_section + u'/last directory import'), filters) if filenames: listbox.addItems(filenames) diff --git a/tests/functional/openlp_core_lib/test_file_dialog.py b/tests/functional/openlp_core_lib/test_file_dialog.py index dc704eaef..b895cc67d 100644 --- a/tests/functional/openlp_core_lib/test_file_dialog.py +++ b/tests/functional/openlp_core_lib/test_file_dialog.py @@ -66,6 +66,6 @@ class TestFileDialog(TestCase): # called. The returned result should corrilate with the input. self.mocked_os.path.exists.assert_has_calls([call(u'/Valid File'), call(u'/url%20encoded%20file%20%231'), call(u'/url encoded file #1'), call(u'/non-existing'), call(u'/non-existing')]) - self.mocked_qt_gui.QmessageBox.information.called_with(self.mocked_parent, UiStrings().FNFT, - UiStrings().FNF % u'/non-existing') + self.mocked_qt_gui.QmessageBox.information.called_with(self.mocked_parent, UiStrings().FileNotFound, + UiStrings().FileNotFoundMessage % u'/non-existing') self.assertEqual(result, [u'/Valid File', u'/url encoded file #1'], u'The returned file list is incorrect') \ No newline at end of file From bd6c2bea42fec17f1a7a39a3cfe09466c325ef62 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Thu, 29 Aug 2013 21:04:23 +0000 Subject: [PATCH 05/46] Added a helper class for song importers and modified the shongshowplus test to use it --- .../songs/songfileimporthelper.py | 113 ++++++++++++++++ .../songs/test_songshowplusimport.py | 123 +++--------------- .../songshowplussongs/Amazing Grace.json | 42 ++++++ .../Beautiful Garden Of Prayer.json | 35 +++++ 4 files changed, 205 insertions(+), 108 deletions(-) create mode 100644 tests/functional/openlp_plugins/songs/songfileimporthelper.py create mode 100644 tests/resources/songshowplussongs/Amazing Grace.json create mode 100644 tests/resources/songshowplussongs/Beautiful Garden Of Prayer.json diff --git a/tests/functional/openlp_plugins/songs/songfileimporthelper.py b/tests/functional/openlp_plugins/songs/songfileimporthelper.py new file mode 100644 index 000000000..91bcbea81 --- /dev/null +++ b/tests/functional/openlp_plugins/songs/songfileimporthelper.py @@ -0,0 +1,113 @@ +""" +The :mod:`songfileimporthelper` modules provides a helper class and methods to easily enable testing the import of +song files from third party applications. +""" +import json +from unittest import TestCase +from mock import patch, MagicMock + +class SongImportTestHelper(TestCase): + """ + This class is designed to be a helper class to reduce repition when testing the import of song files. + """ + def __init__(self, *args, **kwargs): + self.importer_module = __import__( + u'openlp.plugins.songs.lib.%s' % self.importer_module_name, fromlist=[self.importer_class_name]) + self.importer_class = getattr(self.importer_module, self.importer_class_name) + TestCase.__init__(self, *args, **kwargs) + + def setUp(self): + """ + Patch and set up the mocks required. + """ + self.add_copyright_patcher = patch( + u'openlp.plugins.songs.lib.%s.%s.addCopyright' % (self.importer_module_name, self.importer_class_name)) + self.add_verse_patcher = patch( + u'openlp.plugins.songs.lib.%s.%s.addVerse' % (self.importer_module_name, self.importer_class_name)) + self.finish_patcher = patch( + u'openlp.plugins.songs.lib.%s.%s.finish' % (self.importer_module_name, self.importer_class_name)) + self.parse_author_patcher = patch( + u'openlp.plugins.songs.lib.%s.%s.parse_author' % (self.importer_module_name, self.importer_class_name)) + self.song_import_patcher = patch(u'openlp.plugins.songs.lib.%s.SongImport' % self.importer_module_name) + self.mocked_add_copyright = self.add_copyright_patcher.start() + self.mocked_add_verse = self.add_verse_patcher.start() + self.mocked_finish = self.finish_patcher.start() + self.mocked_parse_author = self.parse_author_patcher.start() + self.mocked_song_importer = self.song_import_patcher.start() + self.mocked_manager = MagicMock() + self.mocked_import_wizard = MagicMock() + self.mocked_finish.return_value = True + + def tearDown(self): + """ + Clean up + """ + self.add_copyright_patcher.stop() + self.add_verse_patcher.stop() + self.finish_patcher.stop() + self.parse_author_patcher.stop() + self.song_import_patcher.stop() + + def load_external_result_data(self, file_name): + """ + A method to load and return an object containing the song data from an external file. + """ + result_file = open(file_name, 'rb') + return json.loads(result_file.read()) + + def file_import(self, source_file_name, result_data): + """ + Import the given file and check that it has imported correctly + """ + importer = self.importer_class(self.mocked_manager) + importer.import_wizard = self.mocked_import_wizard + importer.stop_import_flag = False + importer.topics = [] + + # WHEN: Importing the source file + importer.import_source = [source_file_name] + add_verse_calls = self.get_data(result_data, u'verses') + author_calls = self.get_data(result_data, u'authors') + ccli_number = self.get_data(result_data, u'ccli_number') + comments = self.get_data(result_data, u'comments') + song_book_name = self.get_data(result_data, u'song_book_name') + song_copyright = self.get_data(result_data, u'copyright') + song_number = self.get_data(result_data, u'song_number') + title = self.get_data(result_data, u'title') + topics = self.get_data(result_data, u'topics') + verse_order_list = self.get_data(result_data, u'verse_order_list') + + # THEN: doImport should return none, the song data should be as expected, and finish should have been + # called. + self.assertIsNone(importer.doImport(), u'doImport should return None when it has completed') + self.assertEquals(importer.title, title, u'title for %s should be "%s"' % (source_file_name, title)) + for author in author_calls: + self.mocked_parse_author.assert_any_call(author) + if song_copyright: + self.mocked_add_copyright.assert_called_with(song_copyright) + if ccli_number: + self.assertEquals(importer.ccliNumber, ccli_number, u'ccliNumber for %s should be %s' + % (source_file_name, ccli_number)) + for verse_text, verse_tag in add_verse_calls: + self.mocked_add_verse.assert_any_call(verse_text, verse_tag) + if topics: + self.assertEquals(importer.topics, topics, u'topics for %s should be %s' % (source_file_name, topics)) + if comments: + self.assertEquals(importer.comments, comments, u'comments for %s should be "%s"' + % (source_file_name, comments)) + if song_book_name: + self.assertEquals(importer.songBookName, song_book_name, u'songBookName for %s should be "%s"' + % (source_file_name, song_book_name)) + if song_number: + self.assertEquals(importer.songNumber, song_number, u'songNumber for %s should be %s' + % (source_file_name, song_number)) + if verse_order_list: + self.assertEquals(importer.verseOrderList, [], u'verseOrderList for %s should be %s' + % (source_file_name, verse_order_list)) + self.mocked_finish.assert_called_with() + + def get_data(self, data, key): + if key in data: + return data[key] + return u'' + diff --git a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py index 86d77bbdc..2bde3018f 100644 --- a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py @@ -6,50 +6,24 @@ import os from unittest import TestCase from mock import patch, MagicMock +from tests.functional.openlp_plugins.songs.songfileimporthelper import SongImportTestHelper from openlp.plugins.songs.lib import VerseType from openlp.plugins.songs.lib.songshowplusimport import SongShowPlusImport -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'../../../resources/songshowplussongs')) -SONG_TEST_DATA = {u'Amazing Grace.sbsong': - {u'title': u'Amazing Grace (Demonstration)', - u'authors': [u'John Newton', u'Edwin Excell', u'John P. Rees'], - u'copyright': u'Public Domain ', - u'ccli_number': 22025, - u'verses': - [(u'Amazing grace! How sweet the sound!\r\nThat saved a wretch like me!\r\n' - u'I once was lost, but now am found;\r\nWas blind, but now I see.', u'v1'), - (u'\'Twas grace that taught my heart to fear,\r\nAnd grace my fears relieved.\r\n' - u'How precious did that grace appear,\r\nThe hour I first believed.', u'v2'), - (u'The Lord has promised good to me,\r\nHis Word my hope secures.\r\n' - u'He will my shield and portion be\r\nAs long as life endures.', u'v3'), - (u'Thro\' many dangers, toils and snares\r\nI have already come.\r\n' - u'\'Tis grace that brought me safe thus far,\r\nAnd grace will lead me home.', u'v4'), - (u'When we\'ve been there ten thousand years,\r\nBright shining as the sun,\r\n' - u'We\'ve no less days to sing God\'s praise,\r\nThan when we first begun.', u'v5')], - u'topics': [u'Assurance', u'Grace', u'Praise', u'Salvation'], - u'comments': u'\n\n\n', - u'song_book_name': u'Demonstration Songs', - u'song_number': 0, - u'verse_order_list': []}, - u'Beautiful Garden Of Prayer.sbsong': - {u'title': u'Beautiful Garden Of Prayer (Demonstration)', - u'authors': [u'Eleanor Allen Schroll', u'James H. Fillmore'], - u'copyright': u'Public Domain ', - u'ccli_number': 60252, - u'verses': - [(u'There\'s a garden where Jesus is waiting,\r\nThere\'s a place that is wondrously fair.\r\n' - u'For it glows with the light of His presence,\r\n\'Tis the beautiful garden of prayer.', u'v1'), - (u'There\'s a garden where Jesus is waiting,\r\nAnd I go with my burden and care.\r\n' - u'Just to learn from His lips, words of comfort,\r\nIn the beautiful garden of prayer.', u'v2'), - (u'There\'s a garden where Jesus is waiting,\r\nAnd He bids you to come meet Him there,\r\n' - u'Just to bow and receive a new blessing,\r\nIn the beautiful garden of prayer.', u'v3'), - (u'O the beautiful garden, the garden of prayer,\r\nO the beautiful garden of prayer.\r\n' - u'There my Savior awaits, and He opens the gates\r\nTo the beautiful garden of prayer.', u'c1')], - u'topics': [u'Devotion', u'Prayer'], - u'comments': u'', - u'song_book_name': u'', - u'song_number': 0, - u'verse_order_list': []}} +TEST_PATH = os.path.abspath( + os.path.join(os.path.dirname(__file__), u'..', u'..', u'..', u'resources', u'songshowplussongs')) + +class TestSongShowPlusFileImport(SongImportTestHelper): + def __init__(self, *args, **kwargs): + self.importer_class_name = u'SongShowPlusImport' + self.importer_module_name = u'songshowplusimport' + SongImportTestHelper.__init__(self, *args, **kwargs) + + def test_song_import(self): + test_import = self.file_import(os.path.join(TEST_PATH, u'Amazing Grace.sbsong'), + self.load_external_result_data(os.path.join(TEST_PATH, u'Amazing Grace.json'))) + test_import = self.file_import(os.path.join(TEST_PATH, u'Beautiful Garden Of Prayer.sbsong'), + self.load_external_result_data(os.path.join(TEST_PATH, u'Beautiful Garden Of Prayer.json'))) class TestSongShowPlusImport(TestCase): @@ -166,70 +140,3 @@ class TestSongShowPlusImport(TestCase): self.assertEquals(importer.to_openlp_verse_tag(original_tag, ignore_unique=True), openlp_tag, u'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' % (openlp_tag, original_tag)) - - def file_import_test(self): - """ - Test the actual import of real song files and check that the imported data is correct. - """ - - # GIVEN: Test files with a mocked out SongImport class, a mocked out "manager", a mocked out "import_wizard", - # and mocked out "author", "add_copyright", "add_verse", "finish" methods. - with patch(u'openlp.plugins.songs.lib.songshowplusimport.SongImport'): - for song_file in SONG_TEST_DATA: - mocked_manager = MagicMock() - mocked_import_wizard = MagicMock() - mocked_parse_author = MagicMock() - mocked_add_copyright = MagicMock() - mocked_add_verse = MagicMock() - mocked_finish = MagicMock() - mocked_finish.return_value = True - importer = SongShowPlusImport(mocked_manager) - importer.import_wizard = mocked_import_wizard - importer.stop_import_flag = False - importer.parse_author = mocked_parse_author - importer.addCopyright = mocked_add_copyright - importer.addVerse = mocked_add_verse - importer.finish = mocked_finish - importer.topics = [] - - # WHEN: Importing each file - importer.import_source = [os.path.join(TEST_PATH, song_file)] - title = SONG_TEST_DATA[song_file][u'title'] - author_calls = SONG_TEST_DATA[song_file][u'authors'] - song_copyright = SONG_TEST_DATA[song_file][u'copyright'] - ccli_number = SONG_TEST_DATA[song_file][u'ccli_number'] - add_verse_calls = SONG_TEST_DATA[song_file][u'verses'] - topics = SONG_TEST_DATA[song_file][u'topics'] - comments = SONG_TEST_DATA[song_file][u'comments'] - song_book_name = SONG_TEST_DATA[song_file][u'song_book_name'] - song_number = SONG_TEST_DATA[song_file][u'song_number'] - verse_order_list = SONG_TEST_DATA[song_file][u'verse_order_list'] - - # THEN: doImport should return none, the song data should be as expected, and finish should have been - # called. - self.assertIsNone(importer.doImport(), u'doImport should return None when it has completed') - self.assertEquals(importer.title, title, u'title for %s should be "%s"' % (song_file, title)) - for author in author_calls: - mocked_parse_author.assert_any_call(author) - if song_copyright: - mocked_add_copyright.assert_called_with(song_copyright) - if ccli_number: - self.assertEquals(importer.ccliNumber, ccli_number, u'ccliNumber for %s should be %s' - % (song_file, ccli_number)) - for verse_text, verse_tag in add_verse_calls: - mocked_add_verse.assert_any_call(verse_text, verse_tag) - if topics: - self.assertEquals(importer.topics, topics, u'topics for %s should be %s' % (song_file, topics)) - if comments: - self.assertEquals(importer.comments, comments, u'comments for %s should be "%s"' - % (song_file, comments)) - if song_book_name: - self.assertEquals(importer.songBookName, song_book_name, u'songBookName for %s should be "%s"' - % (song_file, song_book_name)) - if song_number: - self.assertEquals(importer.songNumber, song_number, u'songNumber for %s should be %s' - % (song_file, song_number)) - if verse_order_list: - self.assertEquals(importer.verseOrderList, [], u'verseOrderList for %s should be %s' - % (song_file, verse_order_list)) - mocked_finish.assert_called_with() diff --git a/tests/resources/songshowplussongs/Amazing Grace.json b/tests/resources/songshowplussongs/Amazing Grace.json new file mode 100644 index 000000000..878132881 --- /dev/null +++ b/tests/resources/songshowplussongs/Amazing Grace.json @@ -0,0 +1,42 @@ +{ + "authors": [ + "John Newton", + "Edwin Excell", + "John P. Rees" + ], + "ccli_number": 22025, + "comments": "\n\n\n", + "copyright": "Public Domain ", + "song_book_name": "Demonstration Songs", + "song_number": 0, + "title": "Amazing Grace (Demonstration)", + "topics": [ + "Assurance", + "Grace", + "Praise", + "Salvation" + ], + "verse_order_list": [], + "verses": [ + [ + "Amazing grace! How sweet the sound!\r\nThat saved a wretch like me!\r\nI once was lost, but now am found;\r\nWas blind, but now I see.", + "v1" + ], + [ + "'Twas grace that taught my heart to fear,\r\nAnd grace my fears relieved.\r\nHow precious did that grace appear,\r\nThe hour I first believed.", + "v2" + ], + [ + "The Lord has promised good to me,\r\nHis Word my hope secures.\r\nHe will my shield and portion be\r\nAs long as life endures.", + "v3" + ], + [ + "Thro' many dangers, toils and snares\r\nI have already come.\r\n'Tis grace that brought me safe thus far,\r\nAnd grace will lead me home.", + "v4" + ], + [ + "When we've been there ten thousand years,\r\nBright shining as the sun,\r\nWe've no less days to sing God's praise,\r\nThan when we first begun.", + "v5" + ] + ] +} \ No newline at end of file diff --git a/tests/resources/songshowplussongs/Beautiful Garden Of Prayer.json b/tests/resources/songshowplussongs/Beautiful Garden Of Prayer.json new file mode 100644 index 000000000..651af9100 --- /dev/null +++ b/tests/resources/songshowplussongs/Beautiful Garden Of Prayer.json @@ -0,0 +1,35 @@ +{ + "authors": [ + "Eleanor Allen Schroll", + "James H. Fillmore" + ], + "ccli_number": 60252, + "comments": "", + "copyright": "Public Domain ", + "song_book_name": "", + "song_number": 0, + "title": "Beautiful Garden Of Prayer (Demonstration)", + "topics": [ + "Devotion", + "Prayer" + ], + "verse_order_list": [], + "verses": [ + [ + "There's a garden where Jesus is waiting,\r\nThere's a place that is wondrously fair.\r\nFor it glows with the light of His presence,\r\n'Tis the beautiful garden of prayer.", + "v1" + ], + [ + "There's a garden where Jesus is waiting,\r\nAnd I go with my burden and care.\r\nJust to learn from His lips, words of comfort,\r\nIn the beautiful garden of prayer.", + "v2" + ], + [ + "There's a garden where Jesus is waiting,\r\nAnd He bids you to come meet Him there,\r\nJust to bow and receive a new blessing,\r\nIn the beautiful garden of prayer.", + "v3" + ], + [ + "O the beautiful garden, the garden of prayer,\r\nO the beautiful garden of prayer.\r\nThere my Savior awaits, and He opens the gates\r\nTo the beautiful garden of prayer.", + "c1" + ] + ] +} \ No newline at end of file From dc9d3cd74eb2dfd0fd35e2d4488912d144fce931 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 7 Sep 2013 16:55:09 +0000 Subject: [PATCH 06/46] changed test_songshowplusimport.py to py3 --- .../songs/test_songshowplusimport.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py index 4dfe03645..5b5062823 100644 --- a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py @@ -11,19 +11,19 @@ from openlp.plugins.songs.lib import VerseType from openlp.plugins.songs.lib.songshowplusimport import SongShowPlusImport TEST_PATH = os.path.abspath( - os.path.join(os.path.dirname(__file__), u'..', u'..', u'..', u'resources', u'songshowplussongs')) + os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'songshowplussongs')) class TestSongShowPlusFileImport(SongImportTestHelper): def __init__(self, *args, **kwargs): - self.importer_class_name = u'SongShowPlusImport' - self.importer_module_name = u'songshowplusimport' + self.importer_class_name = 'SongShowPlusImport' + self.importer_module_name = 'songshowplusimport' SongImportTestHelper.__init__(self, *args, **kwargs) def test_song_import(self): - test_import = self.file_import(os.path.join(TEST_PATH, u'Amazing Grace.sbsong'), - self.load_external_result_data(os.path.join(TEST_PATH, u'Amazing Grace.json'))) - test_import = self.file_import(os.path.join(TEST_PATH, u'Beautiful Garden Of Prayer.sbsong'), - self.load_external_result_data(os.path.join(TEST_PATH, u'Beautiful Garden Of Prayer.json'))) + test_import = self.file_import(os.path.join(TEST_PATH, 'Amazing Grace.sbsong'), + self.load_external_result_data(os.path.join(TEST_PATH, 'Amazing Grace.json'))) + test_import = self.file_import(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.sbsong'), + self.load_external_result_data(os.path.join(TEST_PATH, 'Beautiful Garden Of Prayer.json'))) class TestSongShowPlusImport(TestCase): From bc30365e0ee48e0b026a7fdb8e3297bec9ba4e40 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 7 Sep 2013 17:02:28 +0000 Subject: [PATCH 07/46] Missed a py2 file --- .../songs/songfileimporthelper.py | 226 +++++++++--------- 1 file changed, 113 insertions(+), 113 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/songfileimporthelper.py b/tests/functional/openlp_plugins/songs/songfileimporthelper.py index 91bcbea81..d40f14154 100644 --- a/tests/functional/openlp_plugins/songs/songfileimporthelper.py +++ b/tests/functional/openlp_plugins/songs/songfileimporthelper.py @@ -1,113 +1,113 @@ -""" -The :mod:`songfileimporthelper` modules provides a helper class and methods to easily enable testing the import of -song files from third party applications. -""" -import json -from unittest import TestCase -from mock import patch, MagicMock - -class SongImportTestHelper(TestCase): - """ - This class is designed to be a helper class to reduce repition when testing the import of song files. - """ - def __init__(self, *args, **kwargs): - self.importer_module = __import__( - u'openlp.plugins.songs.lib.%s' % self.importer_module_name, fromlist=[self.importer_class_name]) - self.importer_class = getattr(self.importer_module, self.importer_class_name) - TestCase.__init__(self, *args, **kwargs) - - def setUp(self): - """ - Patch and set up the mocks required. - """ - self.add_copyright_patcher = patch( - u'openlp.plugins.songs.lib.%s.%s.addCopyright' % (self.importer_module_name, self.importer_class_name)) - self.add_verse_patcher = patch( - u'openlp.plugins.songs.lib.%s.%s.addVerse' % (self.importer_module_name, self.importer_class_name)) - self.finish_patcher = patch( - u'openlp.plugins.songs.lib.%s.%s.finish' % (self.importer_module_name, self.importer_class_name)) - self.parse_author_patcher = patch( - u'openlp.plugins.songs.lib.%s.%s.parse_author' % (self.importer_module_name, self.importer_class_name)) - self.song_import_patcher = patch(u'openlp.plugins.songs.lib.%s.SongImport' % self.importer_module_name) - self.mocked_add_copyright = self.add_copyright_patcher.start() - self.mocked_add_verse = self.add_verse_patcher.start() - self.mocked_finish = self.finish_patcher.start() - self.mocked_parse_author = self.parse_author_patcher.start() - self.mocked_song_importer = self.song_import_patcher.start() - self.mocked_manager = MagicMock() - self.mocked_import_wizard = MagicMock() - self.mocked_finish.return_value = True - - def tearDown(self): - """ - Clean up - """ - self.add_copyright_patcher.stop() - self.add_verse_patcher.stop() - self.finish_patcher.stop() - self.parse_author_patcher.stop() - self.song_import_patcher.stop() - - def load_external_result_data(self, file_name): - """ - A method to load and return an object containing the song data from an external file. - """ - result_file = open(file_name, 'rb') - return json.loads(result_file.read()) - - def file_import(self, source_file_name, result_data): - """ - Import the given file and check that it has imported correctly - """ - importer = self.importer_class(self.mocked_manager) - importer.import_wizard = self.mocked_import_wizard - importer.stop_import_flag = False - importer.topics = [] - - # WHEN: Importing the source file - importer.import_source = [source_file_name] - add_verse_calls = self.get_data(result_data, u'verses') - author_calls = self.get_data(result_data, u'authors') - ccli_number = self.get_data(result_data, u'ccli_number') - comments = self.get_data(result_data, u'comments') - song_book_name = self.get_data(result_data, u'song_book_name') - song_copyright = self.get_data(result_data, u'copyright') - song_number = self.get_data(result_data, u'song_number') - title = self.get_data(result_data, u'title') - topics = self.get_data(result_data, u'topics') - verse_order_list = self.get_data(result_data, u'verse_order_list') - - # THEN: doImport should return none, the song data should be as expected, and finish should have been - # called. - self.assertIsNone(importer.doImport(), u'doImport should return None when it has completed') - self.assertEquals(importer.title, title, u'title for %s should be "%s"' % (source_file_name, title)) - for author in author_calls: - self.mocked_parse_author.assert_any_call(author) - if song_copyright: - self.mocked_add_copyright.assert_called_with(song_copyright) - if ccli_number: - self.assertEquals(importer.ccliNumber, ccli_number, u'ccliNumber for %s should be %s' - % (source_file_name, ccli_number)) - for verse_text, verse_tag in add_verse_calls: - self.mocked_add_verse.assert_any_call(verse_text, verse_tag) - if topics: - self.assertEquals(importer.topics, topics, u'topics for %s should be %s' % (source_file_name, topics)) - if comments: - self.assertEquals(importer.comments, comments, u'comments for %s should be "%s"' - % (source_file_name, comments)) - if song_book_name: - self.assertEquals(importer.songBookName, song_book_name, u'songBookName for %s should be "%s"' - % (source_file_name, song_book_name)) - if song_number: - self.assertEquals(importer.songNumber, song_number, u'songNumber for %s should be %s' - % (source_file_name, song_number)) - if verse_order_list: - self.assertEquals(importer.verseOrderList, [], u'verseOrderList for %s should be %s' - % (source_file_name, verse_order_list)) - self.mocked_finish.assert_called_with() - - def get_data(self, data, key): - if key in data: - return data[key] - return u'' - +""" +The :mod:`songfileimporthelper` modules provides a helper class and methods to easily enable testing the import of +song files from third party applications. +""" +import json +from unittest import TestCase +from mock import patch, MagicMock + +class SongImportTestHelper(TestCase): + """ + This class is designed to be a helper class to reduce repition when testing the import of song files. + """ + def __init__(self, *args, **kwargs): + self.importer_module = __import__( + 'openlp.plugins.songs.lib.%s' % self.importer_module_name, fromlist=[self.importer_class_name]) + self.importer_class = getattr(self.importer_module, self.importer_class_name) + TestCase.__init__(self, *args, **kwargs) + + def setUp(self): + """ + Patch and set up the mocks required. + """ + self.add_copyright_patcher = patch( + 'openlp.plugins.songs.lib.%s.%s.addCopyright' % (self.importer_module_name, self.importer_class_name)) + self.add_verse_patcher = patch( + 'openlp.plugins.songs.lib.%s.%s.addVerse' % (self.importer_module_name, self.importer_class_name)) + self.finish_patcher = patch( + 'openlp.plugins.songs.lib.%s.%s.finish' % (self.importer_module_name, self.importer_class_name)) + self.parse_author_patcher = patch( + 'openlp.plugins.songs.lib.%s.%s.parse_author' % (self.importer_module_name, self.importer_class_name)) + self.song_import_patcher = patch('openlp.plugins.songs.lib.%s.SongImport' % self.importer_module_name) + self.mocked_add_copyright = self.add_copyright_patcher.start() + self.mocked_add_verse = self.add_verse_patcher.start() + self.mocked_finish = self.finish_patcher.start() + self.mocked_parse_author = self.parse_author_patcher.start() + self.mocked_song_importer = self.song_import_patcher.start() + self.mocked_manager = MagicMock() + self.mocked_import_wizard = MagicMock() + self.mocked_finish.return_value = True + + def tearDown(self): + """ + Clean up + """ + self.add_copyright_patcher.stop() + self.add_verse_patcher.stop() + self.finish_patcher.stop() + self.parse_author_patcher.stop() + self.song_import_patcher.stop() + + def load_external_result_data(self, file_name): + """ + A method to load and return an object containing the song data from an external file. + """ + result_file = open(file_name, 'rb') + return json.loads(result_file.read()) + + def file_import(self, source_file_name, result_data): + """ + Import the given file and check that it has imported correctly + """ + importer = self.importer_class(self.mocked_manager) + importer.import_wizard = self.mocked_import_wizard + importer.stop_import_flag = False + importer.topics = [] + + # WHEN: Importing the source file + importer.import_source = [source_file_name] + add_verse_calls = self.get_data(result_data, 'verses') + author_calls = self.get_data(result_data, 'authors') + ccli_number = self.get_data(result_data, 'ccli_number') + comments = self.get_data(result_data, 'comments') + song_book_name = self.get_data(result_data, 'song_book_name') + song_copyright = self.get_data(result_data, 'copyright') + song_number = self.get_data(result_data, 'song_number') + title = self.get_data(result_data, 'title') + topics = self.get_data(result_data, 'topics') + verse_order_list = self.get_data(result_data, 'verse_order_list') + + # THEN: doImport should return none, the song data should be as expected, and finish should have been + # called. + self.assertIsNone(importer.doImport(), 'doImport should return None when it has completed') + self.assertEquals(importer.title, title, 'title for %s should be "%s"' % (source_file_name, title)) + for author in author_calls: + self.mocked_parse_author.assert_any_call(author) + if song_copyright: + self.mocked_add_copyright.assert_called_with(song_copyright) + if ccli_number: + self.assertEquals(importer.ccliNumber, ccli_number, 'ccliNumber for %s should be %s' + % (source_file_name, ccli_number)) + for verse_text, verse_tag in add_verse_calls: + self.mocked_add_verse.assert_any_call(verse_text, verse_tag) + if topics: + self.assertEquals(importer.topics, topics, 'topics for %s should be %s' % (source_file_name, topics)) + if comments: + self.assertEquals(importer.comments, comments, 'comments for %s should be "%s"' + % (source_file_name, comments)) + if song_book_name: + self.assertEquals(importer.songBookName, song_book_name, 'songBookName for %s should be "%s"' + % (source_file_name, song_book_name)) + if song_number: + self.assertEquals(importer.songNumber, song_number, 'songNumber for %s should be %s' + % (source_file_name, song_number)) + if verse_order_list: + self.assertEquals(importer.verseOrderList, [], 'verseOrderList for %s should be %s' + % (source_file_name, verse_order_list)) + self.mocked_finish.assert_called_with() + + def get_data(self, data, key): + if key in data: + return data[key] + return '' + From ca3e32c2948a6480a4774ca82d54a0688b494086 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 14 Sep 2013 22:43:46 +0100 Subject: [PATCH 08/46] Fix for py3 --- tests/functional/openlp_plugins/songs/songfileimporthelper.py | 2 +- .../functional/openlp_plugins/songs/test_songshowplusimport.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/songfileimporthelper.py b/tests/functional/openlp_plugins/songs/songfileimporthelper.py index d40f14154..5ea907651 100644 --- a/tests/functional/openlp_plugins/songs/songfileimporthelper.py +++ b/tests/functional/openlp_plugins/songs/songfileimporthelper.py @@ -53,7 +53,7 @@ class SongImportTestHelper(TestCase): A method to load and return an object containing the song data from an external file. """ result_file = open(file_name, 'rb') - return json.loads(result_file.read()) + return json.loads(result_file.read().decode()) def file_import(self, source_file_name, result_data): """ diff --git a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py index 5b5062823..7f252018b 100644 --- a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py @@ -63,7 +63,7 @@ class TestSongShowPlusImport(TestCase): # THEN: doImport should return none and the progress bar maximum should not be set. self.assertIsNone(importer.doImport(), 'doImport should return None when import_source is not a list') self.assertEquals(mocked_import_wizard.progress_bar.setMaximum.called, False, - 'setMaxium on import_wizard.progress_bar should not have been called') + 'setMaximum on import_wizard.progress_bar should not have been called') def valid_import_source_test(self): """ From 9f5bd87a5052d5d2de29ae0dbe81c69dcc62ac6d Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sun, 15 Sep 2013 20:27:40 +0100 Subject: [PATCH 09/46] Py3 Fixes --- openlp/core/lib/__init__.py | 38 +++++++++++++++++------------------ openlp/core/lib/filedialog.py | 11 +++++----- openlp/core/lib/uistrings.py | 4 ++-- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index b327b4a1c..b4f6b4223 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -374,22 +374,22 @@ def create_separated_list(stringlist): return translate('OpenLP.core.lib', '%s, %s', u'Locale list separator: start') % (stringlist[0], merged) -from registry import Registry -from uistrings import UiStrings -from filedialog import FileDialog -from screen import ScreenList -from settings import Settings -from listwidgetwithdnd import ListWidgetWithDnD -from treewidgetwithdnd import TreeWidgetWithDnD -from formattingtags import FormattingTags -from spelltextedit import SpellTextEdit -from plugin import PluginStatus, StringContent, Plugin -from pluginmanager import PluginManager -from settingstab import SettingsTab -from serviceitem import ServiceItem, ServiceItemType, ItemCapabilities -from htmlbuilder import build_html, build_lyrics_format_css, build_lyrics_outline_css -from toolbar import OpenLPToolbar -from dockwidget import OpenLPDockWidget -from imagemanager import ImageManager -from renderer import Renderer -from mediamanageritem import MediaManagerItem \ No newline at end of file +from .registry import Registry +from .uistrings import UiStrings +from .filedialog import FileDialog +from .screen import ScreenList +from .settings import Settings +from .listwidgetwithdnd import ListWidgetWithDnD +from .treewidgetwithdnd import TreeWidgetWithDnD +from .formattingtags import FormattingTags +from .spelltextedit import SpellTextEdit +from .plugin import PluginStatus, StringContent, Plugin +from .pluginmanager import PluginManager +from .settingstab import SettingsTab +from .serviceitem import ServiceItem, ServiceItemType, ItemCapabilities +from .htmlbuilder import build_html, build_lyrics_format_css, build_lyrics_outline_css +from .toolbar import OpenLPToolbar +from .dockwidget import OpenLPDockWidget +from .imagemanager import ImageManager +from .renderer import Renderer +from .mediamanageritem import MediaManagerItem \ No newline at end of file diff --git a/openlp/core/lib/filedialog.py b/openlp/core/lib/filedialog.py index ea2eba045..03a8b8c47 100644 --- a/openlp/core/lib/filedialog.py +++ b/openlp/core/lib/filedialog.py @@ -32,7 +32,7 @@ Provide a work around for a bug in QFileDialog Date: Sun, 15 Sep 2013 20:42:29 +0100 Subject: [PATCH 10/46] more Py3 fixes --- openlp/core/lib/__init__.py | 6 ++--- .../openlp_core_lib/test_file_dialog.py | 26 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index b4f6b4223..3700e2162 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -370,8 +370,8 @@ def create_separated_list(stringlist): 'Locale list separator: end') % (stringlist[-2], stringlist[-1]) for index in reversed(list(range(1, len(stringlist) - 2))): merged = translate('OpenLP.core.lib', '%s, %s', - u'Locale list separator: middle') % (stringlist[index], merged) - return translate('OpenLP.core.lib', '%s, %s', u'Locale list separator: start') % (stringlist[0], merged) + 'Locale list separator: middle') % (stringlist[index], merged) + return translate('OpenLP.core.lib', '%s, %s', 'Locale list separator: start') % (stringlist[0], merged) from .registry import Registry @@ -392,4 +392,4 @@ from .toolbar import OpenLPToolbar from .dockwidget import OpenLPDockWidget from .imagemanager import ImageManager from .renderer import Renderer -from .mediamanageritem import MediaManagerItem \ No newline at end of file +from .mediamanageritem import MediaManagerItem diff --git a/tests/functional/openlp_core_lib/test_file_dialog.py b/tests/functional/openlp_core_lib/test_file_dialog.py index b895cc67d..0a5736ff0 100644 --- a/tests/functional/openlp_core_lib/test_file_dialog.py +++ b/tests/functional/openlp_core_lib/test_file_dialog.py @@ -1,5 +1,5 @@ """ -Package to test the openlp.core.lib.formattingtags package. +Package to test the openlp.core.lib.filedialog package. """ import copy from unittest import TestCase @@ -13,9 +13,9 @@ class TestFileDialog(TestCase): Test the functions in the :mod:`filedialog` module. """ def setUp(self): - self.os_patcher = patch(u'openlp.core.lib.filedialog.os') - self.qt_gui_patcher = patch(u'openlp.core.lib.filedialog.QtGui') - self.ui_strings_patcher = patch(u'openlp.core.lib.filedialog.UiStrings') + self.os_patcher = patch('openlp.core.lib.filedialog.os') + self.qt_gui_patcher = patch('openlp.core.lib.filedialog.QtGui') + self.ui_strings_patcher = patch('openlp.core.lib.filedialog.UiStrings') self.mocked_os = self.os_patcher.start() self.mocked_qt_gui = self.qt_gui_patcher.start() self.mocked_ui_strings = self.ui_strings_patcher.start() @@ -39,10 +39,10 @@ class TestFileDialog(TestCase): # WHEN: FileDialog.getOpenFileNames is called result = FileDialog.getOpenFileNames(self.mocked_parent) - # THEN: The returned value should be an empty QStiingList and os.path.exists should not have been called + # THEN: The returned value should be an empty QStringList and os.path.exists should not have been called assert not self.mocked_os.path.exists.called self.assertEqual(result, [], - u'FileDialog.getOpenFileNames should return and empty list when QFileDialog.getOpenFileNames is canceled') + 'FileDialog.getOpenFileNames should return and empty list when QFileDialog.getOpenFileNames is canceled') def returned_file_list_test(self): """ @@ -52,20 +52,20 @@ class TestFileDialog(TestCase): self.mocked_os.rest() self.mocked_qt_gui.reset() - # GIVEN: A List of known values as a return value from QFileDialog.getOpenFileNamesand a list of valid + # GIVEN: A List of known values as a return value from QFileDialog.getOpenFileNames and a list of valid # file names. self.mocked_qt_gui.QFileDialog.getOpenFileNames.return_value = [ - u'/Valid File', u'/url%20encoded%20file%20%231', u'/non-existing'] + '/Valid File', '/url%20encoded%20file%20%231', '/non-existing'] self.mocked_os.path.exists.side_effect = lambda file_name: file_name in [ - u'/Valid File', u'/url encoded file #1'] + '/Valid File', '/url encoded file #1'] # WHEN: FileDialog.getOpenFileNames is called result = FileDialog.getOpenFileNames(self.mocked_parent) # THEN: os.path.exists should have been called with known args. QmessageBox.information should have been # called. The returned result should corrilate with the input. - self.mocked_os.path.exists.assert_has_calls([call(u'/Valid File'), call(u'/url%20encoded%20file%20%231'), - call(u'/url encoded file #1'), call(u'/non-existing'), call(u'/non-existing')]) + self.mocked_os.path.exists.assert_has_calls([call('/Valid File'), call('/url%20encoded%20file%20%231'), + call('/url encoded file #1'), call('/non-existing'), call('/non-existing')]) self.mocked_qt_gui.QmessageBox.information.called_with(self.mocked_parent, UiStrings().FileNotFound, - UiStrings().FileNotFoundMessage % u'/non-existing') - self.assertEqual(result, [u'/Valid File', u'/url encoded file #1'], u'The returned file list is incorrect') \ No newline at end of file + UiStrings().FileNotFoundMessage % '/non-existing') + self.assertEqual(result, ['/Valid File', '/url encoded file #1'], 'The returned file list is incorrect') \ No newline at end of file From 91bb04f03a2e28e93689a2f1ba1f0538c2172c03 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 17 Sep 2013 21:31:19 +0100 Subject: [PATCH 11/46] Changed to using super() --- tests/functional/openlp_plugins/songs/songfileimporthelper.py | 2 +- .../functional/openlp_plugins/songs/test_songshowplusimport.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/songfileimporthelper.py b/tests/functional/openlp_plugins/songs/songfileimporthelper.py index 5ea907651..e8bbc46bf 100644 --- a/tests/functional/openlp_plugins/songs/songfileimporthelper.py +++ b/tests/functional/openlp_plugins/songs/songfileimporthelper.py @@ -11,10 +11,10 @@ class SongImportTestHelper(TestCase): This class is designed to be a helper class to reduce repition when testing the import of song files. """ def __init__(self, *args, **kwargs): + super(SongImportTestHelper, self).__init__(*args, **kwargs) self.importer_module = __import__( 'openlp.plugins.songs.lib.%s' % self.importer_module_name, fromlist=[self.importer_class_name]) self.importer_class = getattr(self.importer_module, self.importer_class_name) - TestCase.__init__(self, *args, **kwargs) def setUp(self): """ diff --git a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py index 7f252018b..28ff53249 100644 --- a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py @@ -17,7 +17,7 @@ class TestSongShowPlusFileImport(SongImportTestHelper): def __init__(self, *args, **kwargs): self.importer_class_name = 'SongShowPlusImport' self.importer_module_name = 'songshowplusimport' - SongImportTestHelper.__init__(self, *args, **kwargs) + super(TestSongShowPlusFileImport, self).__init__(*args, **kwargs) def test_song_import(self): test_import = self.file_import(os.path.join(TEST_PATH, 'Amazing Grace.sbsong'), From e8302e9e95ab2112dba7e8b04c96ec026a4663c8 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Tue, 24 Sep 2013 21:40:51 +0100 Subject: [PATCH 12/46] Added test for bug 1184869 --- .../openlp_plugins/bibles/test_http.py | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 tests/functional/openlp_plugins/bibles/test_http.py diff --git a/tests/functional/openlp_plugins/bibles/test_http.py b/tests/functional/openlp_plugins/bibles/test_http.py new file mode 100644 index 000000000..e98c38c97 --- /dev/null +++ b/tests/functional/openlp_plugins/bibles/test_http.py @@ -0,0 +1,180 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +This module contains tests for the http module of the Bibles plugin. +""" +from unittest import TestCase +from mock import MagicMock, patch +from bs4 import BeautifulSoup + +from openlp.plugins.bibles.lib.http import BSExtract + +#TODO: Items left to test +# BGExtract +# __init__ +# _remove_elements +# _extract_verse +# _clean_soup +# _extract_verses +# _extract_verses_old +# get_bible_chapter +# get_books_from_http +# _get_application +# CWExtract +# __init__ +# get_bible_chapter +# get_books_from_http +# _get_application +# HTTPBible +# __init__ +# do_import +# get_verses +# get_chapter +# get_books +# get_chapter_count +# get_verse_count +# _get_application +# get_soup_for_bible_ref +# send_error_message + +class TestBSExtract(TestCase): + """ + Test the BSExtractClass + """ + #TODO: Items left to test + # BSExtract + # __init__ + # get_bible_chapter + # get_books_from_http + # _get_application + def setUp(self): + self.get_soup_for_bible_ref_patcher = patch('openlp.plugins.bibles.lib.http.get_soup_for_bible_ref') + self.log_patcher = patch('openlp.plugins.bibles.lib.http.log') + self.send_error_message_patcher = patch('openlp.plugins.bibles.lib.http.send_error_message') + self.socket_patcher = patch('openlp.plugins.bibles.lib.http.socket') + self.urllib_patcher = patch('openlp.plugins.bibles.lib.http.urllib') + + self.mock_get_soup_for_bible_ref = self.get_soup_for_bible_ref_patcher.start() + self.mock_log = self.log_patcher.start() + self.mock_send_error_message = self.send_error_message_patcher.start() + self.mock_socket = self.socket_patcher.start() + self.mock_soup = MagicMock() + self.mock_urllib = self.urllib_patcher.start() + + def tearDown(self): + self.get_soup_for_bible_ref_patcher.stop() + self.log_patcher.stop() + self.send_error_message_patcher.stop() + self.socket_patcher.stop() + self.urllib_patcher.stop() + + def get_books_from_http_no_soup_test(self): + """ + Test the get_books_from_http method when get_soup_for_bible_ref returns a falsey value + """ + # GIVEN: An instance of BSExtract, and reset log, urllib & get_soup_for_bible_ref mocks + instance = BSExtract() + self.mock_log.debug.reset_mock() + self.mock_urllib.reset_mock() + self.mock_get_soup_for_bible_ref.reset_mock() + + # WHEN: get_books_from_http is called with 'NIV' and get_soup_for_bible_ref returns a None value + self.mock_urllib.parse.quote.return_value = 'NIV' + self.mock_get_soup_for_bible_ref.return_value = None + result = instance.get_books_from_http('NIV') + + # THEN: The rest mocks should be called with known values and get_books_from_http should return None + self.mock_log.debug.assert_called_once_with('BSExtract.get_books_from_http("%s")', 'NIV') + self.mock_urllib.parse.quote.assert_called_once_with(b'NIV') + self.mock_get_soup_for_bible_ref.assert_called_once_with( + 'http://m.bibleserver.com/overlay/selectBook?translation=NIV') + self.assertIsNone(result, + 'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a false value') + + def get_books_from_http_no_content_test(self): + """ + Test the get_books_from_http method when the specified element cannot be found in the tag object returned from + get_soup_for_bible_ref + """ + # GIVEN: An instance of BSExtract, and reset log, urllib, get_soup_for_bible_ref & soup mocks + instance = BSExtract() + self.mock_log.reset_mock() + self.mock_urllib.reset_mock() + self.mock_get_soup_for_bible_ref.reset_mock() + self.mock_soup.reset_mock() + + # WHEN: get_books_from_http is called with 'NIV', get_soup_for_bible_ref returns a mocked_soup object and + # mocked_soup.find returns None + self.mock_urllib.parse.quote.return_value = 'NIV' + self.mock_soup.find.return_value = None + self.mock_get_soup_for_bible_ref.return_value = self.mock_soup + result = instance.get_books_from_http('NIV') + + # THEN: The rest mocks should be called with known values and get_books_from_http should return None + self.mock_log.debug.assert_called_once_with('BSExtract.get_books_from_http("%s")', 'NIV') + self.mock_urllib.parse.quote.assert_called_once_with(b'NIV') + self.mock_get_soup_for_bible_ref.assert_called_once_with( + 'http://m.bibleserver.com/overlay/selectBook?translation=NIV') + self.mock_soup.find.assert_called_once_with('ul') + self.mock_log.error.assert_called_once_with('No books found in the Bibleserver response.') + self.mock_send_error_message.assert_called_once_with('parse') + self.assertIsNone(result, + 'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a false value') + + def get_books_from_http_content_test(self): + """ + Test the get_books_from_http method with sample HTML + Also a regression test for bug #1184869. (The anchor tag in the second list item is empty) + """ + # GIVEN: An instance of BSExtract, and reset log, urllib & get_soup_for_bible_ref mocks and sample HTML data + self.test_html = '' + self.test_soup = BeautifulSoup(self.test_html) + instance = BSExtract() + self.mock_log.reset_mock() + self.mock_urllib.reset_mock() + self.mock_get_soup_for_bible_ref.reset_mock() + self.mock_send_error_message.reset_mock() + + # WHEN: get_books_from_http is called with 'NIV' and get_soup_for_bible_ref returns tag object based on the + # supplied test data. + self.mock_urllib.parse.quote.return_value = 'NIV' + self.mock_get_soup_for_bible_ref.return_value = self.test_soup + result = instance.get_books_from_http('NIV') + + # THEN: The rest mocks should be called with known values and get_books_from_http should return the two books + # in the test data + self.mock_log.debug.assert_called_once_with('BSExtract.get_books_from_http("%s")', 'NIV') + self.mock_urllib.parse.quote.assert_called_once_with(b'NIV') + self.mock_get_soup_for_bible_ref.assert_called_once_with( + 'http://m.bibleserver.com/overlay/selectBook?translation=NIV') + self.assertFalse(self.mock_log.error.called, 'log.error should not have been called') + self.assertFalse(self.mock_send_error_message.called, 'send_error_message should not have been called') + self.assertEquals(result, ['Genesis', 'Leviticus']) From 285508fd2d1b968df936f6df9dc4546d25666a7e Mon Sep 17 00:00:00 2001 From: "s.mehrbrodt@gmail.com" Date: Thu, 26 Sep 2013 17:05:10 +0200 Subject: [PATCH 13/46] Fix Import for SongBeamer files --- openlp/plugins/songs/lib/songbeamerimport.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index f00e98e63..813e5fea4 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -33,6 +33,7 @@ import chardet import codecs import logging import os +import io import re from openlp.plugins.songs.lib import VerseType @@ -105,7 +106,7 @@ class SongBeamerImport(SongImport): self.import_wizard.progress_bar.setMaximum(len(self.import_source)) if not isinstance(self.import_source, list): return - for file in self.import_source: + for _file in self.import_source: # TODO: check that it is a valid SongBeamer file if self.stop_import_flag: return @@ -113,12 +114,9 @@ class SongBeamerImport(SongImport): self.currentVerse = '' self.currentVerseType = VerseType.tags[VerseType.Verse] read_verses = False - file_name = os.path.split(file)[1] - if os.path.isfile(file): - detect_file = open(file, 'r') - details = chardet.detect(detect_file.read()) - detect_file.close() - infile = codecs.open(file, 'r', details['encoding']) + file_name = os.path.split(_file)[1] + if os.path.isfile(_file): + infile = io.open(_file, 'r', encoding="Latin-1") song_data = infile.readlines() infile.close() else: @@ -149,7 +147,7 @@ class SongBeamerImport(SongImport): self.replaceHtmlTags() self.addVerse(self.currentVerse, self.currentVerseType) if not self.finish(): - self.logError(file) + self.logError(_file) def replaceHtmlTags(self): """ From 9dbb2e12b05d541994738110492932685594f484 Mon Sep 17 00:00:00 2001 From: "s.mehrbrodt@gmail.com" Date: Thu, 26 Sep 2013 17:08:27 +0200 Subject: [PATCH 14/46] Remove now unused imports --- openlp/plugins/songs/lib/songbeamerimport.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index 813e5fea4..ab570ba8b 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -29,8 +29,6 @@ """ The :mod:`songbeamerimport` module provides the functionality for importing SongBeamer songs into the OpenLP database. """ -import chardet -import codecs import logging import os import io From c78a2a110329d28ae457d1a17f96e996f9f8c3f4 Mon Sep 17 00:00:00 2001 From: "s.mehrbrodt@gmail.com" Date: Thu, 26 Sep 2013 18:18:04 +0200 Subject: [PATCH 15/46] Open Songbeamer Files in binary mode to detect the encoding --- openlp/plugins/songs/lib/songbeamerimport.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index ab570ba8b..b085b9463 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -29,9 +29,10 @@ """ The :mod:`songbeamerimport` module provides the functionality for importing SongBeamer songs into the OpenLP database. """ +import chardet +import codecs import logging import os -import io import re from openlp.plugins.songs.lib import VerseType @@ -114,7 +115,11 @@ class SongBeamerImport(SongImport): read_verses = False file_name = os.path.split(_file)[1] if os.path.isfile(_file): - infile = io.open(_file, 'r', encoding="Latin-1") + # First open in binary mode to detect the encoding + detect_file = open(_file, 'rb') + details = chardet.detect(detect_file.read()) + detect_file.close() + infile = codecs.open(_file, 'r', details['encoding']) song_data = infile.readlines() infile.close() else: From fb6336484b71c5431b9cfa829124235240406fe6 Mon Sep 17 00:00:00 2001 From: "s.mehrbrodt@gmail.com" Date: Sat, 28 Sep 2013 22:24:05 +0200 Subject: [PATCH 16/46] Rename variable --- openlp/plugins/songs/lib/songbeamerimport.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index b085b9463..3d376e092 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -105,7 +105,7 @@ class SongBeamerImport(SongImport): self.import_wizard.progress_bar.setMaximum(len(self.import_source)) if not isinstance(self.import_source, list): return - for _file in self.import_source: + for import_file in self.import_source: # TODO: check that it is a valid SongBeamer file if self.stop_import_flag: return @@ -113,13 +113,13 @@ class SongBeamerImport(SongImport): self.currentVerse = '' self.currentVerseType = VerseType.tags[VerseType.Verse] read_verses = False - file_name = os.path.split(_file)[1] - if os.path.isfile(_file): + file_name = os.path.split(import_file)[1] + if os.path.isfile(import_file): # First open in binary mode to detect the encoding - detect_file = open(_file, 'rb') + detect_file = open(import_file, 'rb') details = chardet.detect(detect_file.read()) detect_file.close() - infile = codecs.open(_file, 'r', details['encoding']) + infile = codecs.open(import_file, 'r', details['encoding']) song_data = infile.readlines() infile.close() else: @@ -150,7 +150,7 @@ class SongBeamerImport(SongImport): self.replaceHtmlTags() self.addVerse(self.currentVerse, self.currentVerseType) if not self.finish(): - self.logError(_file) + self.logError(import_file) def replaceHtmlTags(self): """ From b5a2ecfa3f50fe96cd33dffc42dcefbd41f6231e Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 5 Oct 2013 08:56:08 +0100 Subject: [PATCH 17/46] Fixed up imports and added Copyright/License header. --- .../songs/songfileimporthelper.py | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/functional/openlp_plugins/songs/songfileimporthelper.py b/tests/functional/openlp_plugins/songs/songfileimporthelper.py index e8bbc46bf..4f44b150c 100644 --- a/tests/functional/openlp_plugins/songs/songfileimporthelper.py +++ b/tests/functional/openlp_plugins/songs/songfileimporthelper.py @@ -1,10 +1,38 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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:`songfileimporthelper` modules provides a helper class and methods to easily enable testing the import of song files from third party applications. """ import json from unittest import TestCase -from mock import patch, MagicMock +from tests.functional import patch, MagicMock class SongImportTestHelper(TestCase): """ From beeea8ab9a7952258d3bdcf2c8cecb1a78fec131 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 5 Oct 2013 10:16:04 +0100 Subject: [PATCH 18/46] changed line spacing arround imports --- tests/functional/openlp_plugins/songs/songfileimporthelper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional/openlp_plugins/songs/songfileimporthelper.py b/tests/functional/openlp_plugins/songs/songfileimporthelper.py index 4f44b150c..f2e87da86 100644 --- a/tests/functional/openlp_plugins/songs/songfileimporthelper.py +++ b/tests/functional/openlp_plugins/songs/songfileimporthelper.py @@ -32,6 +32,7 @@ song files from third party applications. """ import json from unittest import TestCase + from tests.functional import patch, MagicMock class SongImportTestHelper(TestCase): From c471fc79ba3b83eb65905a101f04c3b179044653 Mon Sep 17 00:00:00 2001 From: "s.mehrbrodt@gmail.com02" Date: Mon, 7 Oct 2013 00:07:49 +0200 Subject: [PATCH 19/46] Add Songbeamer Import test --- openlp/plugins/songs/lib/songbeamerimport.py | 2 +- .../songs/test_songbeamerimport.py | 127 ++++++++++++++++++ .../songbeamersongs/Lobsinget dem Herrn.sng | 25 ++++ 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 tests/functional/openlp_plugins/songs/test_songbeamerimport.py create mode 100644 tests/resources/songbeamersongs/Lobsinget dem Herrn.sng diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index 3d376e092..79e6f6263 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -102,9 +102,9 @@ class SongBeamerImport(SongImport): """ Receive a single file or a list of files to import. """ - self.import_wizard.progress_bar.setMaximum(len(self.import_source)) if not isinstance(self.import_source, list): return + self.import_wizard.progress_bar.setMaximum(len(self.import_source)) for import_file in self.import_source: # TODO: check that it is a valid SongBeamer file if self.stop_import_flag: diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py new file mode 100644 index 000000000..e6b1c4570 --- /dev/null +++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py @@ -0,0 +1,127 @@ +""" +This module contains tests for the Songbeamer song importer. +""" + +import os +from unittest import TestCase +from mock import patch, MagicMock + +from openlp.plugins.songs.lib.songbeamerimport import SongBeamerImport + +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../resources/songbeamersongs')) +SONG_TEST_DATA = {'Lobsinget dem Herrn.sng': + {'title': 'GL 1 - Lobsinget dem Herrn', + 'verses': + [('1. Lobsinget dem Herrn,\no preiset Ihn gern!\n' + 'Anbetung und Lob Ihm gebühret.\n', 'v'), + ('2. Lobsingt Seiner Lieb´,\ndie einzig ihn trieb,\n' + 'zu sterben für unsere Sünden!\n', 'v'), + ('3. Lobsingt Seiner Macht!\nSein Werk ist vollbracht:\n' + 'Er sitzet zur Rechten des Vaters.\n', 'v'), + ('4. Lobsingt seiner Treu´,\ndie immerdar neu,\n' + 'bis Er uns zur Herrlichket führet!\n\n', 'v')], + 'song_book_name': 'Glaubenslieder I', + 'song_number': "1"} + } + + +class TestSongBeamerImport(TestCase): + """ + Test the functions in the :mod:`songbeamerimport` module. + """ + def create_importer_test(self): + """ + Test creating an instance of the SongBeamer file importer + """ + # GIVEN: A mocked out SongImport class, and a mocked out "manager" + with patch('openlp.plugins.songs.lib.songbeamerimport.SongImport'): + mocked_manager = MagicMock() + + # WHEN: An importer object is created + importer = SongBeamerImport(mocked_manager) + + # THEN: The importer object should not be None + self.assertIsNotNone(importer, 'Import should not be none') + + def invalid_import_source_test(self): + """ + Test SongBeamerImport.doImport handles different invalid import_source values + """ + # GIVEN: A mocked out SongImport class, and a mocked out "manager" + with patch('openlp.plugins.songs.lib.songbeamerimport.SongImport'): + mocked_manager = MagicMock() + mocked_import_wizard = MagicMock() + importer = SongBeamerImport(mocked_manager) + importer.import_wizard = mocked_import_wizard + importer.stop_import_flag = True + + # WHEN: Import source is not a list + for source in ['not a list', 0]: + importer.import_source = source + + # THEN: doImport should return none and the progress bar maximum should not be set. + self.assertIsNone(importer.doImport(), 'doImport should return None when import_source is not a list') + self.assertEquals(mocked_import_wizard.progress_bar.setMaximum.called, False, + 'setMaxium on import_wizard.progress_bar should not have been called') + + def valid_import_source_test(self): + """ + Test SongBeamerImport.doImport handles different invalid import_source values + """ + # GIVEN: A mocked out SongImport class, and a mocked out "manager" + with patch('openlp.plugins.songs.lib.songbeamerimport.SongImport'): + mocked_manager = MagicMock() + mocked_import_wizard = MagicMock() + importer = SongBeamerImport(mocked_manager) + importer.import_wizard = mocked_import_wizard + importer.stop_import_flag = True + + # WHEN: Import source is a list + importer.import_source = ['List', 'of', 'files'] + + # THEN: doImport should return none and the progress bar setMaximum should be called with the length of + # import_source. + self.assertIsNone(importer.doImport(), + 'doImport should return None when import_source is a list and stop_import_flag is True') + mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source)) + + def file_import_test(self): + """ + Test the actual import of real song files and check that the imported data is correct. + """ + + # GIVEN: Test files with a mocked out SongImport class, a mocked out "manager", a mocked out "import_wizard", + # and mocked out "author", "add_copyright", "add_verse", "finish" methods. + with patch('openlp.plugins.songs.lib.songbeamerimport.SongImport'): + for song_file in SONG_TEST_DATA: + mocked_manager = MagicMock() + mocked_import_wizard = MagicMock() + mocked_add_verse = MagicMock() + mocked_finish = MagicMock() + mocked_finish.return_value = True + importer = SongBeamerImport(mocked_manager) + importer.import_wizard = mocked_import_wizard + importer.stop_import_flag = False + importer.addVerse = mocked_add_verse + importer.finish = mocked_finish + + # WHEN: Importing each file + importer.import_source = [os.path.join(TEST_PATH, song_file)] + title = SONG_TEST_DATA[song_file]['title'] + add_verse_calls = SONG_TEST_DATA[song_file]['verses'] + song_book_name = SONG_TEST_DATA[song_file]['song_book_name'] + song_number = SONG_TEST_DATA[song_file]['song_number'] + + # THEN: doImport should return none, the song data should be as expected, and finish should have been + # called. + self.assertIsNone(importer.doImport(), 'doImport should return None when it has completed') + self.assertEquals(importer.title, title, 'title for %s should be "%s"' % (song_file, title)) + for verse_text, verse_tag in add_verse_calls: + mocked_add_verse.assert_any_call(verse_text, verse_tag) + if song_book_name: + self.assertEquals(importer.songBookName, song_book_name, 'songBookName for %s should be "%s"' + % (song_file, song_book_name)) + if song_number: + self.assertEquals(importer.songNumber, song_number, 'songNumber for %s should be %s' + % (song_file, song_number)) + mocked_finish.assert_called_with() diff --git a/tests/resources/songbeamersongs/Lobsinget dem Herrn.sng b/tests/resources/songbeamersongs/Lobsinget dem Herrn.sng new file mode 100644 index 000000000..fbc9aa9fc --- /dev/null +++ b/tests/resources/songbeamersongs/Lobsinget dem Herrn.sng @@ -0,0 +1,25 @@ +#LangCount=1 +#Title=GL 1 - Lobsinget dem Herrn +#Editor=SongBeamer 4.20 +#Version=3 +#Format=F/K// +#TitleFormat=U +#ChurchSongID=0001 +#Songbook=Glaubenslieder I / 1 +--- +1. Lobsinget dem Herrn, +o preiset Ihn gern! +Anbetung und Lob Ihm gebühret. + --- +2. Lobsingt Seiner Lieb´, +die einzig ihn trieb, +zu sterben für unsere Sünden! + --- +3. Lobsingt Seiner Macht! +Sein Werk ist vollbracht: +Er sitzet zur Rechten des Vaters. + --- +4. Lobsingt seiner Treu´, +die immerdar neu, +bis Er uns zur Herrlichket führet! + From b5831c2f38ab25043cea8d7801910dfff1d2029a Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Thu, 10 Oct 2013 20:58:52 +0100 Subject: [PATCH 20/46] Moved song file import helper --- .../functional/openlp_plugins/songs/test_songshowplusimport.py | 2 +- .../songs/songfileimporthelper.py => helpers/songfileimport.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/{functional/openlp_plugins/songs/songfileimporthelper.py => helpers/songfileimport.py} (100%) diff --git a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py index 127c3b616..aa0779f5c 100644 --- a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py @@ -33,7 +33,7 @@ This module contains tests for the SongShow Plus song importer. import os from unittest import TestCase -from tests.functional.openlp_plugins.songs.songfileimporthelper import SongImportTestHelper +from tests.helpers.songfileimport import SongImportTestHelper from openlp.plugins.songs.lib import VerseType from openlp.plugins.songs.lib.songshowplusimport import SongShowPlusImport from tests.functional import patch, MagicMock diff --git a/tests/functional/openlp_plugins/songs/songfileimporthelper.py b/tests/helpers/songfileimport.py similarity index 100% rename from tests/functional/openlp_plugins/songs/songfileimporthelper.py rename to tests/helpers/songfileimport.py From 257fba8548a75e34a8ce2766fcfedf893516c583 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 13 Oct 2013 14:51:13 +0100 Subject: [PATCH 21/46] Start theme clean up --- openlp/core/__init__.py | 3 +- openlp/core/{theme => common}/__init__.py | 29 +- openlp/core/{utils => common}/applocation.py | 26 +- openlp/core/lib/db.py | 3 +- openlp/core/lib/json/theme.json | 49 ++++ openlp/core/lib/pluginmanager.py | 2 +- openlp/core/lib/theme.py | 15 +- openlp/core/theme/theme.py | 252 ------------------ openlp/core/ui/__init__.py | 3 +- openlp/core/ui/advancedtab.py | 3 +- openlp/core/ui/firsttimeform.py | 3 +- openlp/core/ui/mainwindow.py | 4 +- openlp/core/ui/media/mediacontroller.py | 2 +- openlp/core/ui/printserviceform.py | 2 +- openlp/core/ui/servicemanager.py | 3 +- openlp/core/ui/thememanager.py | 150 +++-------- openlp/core/ui/thememanagerhelper.py | 38 +++ openlp/core/utils/__init__.py | 19 +- openlp/core/utils/languagemanager.py | 2 +- .../plugins/bibles/forms/bibleimportform.py | 3 +- .../plugins/bibles/forms/bibleupgradeform.py | 3 +- openlp/plugins/bibles/lib/db.py | 3 +- openlp/plugins/bibles/lib/manager.py | 3 +- openlp/plugins/bibles/lib/osis.py | 2 +- openlp/plugins/images/lib/mediaitem.py | 3 +- openlp/plugins/media/lib/mediaitem.py | 3 +- .../lib/presentationcontroller.py | 2 +- .../presentations/presentationplugin.py | 2 +- openlp/plugins/remotes/lib/httprouter.py | 4 +- openlp/plugins/remotes/lib/httpserver.py | 3 +- openlp/plugins/remotes/lib/remotetab.py | 3 +- .../songs/forms/duplicatesongremovalform.py | 2 +- openlp/plugins/songs/forms/editsongform.py | 2 +- openlp/plugins/songs/lib/__init__.py | 3 +- openlp/plugins/songs/lib/mediaitem.py | 2 +- openlp/plugins/songs/lib/songimport.py | 2 +- .../openlp_core_utils/test_applocation.py | 2 +- .../openlp_plugins/remotes/test_remotetab.py | 12 +- 38 files changed, 229 insertions(+), 438 deletions(-) rename openlp/core/{theme => common}/__init__.py (75%) rename openlp/core/{utils => common}/applocation.py (88%) create mode 100644 openlp/core/lib/json/theme.json delete mode 100644 openlp/core/theme/theme.py create mode 100644 openlp/core/ui/thememanagerhelper.py diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index f86f9036f..a814ae04c 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -43,6 +43,7 @@ from traceback import format_exception from PyQt4 import QtCore, QtGui +from openlp.core.common import AppLocation from openlp.core.lib import Settings, ScreenList, UiStrings, Registry, check_directory_exists from openlp.core.resources import qInitResources from openlp.core.ui.mainwindow import MainWindow @@ -50,7 +51,7 @@ from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm from openlp.core.ui.firsttimeform import FirstTimeForm from openlp.core.ui.exceptionform import ExceptionForm from openlp.core.ui import SplashScreen -from openlp.core.utils import AppLocation, LanguageManager, VersionThread, get_application_version +from openlp.core.utils import LanguageManager, VersionThread, get_application_version __all__ = ['OpenLP', 'main'] diff --git a/openlp/core/theme/__init__.py b/openlp/core/common/__init__.py similarity index 75% rename from openlp/core/theme/__init__.py rename to openlp/core/common/__init__.py index 4db399fa7..e2c95b6cc 100644 --- a/openlp/core/theme/__init__.py +++ b/openlp/core/common/__init__.py @@ -27,10 +27,31 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ -The :mod:`~openlp.core.theme` module contains all the themeing functions used by -OpenLP when displaying a song or a scripture. +The :mod:`common` module contains most of the components and libraries that make +OpenLP work. """ +import os +import logging -from openlp.core.theme.theme import Theme +log = logging.getLogger(__name__) -__all__ = ['Theme'] + +def check_directory_exists(directory, do_not_log=False): + """ + Check a theme directory exists and if not create it + + ``directory`` + The directory to make sure exists + + ``do_not_log`` + To not log anything. This is need for the start up, when the log isn't ready. + """ + if not do_not_log: + log.debug('check_directory_exists %s' % directory) + try: + if not os.path.exists(directory): + os.makedirs(directory) + except IOError: + pass + +from .applocation import AppLocation \ No newline at end of file diff --git a/openlp/core/utils/applocation.py b/openlp/core/common/applocation.py similarity index 88% rename from openlp/core/utils/applocation.py rename to openlp/core/common/applocation.py index 726cbbeda..7d0010316 100644 --- a/openlp/core/utils/applocation.py +++ b/openlp/core/common/applocation.py @@ -27,16 +27,12 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ -The :mod:`openlp.core.utils.applocation` module provides an utility for OpenLP receiving the data path etc. +The :mod:`openlp.core.common.applocation` module provides an utility for OpenLP receiving the data path etc. """ import logging import os import sys -from openlp.core.lib import Settings -from openlp.core.utils import _get_frozen_path - - if sys.platform != 'win32' and sys.platform != 'darwin': try: from xdg import BaseDirectory @@ -45,7 +41,7 @@ if sys.platform != 'win32' and sys.platform != 'darwin': XDG_BASE_AVAILABLE = False import openlp -from openlp.core.lib import check_directory_exists +from openlp.core.common import check_directory_exists log = logging.getLogger(__name__) @@ -74,15 +70,15 @@ class AppLocation(object): The directory type you want, for instance the data directory. Default *AppLocation.AppDir* """ if dir_type == AppLocation.AppDir: - return _get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), os.path.split(openlp.__file__)[0]) + return get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), os.path.split(openlp.__file__)[0]) elif dir_type == AppLocation.PluginsDir: app_path = os.path.abspath(os.path.split(sys.argv[0])[0]) - return _get_frozen_path(os.path.join(app_path, 'plugins'), + return get_frozen_path(os.path.join(app_path, 'plugins'), os.path.join(os.path.split(openlp.__file__)[0], 'plugins')) elif dir_type == AppLocation.VersionDir: - return _get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), os.path.split(openlp.__file__)[0]) + return get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), os.path.split(openlp.__file__)[0]) elif dir_type == AppLocation.LanguageDir: - app_path = _get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), _get_os_dir_path(dir_type)) + app_path = get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), _get_os_dir_path(dir_type)) return os.path.join(app_path, 'i18n') elif dir_type == AppLocation.DataDir and AppLocation.BaseDir: return os.path.join(AppLocation.BaseDir, 'data') @@ -95,6 +91,7 @@ class AppLocation(object): Return the path OpenLP stores all its data under. """ # Check if we have a different data location. + from openlp.core.lib import Settings if Settings().contains('advanced/data path'): path = Settings().value('advanced/data path') else: @@ -139,6 +136,15 @@ class AppLocation(object): return path +def get_frozen_path(frozen_option, non_frozen_option): + """ + Return a path based on the system status. + """ + if hasattr(sys, 'frozen') and sys.frozen == 1: + return frozen_option + return non_frozen_option + + def _get_os_dir_path(dir_type): """ Return a path based on which OS and environment we are running in. diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index 19cde98eb..0fff6e871 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -41,9 +41,10 @@ from sqlalchemy.pool import NullPool from alembic.migration import MigrationContext from alembic.operations import Operations +from openlp.core.common import AppLocation from openlp.core.lib import translate, Settings from openlp.core.lib.ui import critical_error_message_box -from openlp.core.utils import AppLocation, delete_file +from openlp.core.utils import delete_file log = logging.getLogger(__name__) diff --git a/openlp/core/lib/json/theme.json b/openlp/core/lib/json/theme.json new file mode 100644 index 000000000..1050458d8 --- /dev/null +++ b/openlp/core/lib/json/theme.json @@ -0,0 +1,49 @@ +{ + "background_border_color": "#000000", + "background_color": "#000000", + "background_direction": "vertical", + "background_end_color": "#000000", + "background_filename": "", + "background_start_color": "#000000", + "background_type": "solid", + "display_horizontal_align": 0, + "display_slide_transition": false, + "display_vertical_align": 0, + "font_footer_bold": false, + "font_footer_color": "#FFFFFF", + "font_footer_height": 78, + "font_footer_italics": false, + "font_footer_line_adjustment": 0, + "font_footer_location": "", + "font_footer_name": "Arial", + "font_footer_outline": false, + "font_footer_outline_color": "#000000", + "font_footer_outline_size": 2, + "font_footer_override": false, + "font_footer_shadow": true, + "font_footer_shadow_color": "#000000", + "font_footer_shadow_size": 5, + "font_footer_size": 12, + "font_footer_width": 1004, + "font_footer_x": 10, + "font_footer_y": 690, + "font_main_bold": false, + "font_main_color": "#FFFFFF", + "font_main_height": 690, + "font_main_italics": false, + "font_main_line_adjustment": 0, + "font_main_location": "", + "font_main_name": "Arial", + "font_main_outline": false, + "font_main_outline_color": "#000000", + "font_main_outline_size": 2, + "font_main_override": false, + "font_main_shadow": true, + "font_main_shadow_color": "#000000", + "font_main_shadow_size": 5, + "font_main_size": 40, + "font_main_width": 1004, + "font_main_x": 10, + "font_main_y": 10, + "theme_name": "" +} \ No newline at end of file diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 7b385d140..af7126535 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -35,7 +35,7 @@ import logging import imp from openlp.core.lib import Plugin, PluginStatus, Registry -from openlp.core.utils import AppLocation +from openlp.core.common import AppLocation log = logging.getLogger(__name__) diff --git a/openlp/core/lib/theme.py b/openlp/core/lib/theme.py index 28c0bcc91..d6e67a745 100644 --- a/openlp/core/lib/theme.py +++ b/openlp/core/lib/theme.py @@ -32,11 +32,13 @@ Provide the theme XML and handling functions for OpenLP v2 themes. import os import re import logging +import json from xml.dom.minidom import Document from lxml import etree, objectify +from openlp.core.common import AppLocation -from openlp.core.lib import str_to_bool, ScreenList +from openlp.core.lib import str_to_bool, ScreenList, get_text_file_string log = logging.getLogger(__name__) @@ -202,6 +204,8 @@ class VerticalType(object): BOOLEAN_LIST = ['bold', 'italics', 'override', 'outline', 'shadow', 'slide_transition'] +BOOLEAN_LIST2 = ['True', 'False'] + INTEGER_LIST = ['size', 'line_adjustment', 'x', 'height', 'y', 'width', 'shadow_size', 'outline_size', 'horizontal_align', 'vertical_align', 'wrap_style'] @@ -218,8 +222,12 @@ class ThemeXML(object): Initialise the theme object. """ # Create the minidom document - self.theme_xml = Document() - self.parse_xml(BLANK_THEME_XML) + json_dir = os.path.join(AppLocation.get_directory(AppLocation.AppDir), 'core', 'lib', 'json') + json_file = os.path.join(json_dir, 'theme.json') + jsn = get_text_file_string(json_file) + jsn = json.loads(jsn) + for key, value in jsn.items(): + setattr(self, key, value) def extend_image_filename(self, path): """ @@ -559,6 +567,7 @@ class ThemeXML(object): """ Create the attributes with the correct data types and name format """ + #print(master, element, value) reject, master, element, value = self._translate_tags(master, element, value) if reject: return diff --git a/openlp/core/theme/theme.py b/openlp/core/theme/theme.py deleted file mode 100644 index 7bb581512..000000000 --- a/openlp/core/theme/theme.py +++ /dev/null @@ -1,252 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2013 Raoul Snyman # -# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # -# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # -# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # -# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # -# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # -# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # -# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # -# --------------------------------------------------------------------------- # -# 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 # -############################################################################### -""" -OpenLP version 1 theme handling - -Provides reference data, a default v1 XML theme and class wrapper for -processing version 1 themes in OpenLP version 2. -""" - -from xml.etree.ElementTree import ElementTree, XML -from PyQt4 import QtGui - -DELPHI_COLORS = { - 'clAqua': 0x00FFFF, - 'clBlack': 0x000000, - 'clBlue': 0x0000FF, - 'clFuchsia': 0xFF00FF, - 'clGray': 0x808080, - 'clGreen': 0x008000, - 'clLime': 0x00FF00, - 'clMaroon': 0x800000, - 'clNavy': 0x000080, - 'clOlive': 0x808000, - 'clPurple': 0x800080, - 'clRed': 0xFF0000, - 'clSilver': 0xC0C0C0, - 'clTeal': 0x008080, - 'clWhite': 0xFFFFFF, - 'clYellow': 0xFFFF00 -} - -BLANK_STYLE_XML = \ -''' - - BlankStyle - 1 - 0 - $000000 - - - Arial - clWhite - 30 - pixels - 0 - 0 - 0 - 0 - 0 - -''' - - -class Theme(object): - """ - Provide a class wrapper storing data from an XML theme - - ``name`` - Theme name - - ``BackgroundMode`` - The behaviour of the background. Valid modes are: - - * ``0`` - Transparent - * ``1`` - Opaque - - ``BackgroundType`` - The content of the background. Valid types are: - - * ``0`` - solid color - * ``1`` - gradient color - * ``2`` - image - - ``BackgroundParameter1`` - Extra information about the background. The contents of this attribute - depend on the BackgroundType: - - * ``image`` - image filename - * ``gradient`` - start color - * ``solid`` - color - - ``BackgroundParameter2`` - Extra information about the background. The contents of this attribute - depend on the BackgroundType: - - * ``image`` - border color - * ``gradient`` - end color - * ``solid`` - N/A - - ``BackgroundParameter3`` - Extra information about the background. The contents of this attribute - depend on the BackgroundType: - - * ``image`` - N/A - * ``gradient`` - The direction of the gradient. Valid entries are: - - * ``0`` - vertical - * ``1`` - horizontal - - * ``solid`` - N/A - - ``FontName`` - Name of the font to use for the main font. - - ``FontColor`` - The color for the main font - - ``FontProportion`` - The size of the main font - - ``FontUnits`` - The units for FontProportion, either or - - ``Shadow`` - The shadow type to apply to the main font. - - * ``0`` - no shadow - * non-zero - use shadow - - ``ShadowColor`` - Color for the shadow - - ``Outline`` - The outline to apply to the main font - - * ``0`` - no outline - * non-zero - use outline - - ``OutlineColor`` - Color for the outline (or None if Outline is 0) - - ``HorizontalAlign`` - The horizontal alignment to apply to text. Valid alignments are: - - * ``0`` - left align - * ``1`` - right align - * ``2`` - centre align - - ``VerticalAlign`` - The vertical alignment to apply to the text. Valid alignments are: - - * ``0`` - top align - * ``1`` - bottom align - * ``2`` - centre align - - ``WrapStyle`` - The wrap style to apply to the text. Valid styles are: - - * ``0`` - normal - * ``1`` - lyrics - """ - - def __init__(self, xml): - """ - Initialise a theme with data from xml - - ``xml`` - The data to initialise the theme with - """ - # init to defaults - self._set_from_xml(BLANK_STYLE_XML) - self._set_from_xml(xml) - - def _get_as_string(self): - """ - Return single line string representation of a theme - """ - theme_strings = [] - keys = dir(self) - keys.sort() - for key in keys: - if key[0:1] != '_': - theme_strings.append('_%s_' % (getattr(self, key))) - return ''.join(theme_strings) - - def _set_from_xml(self, xml): - """ - Set theme class attributes with data from XML - - ``xml`` - The data to apply to the theme - """ - root = ElementTree(element=XML(xml.encode('ascii', 'xmlcharrefreplace'))) - xml_iter = root.getiterator() - for element in xml_iter: - delphi_color_change = False - if element.tag != 'Theme': - element_text = element.text - val = 0 - if element_text is None: - val = element_text - # strings need special handling to sort the colours out - if isinstance(element_text, str): - if element_text[0] == '$': - # might be a hex number - try: - val = int(element_text[1:], 16) - except ValueError: - # nope - pass - elif element_text in DELPHI_COLORS: - val = DELPHI_COLORS[element_text] - delphi_color_change = True - else: - try: - val = int(element_text) - except ValueError: - val = element_text - if (element.tag.find('Color') > 0 or (element.tag.find('BackgroundParameter') == 0 and - isinstance(val, int))): - # convert to a wx.Colour - if not delphi_color_change: - val = QtGui.QColor(val & 0xFF, (val >> 8) & 0xFF, (val >> 16) & 0xFF) - else: - val = QtGui.QColor((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF) - setattr(self, element.tag, val) - - def __str__(self): - """ - Provide Python string representation for the class (multiline output) - """ - theme_strings = [] - for key in dir(self): - if key[0:1] != '_': - theme_strings.append('%30s : %s' % (key, getattr(self, key))) - return '\n'.join(theme_strings) diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index 410a8fc16..691736c8f 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -99,10 +99,11 @@ from .formattingtagcontroller import FormattingTagController from .shortcutlistform import ShortcutListForm from .mediadockmanager import MediaDockManager from .servicemanager import ServiceManager +from .thememanagerhelper import ThemeManagerHelper from .thememanager import ThemeManager __all__ = ['SplashScreen', 'AboutForm', 'SettingsForm', 'MainDisplay', 'SlideController', 'ServiceManager', 'ThemeManager', 'MediaDockManager', 'ServiceItemEditForm', 'FirstTimeForm', 'FirstTimeLanguageForm', 'ThemeForm', 'ThemeLayoutForm', 'FileRenameForm', 'StartTimeForm', 'MainDisplay', 'Display', 'ServiceNoteForm', 'SlideController', 'DisplayController', 'GeneralTab', 'ThemesTab', 'AdvancedTab', 'PluginForm', - 'FormattingTagForm', 'ShortcutListForm', 'FormattingTagController'] + 'FormattingTagForm', 'ShortcutListForm', 'FormattingTagController', 'ThemeManagerHelper'] diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index 92f565a71..c61432c57 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -36,8 +36,9 @@ import sys from PyQt4 import QtCore, QtGui +from openlp.core.common.applocation import AppLocation from openlp.core.lib import SettingsTab, Settings, UiStrings, translate, build_icon -from openlp.core.utils import AppLocation, format_time, get_images_filter +from openlp.core.utils import format_time, get_images_filter from openlp.core.lib import SlideLimits log = logging.getLogger(__name__) diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 509316658..182894037 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -41,8 +41,9 @@ from configparser import SafeConfigParser from PyQt4 import QtCore, QtGui +from openlp.core.common.applocation import AppLocation from openlp.core.lib import PluginStatus, Settings, Registry, build_icon, check_directory_exists, translate -from openlp.core.utils import AppLocation, get_web_page +from openlp.core.utils import get_web_page from .firsttimewizard import Ui_FirstTimeWizard, FirstTimePage log = logging.getLogger(__name__) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index edd898be1..37d215c85 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -46,8 +46,10 @@ from openlp.core.lib import Renderer, OpenLPDockWidget, PluginManager, ImageMana from openlp.core.lib.ui import UiStrings, create_action from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, SlideController, PluginForm, \ MediaDockManager, ShortcutListForm, FormattingTagForm + +from openlp.core.common.applocation import AppLocation from openlp.core.ui.media import MediaController -from openlp.core.utils import AppLocation, LanguageManager, add_actions, get_application_version +from openlp.core.utils import LanguageManager, add_actions, get_application_version from openlp.core.utils.actions import ActionList, CategoryOrder from openlp.core.ui.firsttimeform import FirstTimeForm diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index b1fa43ea9..83b9630fc 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -39,7 +39,7 @@ from openlp.core.lib import OpenLPToolbar, Settings, Registry, UiStrings, transl from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.media import MediaState, MediaInfo, MediaType, get_media_players, set_media_players from openlp.core.ui.media.mediaplayer import MediaPlayer -from openlp.core.utils import AppLocation +from openlp.core.common import AppLocation from openlp.core.ui import DisplayControllerType log = logging.getLogger(__name__) diff --git a/openlp/core/ui/printserviceform.py b/openlp/core/ui/printserviceform.py index 660b708d8..153b6bed9 100644 --- a/openlp/core/ui/printserviceform.py +++ b/openlp/core/ui/printserviceform.py @@ -38,7 +38,7 @@ from lxml import html from openlp.core.lib import Settings, UiStrings, Registry, translate, get_text_file_string from openlp.core.ui.printservicedialog import Ui_PrintServiceDialog, ZoomSize -from openlp.core.utils import AppLocation +from openlp.core.common import AppLocation DEFAULT_CSS = """/* Edit this file to customize the service order print. Note, that not all CSS diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index c00f4159b..7610b8dcb 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -42,13 +42,14 @@ log = logging.getLogger(__name__) from PyQt4 import QtCore, QtGui +from openlp.core.common.applocation import AppLocation from openlp.core.lib import OpenLPToolbar, ServiceItem, ItemCapabilities, Settings, PluginStatus, Registry, \ UiStrings, build_icon, translate, str_to_bool, check_directory_exists from openlp.core.lib.theme import ThemeLevel from openlp.core.lib.ui import critical_error_message_box, create_widget_action, find_and_set_in_combo_box from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm from openlp.core.ui.printserviceform import PrintServiceForm -from openlp.core.utils import AppLocation, delete_file, split_filename, format_time +from openlp.core.utils import delete_file, split_filename, format_time from openlp.core.utils.actions import ActionList, CategoryOrder diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index cbc6701df..2b2f6f855 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -38,18 +38,18 @@ import re from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui +from openlp.core.common.applocation import AppLocation from openlp.core.lib import ImageSource, OpenLPToolbar, Registry, Settings, UiStrings, get_text_file_string, \ build_icon, translate, check_item_selected, check_directory_exists, create_thumb, validate_thumb -from openlp.core.lib.theme import ThemeXML, BackgroundType, VerticalType, BackgroundGradientType +from openlp.core.lib.theme import ThemeXML, BackgroundType from openlp.core.lib.ui import critical_error_message_box, create_widget_action -from openlp.core.theme import Theme -from openlp.core.ui import FileRenameForm, ThemeForm -from openlp.core.utils import AppLocation, delete_file, get_locale_key, get_filesystem_encoding +from openlp.core.ui import FileRenameForm, ThemeForm, ThemeManagerHelper +from openlp.core.utils import delete_file, get_locale_key, get_filesystem_encoding log = logging.getLogger(__name__) -class ThemeManager(QtGui.QWidget): +class ThemeManager(QtGui.QWidget, ThemeManagerHelper): """ Manages the orders of Theme. """ @@ -328,8 +328,8 @@ class ThemeManager(QtGui.QWidget): try: encoding = get_filesystem_encoding() shutil.rmtree(os.path.join(self.path, theme).encode(encoding)) - except OSError as xxx_todo_changeme1: - shutil.Error = xxx_todo_changeme1 + except OSError as os_error: + shutil.Error = os_error log.exception('Error deleting theme %s', theme) def on_export_theme(self): @@ -469,7 +469,7 @@ class ThemeManager(QtGui.QWidget): log.debug('No theme data - using default theme') return ThemeXML() else: - return self._create_theme_fom_Xml(xml, self.path) + return self._create_theme_from_Xml(xml, self.path) def over_write_message_box(self, theme_name): """ @@ -501,35 +501,30 @@ class ThemeManager(QtGui.QWidget): log.exception('Theme contains "%s" XML files' % len(xml_file)) raise Exception('validation') xml_tree = ElementTree(element=XML(theme_zip.read(xml_file[0]))).getroot() - v1_background = xml_tree.find('BackgroundType') - if v1_background is not None: - theme_name, file_xml, out_file, abort_import = \ - self.unzip_version_122(directory, theme_zip, xml_file[0], xml_tree, v1_background, out_file) + theme_name = xml_tree.find('name').text.strip() + theme_folder = os.path.join(directory, theme_name) + theme_exists = os.path.exists(theme_folder) + if theme_exists and not self.over_write_message_box(theme_name): + abort_import = True + return else: - theme_name = xml_tree.find('name').text.strip() - theme_folder = os.path.join(directory, theme_name) - theme_exists = os.path.exists(theme_folder) - if theme_exists and not self.over_write_message_box(theme_name): - abort_import = True - return + abort_import = False + for name in theme_zip.namelist(): + name = name.replace('/', os.path.sep) + split_name = name.split(os.path.sep) + if split_name[-1] == '' or len(split_name) == 1: + # is directory or preview file + continue + full_name = os.path.join(directory, name) + check_directory_exists(os.path.dirname(full_name)) + if os.path.splitext(name)[1].lower() == '.xml': + file_xml = str(theme_zip.read(name), 'utf-8') + out_file = open(full_name, 'w') + out_file.write(file_xml) else: - abort_import = False - for name in theme_zip.namelist(): - name = name.replace('/', os.path.sep) - split_name = name.split(os.path.sep) - if split_name[-1] == '' or len(split_name) == 1: - # is directory or preview file - continue - full_name = os.path.join(directory, name) - check_directory_exists(os.path.dirname(full_name)) - if os.path.splitext(name)[1].lower() == '.xml': - file_xml = str(theme_zip.read(name), 'utf-8') - out_file = open(full_name, 'w') - out_file.write(file_xml) - else: - out_file = open(full_name, 'wb') - out_file.write(theme_zip.read(name)) - out_file.close() + out_file = open(full_name, 'wb') + out_file.write(theme_zip.read(name)) + out_file.close() except (IOError, zipfile.BadZipfile): log.exception('Importing theme from zip failed %s' % file_name) raise Exception('validation') @@ -548,7 +543,7 @@ class ThemeManager(QtGui.QWidget): if not abort_import: # As all files are closed, we can create the Theme. if file_xml: - theme = self._create_theme_fom_Xml(file_xml, self.path) + theme = self._create_theme_from_Xml(file_xml, self.path) self.generate_and_save_image(directory, theme_name, theme) # Only show the error message, when IOError was not raised (in # this case the error message has already been shown). @@ -558,38 +553,6 @@ class ThemeManager(QtGui.QWidget): translate('OpenLP.ThemeManager', 'File is not a valid theme.')) log.exception('Theme file does not contain XML data %s' % file_name) - def unzip_version_122(self, dir_name, zip_file, xml_file, xml_tree, background, out_file): - """ - Unzip openlp.org 1.2x theme file and upgrade the theme xml. When calling - this method, please keep in mind, that some parameters are redundant. - """ - theme_name = xml_tree.find('Name').text.strip() - theme_name = self.bad_v1_name_chars.sub('', theme_name) - theme_folder = os.path.join(dir_name, theme_name) - theme_exists = os.path.exists(theme_folder) - if theme_exists and not self.over_write_message_box(theme_name): - return '', '', '', True - themedir = os.path.join(dir_name, theme_name) - check_directory_exists(themedir) - file_xml = str(zip_file.read(xml_file), 'utf-8') - file_xml = self._migrate_version_122(file_xml) - out_file = open(os.path.join(themedir, theme_name + '.xml'), 'w') - out_file.write(file_xml.encode('utf-8')) - out_file.close() - if background.text.strip() == '2': - image_name = xml_tree.find('BackgroundParameter1').text.strip() - # image file has same extension and is in subfolder - image_file = [name for name in zip_file.namelist() if os.path.splitext(name)[1].lower() - == os.path.splitext(image_name)[1].lower() and name.find(r'/')] - if len(image_file) >= 1: - out_file = open(os.path.join(themedir, image_name), 'wb') - out_file.write(zip_file.read(image_file[0])) - out_file.close() - else: - log.exception('Theme file does not contain image file "%s"' % image_name.decode('utf-8', 'replace')) - raise Exception('validation') - return theme_name, file_xml, out_file, False - def check_if_theme_exists(self, theme_name): """ Check if theme already exists and displays error message @@ -697,7 +660,7 @@ class ThemeManager(QtGui.QWidget): image = os.path.join(self.path, theme + '.png') return image - def _create_theme_fom_Xml(self, theme_xml, path): + def _create_theme_from_Xml(self, theme_xml, path): """ Return a theme object using information parsed from XML @@ -741,55 +704,6 @@ class ThemeManager(QtGui.QWidget): return True return False - def _migrate_version_122(self, xml_data): - """ - Convert the xml data from version 1 format to the current format. - - New fields are loaded with defaults to provide a complete, working - theme containing all compatible customisations from the old theme. - - ``xml_data`` - Version 1 theme to convert - """ - theme = Theme(xml_data) - new_theme = ThemeXML() - new_theme.theme_name = self.bad_v1_name_chars.sub('', theme.Name) - if theme.BackgroundType == BackgroundType.Solid: - new_theme.background_type = BackgroundType.to_string(BackgroundType.Solid) - new_theme.background_color = str(theme.BackgroundParameter1.name()) - elif theme.BackgroundType == BackgroundType.Horizontal: - new_theme.background_type = BackgroundType.to_string(BackgroundType.Gradient) - new_theme.background_direction = BackgroundGradientType.to_string(BackgroundGradientType.Horizontal) - if theme.BackgroundParameter3.name() == 1: - new_theme.background_direction = BackgroundGradientType.to_string(BackgroundGradientType.Horizontal) - new_theme.background_start_color = str(theme.BackgroundParameter1.name()) - new_theme.background_end_color = str(theme.BackgroundParameter2.name()) - elif theme.BackgroundType == BackgroundType.Image: - new_theme.background_type = BackgroundType.to_string(BackgroundType.Image) - new_theme.background_filename = str(theme.BackgroundParameter1) - elif theme.BackgroundType == BackgroundType.Transparent: - new_theme.background_type = BackgroundType.to_string(BackgroundType.Transparent) - new_theme.font_main_name = theme.FontName - new_theme.font_main_color = str(theme.FontColor.name()) - new_theme.font_main_size = theme.FontProportion * 3 - new_theme.font_footer_name = theme.FontName - new_theme.font_footer_color = str(theme.FontColor.name()) - new_theme.font_main_shadow = False - if theme.Shadow == 1: - new_theme.font_main_shadow = True - new_theme.font_main_shadow_color = str(theme.ShadowColor.name()) - if theme.Outline == 1: - new_theme.font_main_outline = True - new_theme.font_main_outline_color = str(theme.OutlineColor.name()) - vAlignCorrection = VerticalType.Top - if theme.VerticalAlign == 2: - vAlignCorrection = VerticalType.Middle - elif theme.VerticalAlign == 1: - vAlignCorrection = VerticalType.Bottom - new_theme.display_horizontal_align = theme.HorizontalAlign - new_theme.display_vertical_align = vAlignCorrection - return new_theme.extract_xml() - def _get_renderer(self): """ Adds the Renderer to the class dynamically diff --git a/openlp/core/ui/thememanagerhelper.py b/openlp/core/ui/thememanagerhelper.py new file mode 100644 index 000000000..8fa02bde5 --- /dev/null +++ b/openlp/core/ui/thememanagerhelper.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 Theme Controller helps manages adding, deleteing and modifying of themes. +""" + + +class ThemeManagerHelper(object): + """ + Manages the non ui theme functions. + """ + pass \ No newline at end of file diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index d2e664e75..d07153a2a 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -37,10 +37,13 @@ import os import re from subprocess import Popen, PIPE import sys -import urllib.request, urllib.error, urllib.parse +import urllib.request +import urllib.error +import urllib.parse from PyQt4 import QtGui, QtCore +from openlp.core.common import AppLocation from openlp.core.lib import Registry, Settings @@ -81,15 +84,6 @@ class VersionThread(QtCore.QThread): Registry().execute('openlp_version_check', '%s' % version) -def _get_frozen_path(frozen_option, non_frozen_option): - """ - Return a path based on the system status. - """ - if hasattr(sys, 'frozen') and sys.frozen == 1: - return frozen_option - return non_frozen_option - - def get_application_version(): """ Returns the application version of the running instance of OpenLP:: @@ -418,18 +412,17 @@ def get_natural_key(string): """ key = DIGITS_OR_NONDIGITS.findall(string) key = [int(part) if part.isdigit() else get_locale_key(part) for part in key] - # Python 3 does not support comparision of different types anymore. So make sure, that we do not compare str + # Python 3 does not support comparison of different types anymore. So make sure, that we do not compare str # and int. if string[0].isdigit(): return [b''] + key return key -from .applocation import AppLocation from .languagemanager import LanguageManager from .actions import ActionList -__all__ = ['AppLocation', 'ActionList', 'LanguageManager', 'get_application_version', 'check_latest_version', +__all__ = ['ActionList', 'LanguageManager', 'get_application_version', 'check_latest_version', 'add_actions', 'get_filesystem_encoding', 'get_web_page', 'get_uno_command', 'get_uno_instance', 'delete_file', 'clean_filename', 'format_time', 'get_locale_key', 'get_natural_key'] diff --git a/openlp/core/utils/languagemanager.py b/openlp/core/utils/languagemanager.py index ed58cc037..d6b3cd668 100644 --- a/openlp/core/utils/languagemanager.py +++ b/openlp/core/utils/languagemanager.py @@ -35,7 +35,7 @@ import sys from PyQt4 import QtCore, QtGui -from openlp.core.utils import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Settings, translate log = logging.getLogger(__name__) diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index 459fcbe8b..a4c275005 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -34,11 +34,12 @@ import os from PyQt4 import QtCore, QtGui +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Settings, UiStrings, translate from openlp.core.lib.db import delete_database from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings -from openlp.core.utils import AppLocation, get_locale_key +from openlp.core.utils import get_locale_key from openlp.plugins.bibles.lib.manager import BibleFormat from openlp.plugins.bibles.lib.db import BiblesResourcesDB, clean_filename diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index 299387e67..fc3508d8e 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -36,10 +36,11 @@ from tempfile import gettempdir from PyQt4 import QtCore, QtGui +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Registry, Settings, UiStrings, translate, check_directory_exists from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings -from openlp.core.utils import AppLocation, delete_file +from openlp.core.utils import delete_file from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta, OldBibleDB, BiblesResourcesDB from openlp.plugins.bibles.lib.http import BSExtract, BGExtract, CWExtract diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 8eaabd5ed..858bd6909 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -38,10 +38,11 @@ from sqlalchemy import Column, ForeignKey, Table, or_, types, func from sqlalchemy.orm import class_mapper, mapper, relation from sqlalchemy.orm.exc import UnmappedClassError +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Registry, translate from openlp.core.lib.db import BaseModel, init_db, Manager from openlp.core.lib.ui import critical_error_message_box -from openlp.core.utils import AppLocation, clean_filename +from openlp.core.utils import clean_filename from . import upgrade log = logging.getLogger(__name__) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 3ee4862ec..f648bfaa1 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -30,8 +30,9 @@ import logging import os +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Registry, Settings, translate -from openlp.core.utils import AppLocation, delete_file +from openlp.core.utils import delete_file from openlp.plugins.bibles.lib import parse_reference, get_reference_separator, LanguageSelection from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta from .csvbible import CSVBible diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 6184bff05..c2ce24da6 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -33,8 +33,8 @@ import chardet import codecs import re +from openlp.core.common import AppLocation from openlp.core.lib import translate -from openlp.core.utils import AppLocation from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB log = logging.getLogger(__name__) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 70d4630a0..721018900 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -32,11 +32,12 @@ import os from PyQt4 import QtCore, QtGui +from openlp.core.common.applocation import AppLocation from openlp.core.lib import ItemCapabilities, MediaManagerItem, Registry, ServiceItemContext, Settings, \ StringContent, TreeWidgetWithDnD, UiStrings, build_icon, check_directory_exists, check_item_selected, \ create_thumb, translate, validate_thumb from openlp.core.lib.ui import create_widget_action, critical_error_message_box -from openlp.core.utils import AppLocation, delete_file, get_locale_key, get_images_filter +from openlp.core.utils import delete_file, get_locale_key, get_images_filter from openlp.plugins.images.forms import AddGroupForm, ChooseGroupForm from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 4f173db84..929e1a32c 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -32,12 +32,13 @@ import os from PyQt4 import QtCore, QtGui +from openlp.core.common.applocation import AppLocation from openlp.core.lib import ItemCapabilities, MediaManagerItem,MediaType, Registry, ServiceItem, ServiceItemContext, \ Settings, UiStrings, build_icon, check_item_selected, check_directory_exists, translate from openlp.core.lib.ui import critical_error_message_box, create_horizontal_adjusting_combo_box from openlp.core.ui import DisplayController, Display, DisplayControllerType from openlp.core.ui.media import get_media_players, set_media_players -from openlp.core.utils import AppLocation, get_locale_key +from openlp.core.utils import get_locale_key log = logging.getLogger(__name__) diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index 0a70b174a..d5ac16314 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -33,8 +33,8 @@ import shutil from PyQt4 import QtCore +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Registry, Settings, check_directory_exists, create_thumb, validate_thumb -from openlp.core.utils import AppLocation log = logging.getLogger(__name__) diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index be5d3f52d..20d07f0d7 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -35,8 +35,8 @@ import logging from PyQt4 import QtCore +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Plugin, StringContent, build_icon, translate -from openlp.core.utils import AppLocation from openlp.plugins.presentations.lib import PresentationController, PresentationMediaItem, PresentationTab diff --git a/openlp/plugins/remotes/lib/httprouter.py b/openlp/plugins/remotes/lib/httprouter.py index f12fbb290..e6667c119 100644 --- a/openlp/plugins/remotes/lib/httprouter.py +++ b/openlp/plugins/remotes/lib/httprouter.py @@ -121,12 +121,12 @@ import urllib.request import urllib.error from urllib.parse import urlparse, parse_qs - from mako.template import Template from PyQt4 import QtCore +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Registry, Settings, PluginStatus, StringContent, image_to_byte -from openlp.core.utils import AppLocation, translate +from openlp.core.utils import translate log = logging.getLogger(__name__) diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 7776812fa..f2c641bb0 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -37,12 +37,11 @@ import ssl import socket import os import logging -from urllib.parse import urlparse, parse_qs from PyQt4 import QtCore +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Settings -from openlp.core.utils import AppLocation from openlp.plugins.remotes.lib import HttpRouter diff --git a/openlp/plugins/remotes/lib/remotetab.py b/openlp/plugins/remotes/lib/remotetab.py index 17d368bd2..837d63053 100644 --- a/openlp/plugins/remotes/lib/remotetab.py +++ b/openlp/plugins/remotes/lib/remotetab.py @@ -31,9 +31,8 @@ import os.path from PyQt4 import QtCore, QtGui, QtNetwork +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Settings, SettingsTab, translate -from openlp.core.utils import AppLocation - ZERO_URL = '0.0.0.0' diff --git a/openlp/plugins/songs/forms/duplicatesongremovalform.py b/openlp/plugins/songs/forms/duplicatesongremovalform.py index e058089aa..190bbea79 100644 --- a/openlp/plugins/songs/forms/duplicatesongremovalform.py +++ b/openlp/plugins/songs/forms/duplicatesongremovalform.py @@ -35,9 +35,9 @@ import os from PyQt4 import QtCore, QtGui +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Registry, translate from openlp.core.ui.wizard import OpenLPWizard, WizardStrings -from openlp.core.utils import AppLocation from openlp.plugins.songs.lib import delete_song from openlp.plugins.songs.lib.db import Song, MediaFile from openlp.plugins.songs.forms.songreviewwidget import SongReviewWidget diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 66f71545f..cf0ab94cf 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -38,10 +38,10 @@ import shutil from PyQt4 import QtCore, QtGui +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Registry, PluginStatus, MediaType, UiStrings, translate, create_separated_list, \ check_directory_exists from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box -from openlp.core.utils import AppLocation from openlp.plugins.songs.lib import VerseType, clean_song from openlp.plugins.songs.lib.db import Book, Song, Author, Topic, MediaFile from openlp.plugins.songs.lib.ui import SongStrings diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index 12874aa89..1ae645e09 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -36,8 +36,9 @@ import re from PyQt4 import QtGui +from openlp.core.common.applocation import AppLocation from openlp.core.lib import translate -from openlp.core.utils import AppLocation, CONTROL_CHARS +from openlp.core.utils import CONTROL_CHARS from openlp.plugins.songs.lib.db import MediaFile, Song from .db import Author from .ui import SongStrings diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 957edbca0..469cb1258 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -35,10 +35,10 @@ import shutil from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_ +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, PluginStatus, ServiceItemContext, Settings, \ UiStrings, translate, check_item_selected, create_separated_list, check_directory_exists from openlp.core.lib.ui import create_widget_action -from openlp.core.utils import AppLocation from openlp.plugins.songs.forms.editsongform import EditSongForm from openlp.plugins.songs.forms.songmaintenanceform import SongMaintenanceForm from openlp.plugins.songs.forms.songimportform import SongImportForm diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 2381959ad..04b8a2baa 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -34,9 +34,9 @@ import os from PyQt4 import QtCore +from openlp.core.common.applocation import AppLocation from openlp.core.lib import Registry, translate, check_directory_exists from openlp.core.ui.wizard import WizardStrings -from openlp.core.utils import AppLocation from openlp.plugins.songs.lib import clean_song, VerseType from openlp.plugins.songs.lib.db import Song, Author, Topic, Book, MediaFile from openlp.plugins.songs.lib.ui import SongStrings diff --git a/tests/functional/openlp_core_utils/test_applocation.py b/tests/functional/openlp_core_utils/test_applocation.py index d34c0cfa5..4e2caae47 100644 --- a/tests/functional/openlp_core_utils/test_applocation.py +++ b/tests/functional/openlp_core_utils/test_applocation.py @@ -32,7 +32,7 @@ Functional tests to test the AppLocation class and related methods. import copy from unittest import TestCase -from openlp.core.utils import AppLocation +from openlp.core.common.applocation import AppLocation from tests.functional import patch FILE_LIST = ['file1', 'file2', 'file3.txt', 'file4.txt', 'file5.mp3', 'file6.mp3'] diff --git a/tests/functional/openlp_plugins/remotes/test_remotetab.py b/tests/functional/openlp_plugins/remotes/test_remotetab.py index 86652ffa4..51198bdc2 100644 --- a/tests/functional/openlp_plugins/remotes/test_remotetab.py +++ b/tests/functional/openlp_plugins/remotes/test_remotetab.py @@ -105,10 +105,10 @@ class TestRemoteTab(TestCase): Test the set_urls function with standard defaults """ # GIVEN: A mocked location - with patch('openlp.core.utils.applocation.Settings') as mocked_class, \ + with patch('openlp.core.common.applocation.Settings') as mocked_class, \ patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ - patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \ - patch('openlp.core.utils.applocation.os') as mocked_os: + patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists, \ + patch('openlp.core.common.applocation.os') as mocked_os: # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() mocked_settings = mocked_class.return_value mocked_settings.contains.return_value = False @@ -133,10 +133,10 @@ class TestRemoteTab(TestCase): Test the set_urls function with certificate available """ # GIVEN: A mocked location - with patch('openlp.core.utils.applocation.Settings') as mocked_class, \ + with patch('openlp.core.common.applocation.Settings') as mocked_class, \ patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ - patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \ - patch('openlp.core.utils.applocation.os') as mocked_os: + patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists, \ + patch('openlp.core.common.applocation.os') as mocked_os: # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() mocked_settings = mocked_class.return_value mocked_settings.contains.return_value = False From b860abb23bd48e2c4e798860703edad0662be8a1 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 13 Oct 2013 16:52:04 +0100 Subject: [PATCH 22/46] fix fields --- openlp/core/common/__init__.py | 2 +- openlp/core/lib/json/theme.json | 2 +- openlp/core/lib/theme.py | 50 +------------------ openlp/core/ui/advancedtab.py | 2 +- openlp/core/ui/firsttimeform.py | 2 +- openlp/core/ui/mainwindow.py | 2 +- openlp/core/ui/servicemanager.py | 2 +- openlp/core/ui/thememanager.py | 2 +- .../plugins/bibles/forms/bibleimportform.py | 4 +- .../plugins/bibles/forms/bibleupgradeform.py | 2 +- openlp/plugins/bibles/lib/db.py | 2 +- openlp/plugins/bibles/lib/manager.py | 2 +- openlp/plugins/images/lib/mediaitem.py | 2 +- openlp/plugins/media/lib/mediaitem.py | 2 +- .../lib/presentationcontroller.py | 2 +- .../presentations/presentationplugin.py | 2 +- openlp/plugins/remotes/lib/httprouter.py | 2 +- openlp/plugins/remotes/lib/httpserver.py | 2 +- openlp/plugins/remotes/lib/remotetab.py | 2 +- .../songs/forms/duplicatesongremovalform.py | 2 +- openlp/plugins/songs/forms/editsongform.py | 2 +- openlp/plugins/songs/lib/__init__.py | 2 +- openlp/plugins/songs/lib/mediaitem.py | 2 +- openlp/plugins/songs/lib/songimport.py | 2 +- .../openlp_core_utils/test_applocation.py | 2 +- 25 files changed, 26 insertions(+), 74 deletions(-) diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index e2c95b6cc..1f205c958 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -54,4 +54,4 @@ def check_directory_exists(directory, do_not_log=False): except IOError: pass -from .applocation import AppLocation \ No newline at end of file +from .applocation import AppLocation diff --git a/openlp/core/lib/json/theme.json b/openlp/core/lib/json/theme.json index 1050458d8..9991f2b53 100644 --- a/openlp/core/lib/json/theme.json +++ b/openlp/core/lib/json/theme.json @@ -46,4 +46,4 @@ "font_main_x": 10, "font_main_y": 10, "theme_name": "" -} \ No newline at end of file +} diff --git a/openlp/core/lib/theme.py b/openlp/core/lib/theme.py index d6e67a745..c10a59560 100644 --- a/openlp/core/lib/theme.py +++ b/openlp/core/lib/theme.py @@ -42,52 +42,6 @@ from openlp.core.lib import str_to_bool, ScreenList, get_text_file_string log = logging.getLogger(__name__) -BLANK_THEME_XML = \ -''' - - - - - #000000 - - - #000000 - #000000 - vertical - - - #000000 - - - Arial - #FFFFFF - 40 - False - False - 0 - True - False - - - - Arial - #FFFFFF - 12 - False - False - 0 - True - False - - - - 0 - 0 - False - - -''' - class ThemeLevel(object): """ @@ -204,8 +158,6 @@ class VerticalType(object): BOOLEAN_LIST = ['bold', 'italics', 'override', 'outline', 'shadow', 'slide_transition'] -BOOLEAN_LIST2 = ['True', 'False'] - INTEGER_LIST = ['size', 'line_adjustment', 'x', 'height', 'y', 'width', 'shadow_size', 'outline_size', 'horizontal_align', 'vertical_align', 'wrap_style'] @@ -221,7 +173,7 @@ class ThemeXML(object): """ Initialise the theme object. """ - # Create the minidom document + # basic theme object with defaults json_dir = os.path.join(AppLocation.get_directory(AppLocation.AppDir), 'core', 'lib', 'json') json_file = os.path.join(json_dir, 'theme.json') jsn = get_text_file_string(json_file) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index c61432c57..fbd44a9f8 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -36,7 +36,7 @@ import sys from PyQt4 import QtCore, QtGui -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import SettingsTab, Settings, UiStrings, translate, build_icon from openlp.core.utils import format_time, get_images_filter from openlp.core.lib import SlideLimits diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 182894037..062af6447 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -41,7 +41,7 @@ from configparser import SafeConfigParser from PyQt4 import QtCore, QtGui -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import PluginStatus, Settings, Registry, build_icon, check_directory_exists, translate from openlp.core.utils import get_web_page from .firsttimewizard import Ui_FirstTimeWizard, FirstTimePage diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 37d215c85..7cb4de6cf 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -47,7 +47,7 @@ from openlp.core.lib.ui import UiStrings, create_action from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, SlideController, PluginForm, \ MediaDockManager, ShortcutListForm, FormattingTagForm -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.ui.media import MediaController from openlp.core.utils import LanguageManager, add_actions, get_application_version from openlp.core.utils.actions import ActionList, CategoryOrder diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 7610b8dcb..94f6b512d 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -42,7 +42,7 @@ log = logging.getLogger(__name__) from PyQt4 import QtCore, QtGui -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import OpenLPToolbar, ServiceItem, ItemCapabilities, Settings, PluginStatus, Registry, \ UiStrings, build_icon, translate, str_to_bool, check_directory_exists from openlp.core.lib.theme import ThemeLevel diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 2b2f6f855..3b07d0ed9 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -38,7 +38,7 @@ import re from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import ImageSource, OpenLPToolbar, Registry, Settings, UiStrings, get_text_file_string, \ build_icon, translate, check_item_selected, check_directory_exists, create_thumb, validate_thumb from openlp.core.lib.theme import ThemeXML, BackgroundType diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index a4c275005..93bb5d565 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -32,9 +32,9 @@ The bible import functions for OpenLP import logging import os -from PyQt4 import QtCore, QtGui +from PyQt4 import QtGui -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Settings, UiStrings, translate from openlp.core.lib.db import delete_database from openlp.core.lib.ui import critical_error_message_box diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index fc3508d8e..2962eee9d 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -36,7 +36,7 @@ from tempfile import gettempdir from PyQt4 import QtCore, QtGui -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Registry, Settings, UiStrings, translate, check_directory_exists from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 858bd6909..89ff8a61a 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -38,7 +38,7 @@ from sqlalchemy import Column, ForeignKey, Table, or_, types, func from sqlalchemy.orm import class_mapper, mapper, relation from sqlalchemy.orm.exc import UnmappedClassError -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Registry, translate from openlp.core.lib.db import BaseModel, init_db, Manager from openlp.core.lib.ui import critical_error_message_box diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index f648bfaa1..a05d0c301 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -30,7 +30,7 @@ import logging import os -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Registry, Settings, translate from openlp.core.utils import delete_file from openlp.plugins.bibles.lib import parse_reference, get_reference_separator, LanguageSelection diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 721018900..9aeeeaee6 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -32,7 +32,7 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import ItemCapabilities, MediaManagerItem, Registry, ServiceItemContext, Settings, \ StringContent, TreeWidgetWithDnD, UiStrings, build_icon, check_directory_exists, check_item_selected, \ create_thumb, translate, validate_thumb diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 929e1a32c..7464bd178 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -32,7 +32,7 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import ItemCapabilities, MediaManagerItem,MediaType, Registry, ServiceItem, ServiceItemContext, \ Settings, UiStrings, build_icon, check_item_selected, check_directory_exists, translate from openlp.core.lib.ui import critical_error_message_box, create_horizontal_adjusting_combo_box diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index d5ac16314..b850820c5 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -33,7 +33,7 @@ import shutil from PyQt4 import QtCore -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Registry, Settings, check_directory_exists, create_thumb, validate_thumb log = logging.getLogger(__name__) diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index 20d07f0d7..e37312095 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -35,7 +35,7 @@ import logging from PyQt4 import QtCore -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Plugin, StringContent, build_icon, translate from openlp.plugins.presentations.lib import PresentationController, PresentationMediaItem, PresentationTab diff --git a/openlp/plugins/remotes/lib/httprouter.py b/openlp/plugins/remotes/lib/httprouter.py index e6667c119..42b45abc6 100644 --- a/openlp/plugins/remotes/lib/httprouter.py +++ b/openlp/plugins/remotes/lib/httprouter.py @@ -124,7 +124,7 @@ from urllib.parse import urlparse, parse_qs from mako.template import Template from PyQt4 import QtCore -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Registry, Settings, PluginStatus, StringContent, image_to_byte from openlp.core.utils import translate diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index f2c641bb0..a8453fb2b 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -40,7 +40,7 @@ import logging from PyQt4 import QtCore -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Settings from openlp.plugins.remotes.lib import HttpRouter diff --git a/openlp/plugins/remotes/lib/remotetab.py b/openlp/plugins/remotes/lib/remotetab.py index 837d63053..d7ae97342 100644 --- a/openlp/plugins/remotes/lib/remotetab.py +++ b/openlp/plugins/remotes/lib/remotetab.py @@ -31,7 +31,7 @@ import os.path from PyQt4 import QtCore, QtGui, QtNetwork -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Settings, SettingsTab, translate ZERO_URL = '0.0.0.0' diff --git a/openlp/plugins/songs/forms/duplicatesongremovalform.py b/openlp/plugins/songs/forms/duplicatesongremovalform.py index 190bbea79..f4121c85a 100644 --- a/openlp/plugins/songs/forms/duplicatesongremovalform.py +++ b/openlp/plugins/songs/forms/duplicatesongremovalform.py @@ -35,7 +35,6 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.common.applocation import AppLocation from openlp.core.lib import Registry, translate from openlp.core.ui.wizard import OpenLPWizard, WizardStrings from openlp.plugins.songs.lib import delete_song @@ -45,6 +44,7 @@ from openlp.plugins.songs.lib.songcompare import songs_probably_equal log = logging.getLogger(__name__) + class DuplicateSongRemovalForm(OpenLPWizard): """ This is the Duplicate Song Removal Wizard. It provides functionality to diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index cf0ab94cf..cd44baf4f 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -38,7 +38,7 @@ import shutil from PyQt4 import QtCore, QtGui -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Registry, PluginStatus, MediaType, UiStrings, translate, create_separated_list, \ check_directory_exists from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index 1ae645e09..d2c25bd15 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -36,7 +36,7 @@ import re from PyQt4 import QtGui -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import translate from openlp.core.utils import CONTROL_CHARS from openlp.plugins.songs.lib.db import MediaFile, Song diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 469cb1258..b376c541b 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -35,7 +35,7 @@ import shutil from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_ -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, PluginStatus, ServiceItemContext, Settings, \ UiStrings, translate, check_item_selected, create_separated_list, check_directory_exists from openlp.core.lib.ui import create_widget_action diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 04b8a2baa..74e2a0272 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -34,7 +34,7 @@ import os from PyQt4 import QtCore -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from openlp.core.lib import Registry, translate, check_directory_exists from openlp.core.ui.wizard import WizardStrings from openlp.plugins.songs.lib import clean_song, VerseType diff --git a/tests/functional/openlp_core_utils/test_applocation.py b/tests/functional/openlp_core_utils/test_applocation.py index 4e2caae47..a79d5cefc 100644 --- a/tests/functional/openlp_core_utils/test_applocation.py +++ b/tests/functional/openlp_core_utils/test_applocation.py @@ -32,7 +32,7 @@ Functional tests to test the AppLocation class and related methods. import copy from unittest import TestCase -from openlp.core.common.applocation import AppLocation +from openlp.core.common import AppLocation from tests.functional import patch FILE_LIST = ['file1', 'file2', 'file3.txt', 'file4.txt', 'file5.mp3', 'file6.mp3'] From a013d17bdd5fe576e99ab02d55dde992f07ca27e Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 13 Oct 2013 18:02:12 +0100 Subject: [PATCH 23/46] fix tests and add basic test --- openlp/core/common/__init__.py | 10 +++ openlp/core/common/applocation.py | 12 +--- .../functional/openlp_core_common/__init__.py | 1 + .../test_applocation.py | 64 +++++++++++++----- .../functional/openlp_core_lib/test_theme.py | 65 +++++++++++++++++++ .../openlp_core_utils/test_utils.py | 30 +-------- .../openlp_plugins/remotes/test_remotetab.py | 4 +- 7 files changed, 126 insertions(+), 60 deletions(-) create mode 100644 tests/functional/openlp_core_common/__init__.py rename tests/functional/{openlp_core_utils => openlp_core_common}/test_applocation.py (74%) create mode 100644 tests/functional/openlp_core_lib/test_theme.py diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index 1f205c958..02fab3512 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -32,6 +32,7 @@ OpenLP work. """ import os import logging +import sys log = logging.getLogger(__name__) @@ -54,4 +55,13 @@ def check_directory_exists(directory, do_not_log=False): except IOError: pass + +def get_frozen_path(frozen_option, non_frozen_option): + """ + Return a path based on the system status. + """ + if hasattr(sys, 'frozen') and sys.frozen == 1: + return frozen_option + return non_frozen_option + from .applocation import AppLocation diff --git a/openlp/core/common/applocation.py b/openlp/core/common/applocation.py index 7d0010316..8925b4c59 100644 --- a/openlp/core/common/applocation.py +++ b/openlp/core/common/applocation.py @@ -41,7 +41,7 @@ if sys.platform != 'win32' and sys.platform != 'darwin': XDG_BASE_AVAILABLE = False import openlp -from openlp.core.common import check_directory_exists +from openlp.core.common import check_directory_exists, get_frozen_path log = logging.getLogger(__name__) @@ -136,15 +136,6 @@ class AppLocation(object): return path -def get_frozen_path(frozen_option, non_frozen_option): - """ - Return a path based on the system status. - """ - if hasattr(sys, 'frozen') and sys.frozen == 1: - return frozen_option - return non_frozen_option - - def _get_os_dir_path(dir_type): """ Return a path based on which OS and environment we are running in. @@ -177,4 +168,3 @@ def _get_os_dir_path(dir_type): if dir_type == AppLocation.DataDir: return os.path.join(str(os.getenv('HOME')), '.openlp', 'data') return os.path.join(str(os.getenv('HOME')), '.openlp') - diff --git a/tests/functional/openlp_core_common/__init__.py b/tests/functional/openlp_core_common/__init__.py new file mode 100644 index 000000000..f87606f07 --- /dev/null +++ b/tests/functional/openlp_core_common/__init__.py @@ -0,0 +1 @@ +__author__ = 'tim' diff --git a/tests/functional/openlp_core_utils/test_applocation.py b/tests/functional/openlp_core_common/test_applocation.py similarity index 74% rename from tests/functional/openlp_core_utils/test_applocation.py rename to tests/functional/openlp_core_common/test_applocation.py index a79d5cefc..7ce891bd9 100644 --- a/tests/functional/openlp_core_utils/test_applocation.py +++ b/tests/functional/openlp_core_common/test_applocation.py @@ -32,7 +32,7 @@ Functional tests to test the AppLocation class and related methods. import copy from unittest import TestCase -from openlp.core.common import AppLocation +from openlp.core.common import AppLocation, get_frozen_path from tests.functional import patch FILE_LIST = ['file1', 'file2', 'file3.txt', 'file4.txt', 'file5.mp3', 'file6.mp3'] @@ -46,10 +46,10 @@ class TestAppLocation(TestCase): """ Test the AppLocation.get_data_path() method """ - with patch('openlp.core.utils.applocation.Settings') as mocked_class, \ - patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ - patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \ - patch('openlp.core.utils.applocation.os') as mocked_os: + with patch('openlp.core.lib.Settings') as mocked_class, \ + patch('openlp.core.common.AppLocation.get_directory') as mocked_get_directory, \ + patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists, \ + patch('openlp.core.common.applocation.os') as mocked_os: # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() mocked_settings = mocked_class.return_value mocked_settings.contains.return_value = False @@ -70,8 +70,8 @@ class TestAppLocation(TestCase): """ Test the AppLocation.get_data_path() method when a custom location is set in the settings """ - with patch('openlp.core.utils.applocation.Settings') as mocked_class,\ - patch('openlp.core.utils.applocation.os') as mocked_os: + with patch('openlp.core.lib.Settings') as mocked_class,\ + patch('openlp.core.common.applocation.os') as mocked_os: # GIVEN: A mocked out Settings class which returns a custom data location mocked_settings = mocked_class.return_value mocked_settings.contains.return_value = True @@ -90,8 +90,8 @@ class TestAppLocation(TestCase): """ Test the AppLocation.get_files() method with no parameters passed. """ - with patch('openlp.core.utils.AppLocation.get_data_path') as mocked_get_data_path, \ - patch('openlp.core.utils.applocation.os.listdir') as mocked_listdir: + with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \ + patch('openlp.core.common.applocation.os.listdir') as mocked_listdir: # GIVEN: Our mocked modules/methods. mocked_get_data_path.return_value = 'test/dir' mocked_listdir.return_value = copy.deepcopy(FILE_LIST) @@ -106,8 +106,8 @@ class TestAppLocation(TestCase): """ Test the AppLocation.get_files() method with all parameters passed. """ - with patch('openlp.core.utils.AppLocation.get_data_path') as mocked_get_data_path, \ - patch('openlp.core.utils.applocation.os.listdir') as mocked_listdir: + with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \ + patch('openlp.core.common.applocation.os.listdir') as mocked_listdir: # GIVEN: Our mocked modules/methods. mocked_get_data_path.return_value = 'test/dir' mocked_listdir.return_value = copy.deepcopy(FILE_LIST) @@ -125,8 +125,8 @@ class TestAppLocation(TestCase): """ Test the AppLocation.get_section_data_path() method """ - with patch('openlp.core.utils.AppLocation.get_data_path') as mocked_get_data_path, \ - patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists: + with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \ + patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists: # GIVEN: A mocked out AppLocation.get_data_path() mocked_get_data_path.return_value = 'test/dir' mocked_check_directory_exists.return_value = True @@ -143,7 +143,7 @@ class TestAppLocation(TestCase): Test the AppLocation.get_directory() method for AppLocation.AppDir """ # GIVEN: A mocked out _get_frozen_path function - with patch('openlp.core.utils.applocation._get_frozen_path') as mocked_get_frozen_path: + with patch('openlp.core.common.applocation.get_frozen_path') as mocked_get_frozen_path: mocked_get_frozen_path.return_value = 'app/dir' # WHEN: We call AppLocation.get_directory @@ -157,10 +157,10 @@ class TestAppLocation(TestCase): Test the AppLocation.get_directory() method for AppLocation.PluginsDir """ # GIVEN: _get_frozen_path, abspath, split and sys are mocked out - with patch('openlp.core.utils.applocation._get_frozen_path') as mocked_get_frozen_path, \ - patch('openlp.core.utils.applocation.os.path.abspath') as mocked_abspath, \ - patch('openlp.core.utils.applocation.os.path.split') as mocked_split, \ - patch('openlp.core.utils.applocation.sys') as mocked_sys: + with patch('openlp.core.common.applocation.get_frozen_path') as mocked_get_frozen_path, \ + patch('openlp.core.common.applocation.os.path.abspath') as mocked_abspath, \ + patch('openlp.core.common.applocation.os.path.split') as mocked_split, \ + patch('openlp.core.common.applocation.sys') as mocked_sys: mocked_abspath.return_value = 'plugins/dir' mocked_split.return_value = ['openlp'] mocked_get_frozen_path.return_value = 'plugins/dir' @@ -172,3 +172,31 @@ class TestAppLocation(TestCase): # THEN: The correct directory should be returned self.assertEqual('plugins/dir', directory, 'Directory should be "plugins/dir"') + + def get_frozen_path_in_unfrozen_app_test(self): + """ + Test the _get_frozen_path() function when the application is not frozen (compiled by PyInstaller) + """ + with patch('openlp.core.utils.sys') as mocked_sys: + # GIVEN: The sys module "without" a "frozen" attribute + mocked_sys.frozen = None + + # WHEN: We call _get_frozen_path() with two parameters + frozen_path = get_frozen_path('frozen', 'not frozen') + + # THEN: The non-frozen parameter is returned + self.assertEqual('not frozen', frozen_path, '_get_frozen_path should return "not frozen"') + + def get_frozen_path_in_frozen_app_test(self): + """ + Test the get_frozen_path() function when the application is frozen (compiled by PyInstaller) + """ + with patch('openlp.core.common.sys') as mocked_sys: + # GIVEN: The sys module *with* a "frozen" attribute + mocked_sys.frozen = 1 + + # WHEN: We call _get_frozen_path() with two parameters + frozen_path = get_frozen_path('frozen', 'not frozen') + + # THEN: The frozen parameter is returned + self.assertEqual('frozen', frozen_path, 'Should return "frozen"') \ No newline at end of file diff --git a/tests/functional/openlp_core_lib/test_theme.py b/tests/functional/openlp_core_lib/test_theme.py new file mode 100644 index 000000000..e533b1b8d --- /dev/null +++ b/tests/functional/openlp_core_lib/test_theme.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +Package to test the openlp.core.lib.theme package. +""" +from tests.functional import MagicMock, patch +from unittest import TestCase + +from openlp.core.lib.theme import ThemeXML + + +class TestTheme(TestCase): + """ + Test the functions in the Theme module + """ + def setUp(self): + """ + Create the UI + """ + pass + + def tearDown(self): + """ + Delete all the C++ objects at the end so that we don't have a segfault + """ + pass + + def test_new_theme(self): + """ + Test the theme creation - basic test + """ + # GIVEN: A new theme + + # WHEN: A theme is created + default_theme = ThemeXML() + + # THEN: We should get some default behaviours + self.assertTrue(default_theme.background_border_color == '#000000', 'The theme should have a black border') + self.assertTrue(default_theme.background_type == 'solid', 'There theme should have a solid backgrounds') \ No newline at end of file diff --git a/tests/functional/openlp_core_utils/test_utils.py b/tests/functional/openlp_core_utils/test_utils.py index 83cc24011..dfc31b245 100644 --- a/tests/functional/openlp_core_utils/test_utils.py +++ b/tests/functional/openlp_core_utils/test_utils.py @@ -31,7 +31,7 @@ Functional tests to test the AppLocation class and related methods. """ from unittest import TestCase -from openlp.core.utils import clean_filename, get_filesystem_encoding, _get_frozen_path, get_locale_key, \ +from openlp.core.utils import clean_filename, get_filesystem_encoding, get_locale_key, \ get_natural_key, split_filename from tests.functional import patch @@ -75,34 +75,6 @@ class TestUtils(TestCase): mocked_getdefaultencoding.assert_called_with() self.assertEqual('utf-8', result, 'The result should be "utf-8"') - def get_frozen_path_in_unfrozen_app_test(self): - """ - Test the _get_frozen_path() function when the application is not frozen (compiled by PyInstaller) - """ - with patch('openlp.core.utils.sys') as mocked_sys: - # GIVEN: The sys module "without" a "frozen" attribute - mocked_sys.frozen = None - - # WHEN: We call _get_frozen_path() with two parameters - frozen_path = _get_frozen_path('frozen', 'not frozen') - - # THEN: The non-frozen parameter is returned - self.assertEqual('not frozen', frozen_path, '_get_frozen_path should return "not frozen"') - - def get_frozen_path_in_frozen_app_test(self): - """ - Test the _get_frozen_path() function when the application is frozen (compiled by PyInstaller) - """ - with patch('openlp.core.utils.sys') as mocked_sys: - # GIVEN: The sys module *with* a "frozen" attribute - mocked_sys.frozen = 1 - - # WHEN: We call _get_frozen_path() with two parameters - frozen_path = _get_frozen_path('frozen', 'not frozen') - - # THEN: The frozen parameter is returned - self.assertEqual('frozen', frozen_path, 'Should return "frozen"') - def split_filename_with_file_path_test(self): """ Test the split_filename() function with a path to a file diff --git a/tests/functional/openlp_plugins/remotes/test_remotetab.py b/tests/functional/openlp_plugins/remotes/test_remotetab.py index 51198bdc2..d176a001d 100644 --- a/tests/functional/openlp_plugins/remotes/test_remotetab.py +++ b/tests/functional/openlp_plugins/remotes/test_remotetab.py @@ -105,7 +105,7 @@ class TestRemoteTab(TestCase): Test the set_urls function with standard defaults """ # GIVEN: A mocked location - with patch('openlp.core.common.applocation.Settings') as mocked_class, \ + with patch('openlp.core.lib.Settings') as mocked_class, \ patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists, \ patch('openlp.core.common.applocation.os') as mocked_os: @@ -133,7 +133,7 @@ class TestRemoteTab(TestCase): Test the set_urls function with certificate available """ # GIVEN: A mocked location - with patch('openlp.core.common.applocation.Settings') as mocked_class, \ + with patch('openlp.core.lib.Settings') as mocked_class, \ patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists, \ patch('openlp.core.common.applocation.os') as mocked_os: From a82c64237c3f26957bc46a11ecf94b52afa2535c Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 13 Oct 2013 18:23:52 +0100 Subject: [PATCH 24/46] Fix move of check_directory_exists --- openlp/core/__init__.py | 4 +- openlp/core/lib/__init__.py | 44 +++++-------------- openlp/core/ui/firsttimeform.py | 4 +- openlp/core/ui/mainwindow.py | 4 +- openlp/core/ui/servicemanager.py | 4 +- openlp/core/ui/thememanager.py | 4 +- .../plugins/bibles/forms/bibleupgradeform.py | 4 +- openlp/plugins/images/lib/mediaitem.py | 6 +-- openlp/plugins/media/lib/mediaitem.py | 4 +- .../lib/presentationcontroller.py | 4 +- openlp/plugins/songs/forms/editsongform.py | 5 +-- openlp/plugins/songs/lib/mediaitem.py | 4 +- openlp/plugins/songs/lib/openlyricsexport.py | 3 +- openlp/plugins/songs/lib/songimport.py | 4 +- .../songusage/forms/songusagedetailform.py | 3 +- tests/functional/openlp_core_lib/test_lib.py | 3 +- .../openlp_plugins/remotes/test_remotetab.py | 4 +- 17 files changed, 45 insertions(+), 63 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index a814ae04c..2ea41a3ec 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -43,8 +43,8 @@ from traceback import format_exception from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation -from openlp.core.lib import Settings, ScreenList, UiStrings, Registry, check_directory_exists +from openlp.core.common import AppLocation, check_directory_exists +from openlp.core.lib import Settings, ScreenList, UiStrings, Registry from openlp.core.resources import qInitResources from openlp.core.ui.mainwindow import MainWindow from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index bc427830e..40a9c2367 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -326,52 +326,32 @@ def expand_tags(text): text = text.replace(tag['end tag'], tag['end html']) return text - -def check_directory_exists(directory, do_not_log=False): - """ - Check a theme directory exists and if not create it - - ``directory`` - The directory to make sure exists - - ``do_not_log`` - To not log anything. This is need for the start up, when the log isn't ready. - """ - if not do_not_log: - log.debug('check_directory_exists %s' % directory) - try: - if not os.path.exists(directory): - os.makedirs(directory) - except IOError: - pass - - -def create_separated_list(stringlist): +def create_separated_list(string_list): """ Returns a string that represents a join of a list of strings with a localized separator. This function corresponds to QLocale::createSeparatedList which was introduced in Qt 4.8 and implements the algorithm from http://www.unicode.org/reports/tr35/#ListPatterns - ``stringlist`` + ``string_list`` List of unicode strings """ if LooseVersion(Qt.PYQT_VERSION_STR) >= LooseVersion('4.9') and \ LooseVersion(Qt.qVersion()) >= LooseVersion('4.8'): - return QtCore.QLocale().createSeparatedList(stringlist) - if not stringlist: + return QtCore.QLocale().createSeparatedList(string_list) + if not string_list: return '' - elif len(stringlist) == 1: - return stringlist[0] - elif len(stringlist) == 2: + elif len(string_list) == 1: + return string_list[0] + elif len(string_list) == 2: return translate('OpenLP.core.lib', '%s and %s', - 'Locale list separator: 2 items') % (stringlist[0], stringlist[1]) + 'Locale list separator: 2 items') % (string_list[0], string_list[1]) else: merged = translate('OpenLP.core.lib', '%s, and %s', - 'Locale list separator: end') % (stringlist[-2], stringlist[-1]) - for index in reversed(list(range(1, len(stringlist) - 2))): + 'Locale list separator: end') % (string_list[-2], string_list[-1]) + for index in reversed(list(range(1, len(string_list) - 2))): merged = translate('OpenLP.core.lib', '%s, %s', - 'Locale list separator: middle') % (stringlist[index], merged) - return translate('OpenLP.core.lib', '%s, %s', 'Locale list separator: start') % (stringlist[0], merged) + 'Locale list separator: middle') % (string_list[index], merged) + return translate('OpenLP.core.lib', '%s, %s', 'Locale list separator: start') % (string_list[0], merged) from .registry import Registry diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 062af6447..cbb5434f9 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -41,8 +41,8 @@ from configparser import SafeConfigParser from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation -from openlp.core.lib import PluginStatus, Settings, Registry, build_icon, check_directory_exists, translate +from openlp.core.common import AppLocation, check_directory_exists +from openlp.core.lib import PluginStatus, Settings, Registry, build_icon, translate from openlp.core.utils import get_web_page from .firsttimewizard import Ui_FirstTimeWizard, FirstTimePage diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 7cb4de6cf..4110c5e04 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -42,12 +42,12 @@ from datetime import datetime from PyQt4 import QtCore, QtGui from openlp.core.lib import Renderer, OpenLPDockWidget, PluginManager, ImageManager, PluginStatus, Registry, \ - Settings, ScreenList, build_icon, check_directory_exists, translate + Settings, ScreenList, build_icon, translate from openlp.core.lib.ui import UiStrings, create_action from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, SlideController, PluginForm, \ MediaDockManager, ShortcutListForm, FormattingTagForm -from openlp.core.common import AppLocation +from openlp.core.common import AppLocation, check_directory_exists from openlp.core.ui.media import MediaController from openlp.core.utils import LanguageManager, add_actions, get_application_version from openlp.core.utils.actions import ActionList, CategoryOrder diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 94f6b512d..ee4fa850f 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -42,9 +42,9 @@ log = logging.getLogger(__name__) from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation +from openlp.core.common import AppLocation, check_directory_exists from openlp.core.lib import OpenLPToolbar, ServiceItem, ItemCapabilities, Settings, PluginStatus, Registry, \ - UiStrings, build_icon, translate, str_to_bool, check_directory_exists + UiStrings, build_icon, translate from openlp.core.lib.theme import ThemeLevel from openlp.core.lib.ui import critical_error_message_box, create_widget_action, find_and_set_in_combo_box from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 3b07d0ed9..8dd0727ea 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -38,9 +38,9 @@ import re from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation +from openlp.core.common import AppLocation, check_directory_exists from openlp.core.lib import ImageSource, OpenLPToolbar, Registry, Settings, UiStrings, get_text_file_string, \ - build_icon, translate, check_item_selected, check_directory_exists, create_thumb, validate_thumb + build_icon, translate, check_item_selected, create_thumb, validate_thumb from openlp.core.lib.theme import ThemeXML, BackgroundType from openlp.core.lib.ui import critical_error_message_box, create_widget_action from openlp.core.ui import FileRenameForm, ThemeForm, ThemeManagerHelper diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index 2962eee9d..ca74d6666 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -36,8 +36,8 @@ from tempfile import gettempdir from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation -from openlp.core.lib import Registry, Settings, UiStrings, translate, check_directory_exists +from openlp.core.common import AppLocation, check_directory_exists +from openlp.core.lib import Registry, Settings, UiStrings, translate from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings from openlp.core.utils import delete_file diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 9aeeeaee6..ce7d55e17 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -32,10 +32,10 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation +from openlp.core.common import AppLocation, check_directory_exists from openlp.core.lib import ItemCapabilities, MediaManagerItem, Registry, ServiceItemContext, Settings, \ - StringContent, TreeWidgetWithDnD, UiStrings, build_icon, check_directory_exists, check_item_selected, \ - create_thumb, translate, validate_thumb + StringContent, TreeWidgetWithDnD, UiStrings, build_icon, check_item_selected, create_thumb, translate, \ + validate_thumb from openlp.core.lib.ui import create_widget_action, critical_error_message_box from openlp.core.utils import delete_file, get_locale_key, get_images_filter from openlp.plugins.images.forms import AddGroupForm, ChooseGroupForm diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 7464bd178..dc6b1456f 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -32,9 +32,9 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation +from openlp.core.common import AppLocation, check_directory_exists from openlp.core.lib import ItemCapabilities, MediaManagerItem,MediaType, Registry, ServiceItem, ServiceItemContext, \ - Settings, UiStrings, build_icon, check_item_selected, check_directory_exists, translate + Settings, UiStrings, build_icon, check_item_selected, translate from openlp.core.lib.ui import critical_error_message_box, create_horizontal_adjusting_combo_box from openlp.core.ui import DisplayController, Display, DisplayControllerType from openlp.core.ui.media import get_media_players, set_media_players diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index b850820c5..08584038e 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -33,8 +33,8 @@ import shutil from PyQt4 import QtCore -from openlp.core.common import AppLocation -from openlp.core.lib import Registry, Settings, check_directory_exists, create_thumb, validate_thumb +from openlp.core.common import AppLocation, check_directory_exists +from openlp.core.lib import Registry, Settings, create_thumb, validate_thumb log = logging.getLogger(__name__) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index cd44baf4f..83b4c8d04 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -38,9 +38,8 @@ import shutil from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation -from openlp.core.lib import Registry, PluginStatus, MediaType, UiStrings, translate, create_separated_list, \ - check_directory_exists +from openlp.core.common import AppLocation, check_directory_exists +from openlp.core.lib import Registry, PluginStatus, MediaType, UiStrings, translate, create_separated_list from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box from openlp.plugins.songs.lib import VerseType, clean_song from openlp.plugins.songs.lib.db import Book, Song, Author, Topic, MediaFile diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index b376c541b..a708948ae 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -35,9 +35,9 @@ import shutil from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_ -from openlp.core.common import AppLocation +from openlp.core.common import AppLocation, check_directory_exists from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, PluginStatus, ServiceItemContext, Settings, \ - UiStrings, translate, check_item_selected, create_separated_list, check_directory_exists + UiStrings, translate, check_item_selected, create_separated_list from openlp.core.lib.ui import create_widget_action from openlp.plugins.songs.forms.editsongform import EditSongForm from openlp.plugins.songs.forms.songmaintenanceform import SongMaintenanceForm diff --git a/openlp/plugins/songs/lib/openlyricsexport.py b/openlp/plugins/songs/lib/openlyricsexport.py index a1d17d595..ef62a64f0 100644 --- a/openlp/plugins/songs/lib/openlyricsexport.py +++ b/openlp/plugins/songs/lib/openlyricsexport.py @@ -35,7 +35,8 @@ import os from lxml import etree -from openlp.core.lib import Registry, check_directory_exists, translate +from openlp.core.common import check_directory_exists +from openlp.core.lib import Registry, translate from openlp.core.utils import clean_filename from openlp.plugins.songs.lib.xml import OpenLyrics diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 74e2a0272..378f18272 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -34,8 +34,8 @@ import os from PyQt4 import QtCore -from openlp.core.common import AppLocation -from openlp.core.lib import Registry, translate, check_directory_exists +from openlp.core.common import AppLocation, check_directory_exists +from openlp.core.lib import Registry, translate from openlp.core.ui.wizard import WizardStrings from openlp.plugins.songs.lib import clean_song, VerseType from openlp.plugins.songs.lib.db import Song, Author, Topic, Book, MediaFile diff --git a/openlp/plugins/songusage/forms/songusagedetailform.py b/openlp/plugins/songusage/forms/songusagedetailform.py index 725668bd3..e5925da78 100644 --- a/openlp/plugins/songusage/forms/songusagedetailform.py +++ b/openlp/plugins/songusage/forms/songusagedetailform.py @@ -33,7 +33,8 @@ import os from PyQt4 import QtGui from sqlalchemy.sql import and_ -from openlp.core.lib import Registry, Settings, translate, check_directory_exists +from openlp.core.common import check_directory_exists +from openlp.core.lib import Registry, Settings, translate from openlp.plugins.songusage.lib.db import SongUsageItem from .songusagedetaildialog import Ui_SongUsageDetailDialog diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 9bb74e0d3..6ba7eddbb 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -36,7 +36,8 @@ from datetime import datetime, timedelta from PyQt4 import QtCore, QtGui -from openlp.core.lib import str_to_bool, create_thumb, translate, check_directory_exists, get_text_file_string, \ +from openlp.core.common import check_directory_exists +from openlp.core.lib import str_to_bool, create_thumb, translate, get_text_file_string, \ build_icon, image_to_byte, check_item_selected, validate_thumb, create_separated_list, clean_tags, expand_tags from tests.functional import MagicMock, patch diff --git a/tests/functional/openlp_plugins/remotes/test_remotetab.py b/tests/functional/openlp_plugins/remotes/test_remotetab.py index d176a001d..cd32479d4 100644 --- a/tests/functional/openlp_plugins/remotes/test_remotetab.py +++ b/tests/functional/openlp_plugins/remotes/test_remotetab.py @@ -107,7 +107,7 @@ class TestRemoteTab(TestCase): # GIVEN: A mocked location with patch('openlp.core.lib.Settings') as mocked_class, \ patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ - patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists, \ + patch('openlp.core.common.check_directory_exists') as mocked_check_directory_exists, \ patch('openlp.core.common.applocation.os') as mocked_os: # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() mocked_settings = mocked_class.return_value @@ -135,7 +135,7 @@ class TestRemoteTab(TestCase): # GIVEN: A mocked location with patch('openlp.core.lib.Settings') as mocked_class, \ patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ - patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists, \ + patch('openlp.core.common.check_directory_exists') as mocked_check_directory_exists, \ patch('openlp.core.common.applocation.os') as mocked_os: # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() mocked_settings = mocked_class.return_value From 63685cb29e621528f7eb0a00bcea729fe8ca83cc Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 13 Oct 2013 21:36:42 +0100 Subject: [PATCH 25/46] Move Settings and translate --- openlp/core/__init__.py | 4 +- openlp/core/common/__init__.py | 42 ++ openlp/core/common/applocation.py | 4 +- openlp/core/{lib => common}/uistrings.py | 2 +- openlp/core/lib/__init__.py | 33 +- openlp/core/lib/db.py | 4 +- openlp/core/lib/formattingtags.py | 3 +- openlp/core/lib/mediamanageritem.py | 3 +- openlp/core/lib/plugin.py | 3 +- openlp/core/lib/renderer.py | 5 +- openlp/core/lib/screen.py | 4 +- openlp/core/lib/serviceitem.py | 3 +- openlp/core/lib/settings.py | 499 ------------------ openlp/core/lib/theme.py | 9 - openlp/core/lib/ui.py | 3 +- openlp/core/ui/aboutdialog.py | 3 +- openlp/core/ui/advancedtab.py | 5 +- openlp/core/ui/exceptionform.py | 2 +- openlp/core/ui/firsttimeform.py | 4 +- openlp/core/ui/formattingtagdialog.py | 3 +- openlp/core/ui/generaltab.py | 3 +- openlp/core/ui/maindisplay.py | 3 +- openlp/core/ui/mainwindow.py | 4 +- openlp/core/ui/media/__init__.py | 2 +- openlp/core/ui/media/mediacontroller.py | 3 +- openlp/core/ui/media/phononplayer.py | 3 +- openlp/core/ui/media/playertab.py | 3 +- openlp/core/ui/media/vlcplayer.py | 3 +- openlp/core/ui/media/webkitplayer.py | 3 +- openlp/core/ui/plugindialog.py | 2 +- openlp/core/ui/printservicedialog.py | 3 +- openlp/core/ui/printserviceform.py | 3 +- openlp/core/ui/servicemanager.py | 8 +- openlp/core/ui/shortcutlistform.py | 4 +- openlp/core/ui/slidecontroller.py | 5 +- openlp/core/ui/starttimedialog.py | 2 +- openlp/core/ui/starttimeform.py | 3 +- openlp/core/ui/themeform.py | 3 +- openlp/core/ui/thememanager.py | 6 +- openlp/core/ui/themestab.py | 4 +- openlp/core/ui/themewizard.py | 3 +- openlp/core/ui/wizard.py | 5 +- openlp/core/utils/__init__.py | 4 +- openlp/core/utils/actions.py | 2 +- openlp/core/utils/languagemanager.py | 4 +- openlp/plugins/alerts/alertsplugin.py | 3 +- openlp/plugins/alerts/lib/alertstab.py | 3 +- .../plugins/bibles/forms/bibleimportform.py | 3 +- .../plugins/bibles/forms/bibleupgradeform.py | 4 +- openlp/plugins/bibles/forms/booknamedialog.py | 2 +- openlp/plugins/bibles/forms/booknameform.py | 2 +- .../plugins/bibles/forms/editbibledialog.py | 3 +- openlp/plugins/bibles/forms/editbibleform.py | 3 +- openlp/plugins/bibles/forms/languagedialog.py | 2 +- openlp/plugins/bibles/forms/languageform.py | 2 +- openlp/plugins/bibles/lib/__init__.py | 3 +- openlp/plugins/bibles/lib/biblestab.py | 3 +- openlp/plugins/bibles/lib/manager.py | 4 +- openlp/plugins/bibles/lib/mediaitem.py | 5 +- .../plugins/custom/forms/editcustomdialog.py | 3 +- .../custom/forms/editcustomslidedialog.py | 3 +- .../custom/forms/editcustomslideform.py | 2 +- openlp/plugins/custom/lib/customtab.py | 3 +- openlp/plugins/custom/lib/mediaitem.py | 5 +- openlp/plugins/images/imageplugin.py | 5 +- openlp/plugins/images/lib/imagetab.py | 3 +- openlp/plugins/images/lib/mediaitem.py | 6 +- openlp/plugins/media/lib/mediaitem.py | 4 +- openlp/plugins/media/lib/mediatab.py | 3 +- openlp/plugins/media/mediaplugin.py | 2 +- openlp/plugins/presentations/lib/mediaitem.py | 5 +- .../lib/presentationcontroller.py | 4 +- .../presentations/lib/presentationtab.py | 3 +- openlp/plugins/remotes/lib/httprouter.py | 5 +- openlp/plugins/remotes/lib/httpserver.py | 3 +- openlp/plugins/remotes/lib/remotetab.py | 4 +- openlp/plugins/songs/forms/editsongdialog.py | 3 +- openlp/plugins/songs/forms/editsongform.py | 4 +- openlp/plugins/songs/forms/songexportform.py | 3 +- openlp/plugins/songs/forms/songimportform.py | 4 +- .../songs/forms/songmaintenancedialog.py | 3 +- .../songs/forms/songmaintenanceform.py | 3 +- openlp/plugins/songs/lib/importer.py | 2 +- openlp/plugins/songs/lib/mediaitem.py | 6 +- openlp/plugins/songs/lib/olpimport.py | 2 +- openlp/plugins/songs/lib/oooimport.py | 1 + openlp/plugins/songs/lib/openlyricsexport.py | 4 +- openlp/plugins/songs/lib/opensongimport.py | 3 +- openlp/plugins/songs/lib/powersongimport.py | 2 +- openlp/plugins/songs/lib/songimport.py | 4 +- openlp/plugins/songs/lib/songproimport.py | 1 + .../plugins/songs/lib/songshowplusimport.py | 5 +- openlp/plugins/songs/lib/songstab.py | 3 +- openlp/plugins/songs/lib/ui.py | 1 + .../songs/lib/worshipcenterproimport.py | 2 +- openlp/plugins/songs/lib/wowimport.py | 2 +- openlp/plugins/songs/lib/xml.py | 3 +- openlp/plugins/songs/lib/zionworximport.py | 2 +- openlp/plugins/songs/songsplugin.py | 3 +- .../songusage/forms/songusagedeletedialog.py | 2 +- .../songusage/forms/songusagedeleteform.py | 5 +- .../songusage/forms/songusagedetaildialog.py | 3 +- .../songusage/forms/songusagedetailform.py | 4 +- openlp/plugins/songusage/songusageplugin.py | 3 +- .../openlp_core_common/test_applocation.py | 5 +- .../test_settings.py | 2 +- .../test_uistrings.py | 2 +- .../openlp_core_lib/test_formattingtags.py | 4 +- tests/functional/openlp_core_lib/test_lib.py | 4 +- .../openlp_core_lib/test_pluginmanager.py | 3 +- .../openlp_core_utils/test_actions.py | 2 +- .../openlp_plugins/remotes/test_remotetab.py | 6 +- .../openlp_plugins/remotes/test_router.py | 2 +- .../openlp_plugins/songs/test_mediaitem.py | 3 +- .../openlp_core_lib/test_pluginmanager.py | 3 +- 115 files changed, 257 insertions(+), 693 deletions(-) rename openlp/core/{lib => common}/uistrings.py (99%) delete mode 100644 openlp/core/lib/settings.py rename tests/functional/{openlp_core_lib => openlp_core_common}/test_settings.py (99%) rename tests/functional/{openlp_core_lib => openlp_core_common}/test_uistrings.py (98%) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 2ea41a3ec..7d198db5e 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -43,8 +43,8 @@ from traceback import format_exception from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation, check_directory_exists -from openlp.core.lib import Settings, ScreenList, UiStrings, Registry +from openlp.core.common import AppLocation, Settings, UiStrings, check_directory_exists +from openlp.core.lib import ScreenList, Registry from openlp.core.resources import qInitResources from openlp.core.ui.mainwindow import MainWindow from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index 02fab3512..42fde7065 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -34,6 +34,8 @@ import os import logging import sys +from PyQt4 import QtCore + log = logging.getLogger(__name__) @@ -64,4 +66,44 @@ def get_frozen_path(frozen_option, non_frozen_option): return frozen_option return non_frozen_option + +class ThemeLevel(object): + """ + Provides an enumeration for the level a theme applies to + """ + Global = 1 + Service = 2 + Song = 3 + + +def translate(context, text, comment=None, encoding=QtCore.QCoreApplication.CodecForTr, n=-1, + qt_translate=QtCore.QCoreApplication.translate): + """ + A special shortcut method to wrap around the Qt4 translation functions. This abstracts the translation procedure so + that we can change it if at a later date if necessary, without having to redo the whole of OpenLP. + + ``context`` + The translation context, used to give each string a context or a namespace. + + ``text`` + The text to put into the translation tables for translation. + + ``comment`` + An identifying string for when the same text is used in different roles within the same context. + """ + return qt_translate(context, text, comment, encoding, n) + + +class SlideLimits(object): + """ + Provides an enumeration for behaviour of OpenLP at the end limits of each service item when pressing the up/down + arrow keys + """ + End = 1 + Wrap = 2 + Next = 3 + +from .uistrings import UiStrings +from .settings import Settings from .applocation import AppLocation + diff --git a/openlp/core/common/applocation.py b/openlp/core/common/applocation.py index 8925b4c59..41b47ecbe 100644 --- a/openlp/core/common/applocation.py +++ b/openlp/core/common/applocation.py @@ -33,6 +33,9 @@ import logging import os import sys +from openlp.core.common import Settings + + if sys.platform != 'win32' and sys.platform != 'darwin': try: from xdg import BaseDirectory @@ -91,7 +94,6 @@ class AppLocation(object): Return the path OpenLP stores all its data under. """ # Check if we have a different data location. - from openlp.core.lib import Settings if Settings().contains('advanced/data path'): path = Settings().value('advanced/data path') else: diff --git a/openlp/core/lib/uistrings.py b/openlp/core/common/uistrings.py similarity index 99% rename from openlp/core/lib/uistrings.py rename to openlp/core/common/uistrings.py index 6d4b4d250..d7a4c1c42 100644 --- a/openlp/core/lib/uistrings.py +++ b/openlp/core/common/uistrings.py @@ -31,7 +31,7 @@ The :mod:`uistrings` module provides standard strings for OpenLP. """ import logging -from openlp.core.lib import translate +from openlp.core.common import translate log = logging.getLogger(__name__) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 40a9c2367..67ac409df 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -37,6 +37,8 @@ import os from PyQt4 import QtCore, QtGui, Qt +from openlp.core.common import translate + log = logging.getLogger(__name__) @@ -72,16 +74,6 @@ class MediaType(object): Video = 2 -class SlideLimits(object): - """ - Provides an enumeration for behaviour of OpenLP at the end limits of each service item when pressing the up/down - arrow keys - """ - End = 1 - Wrap = 2 - Next = 3 - - class ServiceItemAction(object): """ Provides an enumeration for the required action moving between service items by left/right arrow keys @@ -91,24 +83,6 @@ class ServiceItemAction(object): Next = 3 -def translate(context, text, comment=None, encoding=QtCore.QCoreApplication.CodecForTr, n=-1, - qt_translate=QtCore.QCoreApplication.translate): - """ - A special shortcut method to wrap around the Qt4 translation functions. This abstracts the translation procedure so - that we can change it if at a later date if necessary, without having to redo the whole of OpenLP. - - ``context`` - The translation context, used to give each string a context or a namespace. - - ``text`` - The text to put into the translation tables for translation. - - ``comment`` - An identifying string for when the same text is used in different roles within the same context. - """ - return qt_translate(context, text, comment, encoding, n) - - def get_text_file_string(text_file): """ Open a file and return its content as unicode string. If the supplied file name is not a file then the function @@ -326,6 +300,7 @@ def expand_tags(text): text = text.replace(tag['end tag'], tag['end html']) return text + def create_separated_list(string_list): """ Returns a string that represents a join of a list of strings with a localized separator. This function corresponds @@ -355,9 +330,7 @@ def create_separated_list(string_list): from .registry import Registry -from .uistrings import UiStrings from .screen import ScreenList -from .settings import Settings from .listwidgetwithdnd import ListWidgetWithDnD from .treewidgetwithdnd import TreeWidgetWithDnD from .formattingtags import FormattingTags diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index 0fff6e871..6bbca9b5c 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -41,8 +41,8 @@ from sqlalchemy.pool import NullPool from alembic.migration import MigrationContext from alembic.operations import Operations -from openlp.core.common import AppLocation -from openlp.core.lib import translate, Settings +from openlp.core.common import AppLocation, Settings +from openlp.core.lib import translate from openlp.core.lib.ui import critical_error_message_box from openlp.core.utils import delete_file diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index f914677c6..58e3226d1 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -31,7 +31,8 @@ Provide HTML Tag management and Formatting Tag access class """ import json -from openlp.core.lib import Settings, translate +from openlp.core.common import Settings +from openlp.core.lib import translate class FormattingTags(object): diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 3fddc18f2..01e16eef3 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -35,8 +35,9 @@ import re from PyQt4 import QtCore, QtGui +from openlp.core.common import Settings, UiStrings, translate from openlp.core.lib import OpenLPToolbar, ServiceItem, StringContent, ListWidgetWithDnD, \ - ServiceItemContext, Settings, Registry, UiStrings, translate + ServiceItemContext, Registry from openlp.core.lib.searchedit import SearchEdit from openlp.core.lib.ui import create_widget_action, critical_error_message_box diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index fc9830398..2e6f42c6b 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -34,7 +34,8 @@ import os from PyQt4 import QtCore -from openlp.core.lib import Settings, Registry, UiStrings +from openlp.core.common import Settings, UiStrings +from openlp.core.lib import Registry from openlp.core.utils import get_application_version log = logging.getLogger(__name__) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 4b2aacda6..b743f3962 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -31,9 +31,10 @@ import logging from PyQt4 import QtGui, QtCore, QtWebKit -from openlp.core.lib import Settings, FormattingTags, ImageSource, ItemCapabilities, Registry, ScreenList, \ +from openlp.core.common import Settings +from openlp.core.lib import FormattingTags, ImageSource, ItemCapabilities, Registry, ScreenList, \ ServiceItem, expand_tags, build_lyrics_format_css, build_lyrics_outline_css -from openlp.core.lib.theme import ThemeLevel +from openlp.core.common import ThemeLevel from openlp.core.ui import MainDisplay log = logging.getLogger(__name__) diff --git a/openlp/core/lib/screen.py b/openlp/core/lib/screen.py index d1cca99cd..ddae9fba1 100644 --- a/openlp/core/lib/screen.py +++ b/openlp/core/lib/screen.py @@ -36,7 +36,8 @@ import copy from PyQt4 import QtCore -from openlp.core.lib import Registry, translate +from openlp.core.common import Settings, translate +from openlp.core.lib import Registry log = logging.getLogger(__name__) @@ -244,7 +245,6 @@ class ScreenList(object): """ Loads the screen size and the monitor number from the settings. """ - from openlp.core.lib import Settings # Add the screen settings to the settings dict. This has to be done here due to cyclic dependency. # Do not do this anywhere else. screen_settings = { diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index cbb3c8458..c1438840b 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -39,7 +39,8 @@ import uuid from PyQt4 import QtGui -from openlp.core.lib import ImageSource, Settings, Registry, build_icon, clean_tags, expand_tags, translate +from openlp.core.common import Settings +from openlp.core.lib import ImageSource, Registry, build_icon, clean_tags, expand_tags, translate log = logging.getLogger(__name__) diff --git a/openlp/core/lib/settings.py b/openlp/core/lib/settings.py deleted file mode 100644 index a124132ab..000000000 --- a/openlp/core/lib/settings.py +++ /dev/null @@ -1,499 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2013 Raoul Snyman # -# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # -# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # -# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # -# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # -# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # -# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # -# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # -# --------------------------------------------------------------------------- # -# 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 # -############################################################################### -""" -This class contains the core default settings. -""" -import datetime -import logging -import os -import sys - -from PyQt4 import QtCore, QtGui - -from openlp.core.lib import SlideLimits, UiStrings -from openlp.core.lib.theme import ThemeLevel - - -log = logging.getLogger(__name__) - - -# Fix for bug #1014422. -X11_BYPASS_DEFAULT = True -if sys.platform.startswith('linux'): - # Default to False on Gnome. - X11_BYPASS_DEFAULT = bool(not os.environ.get('GNOME_DESKTOP_SESSION_ID')) - # Default to False on Xfce. - if os.environ.get('DESKTOP_SESSION') == 'xfce': - X11_BYPASS_DEFAULT = False - - -class Settings(QtCore.QSettings): - """ - Class to wrap QSettings. - - * Exposes all the methods of QSettings. - * Adds functionality for OpenLP Portable. If the ``defaultFormat`` is set to - ``IniFormat``, and the path to the Ini file is set using ``set_filename``, - then the Settings constructor (without any arguments) will create a Settings - object for accessing settings stored in that Ini file. - - ``__default_settings__`` - This dict contains all core settings with their default values. - - ``__obsolete_settings__`` - Each entry is structured in the following way:: - - (u'general/enable slide loop', u'advanced/slide limits', - [(SlideLimits.Wrap, True), (SlideLimits.End, False)]) - - The first entry is the *old key*; it will be removed. - - The second entry is the *new key*; we will add it to the config. If this is just an empty string, we just remove - the old key. - - The last entry is a list containing two-pair tuples. If the list is empty, no conversion is made. Otherwise each - pair describes how to convert the old setting's value:: - - (SlideLimits.Wrap, True) - - This means, that if the value of ``general/enable slide loop`` is equal (``==``) ``True`` then we set - ``advanced/slide limits`` to ``SlideLimits.Wrap``. **NOTE**, this means that the rules have to cover all cases! - So, if the type of the old value is bool, then there must be two rules. - """ - __default_settings__ = { - 'advanced/add page break': False, - 'advanced/alternate rows': not sys.platform.startswith('win'), - 'advanced/current media plugin': -1, - 'advanced/data path': '', - 'advanced/default color': '#ffffff', - 'advanced/default image': ':/graphics/openlp-splash-screen.png', - # 7 stands for now, 0 to 6 is Monday to Sunday. - 'advanced/default service day': 7, - 'advanced/default service enabled': True, - 'advanced/default service hour': 11, - 'advanced/default service minute': 0, - 'advanced/default service name': UiStrings().DefaultServiceName, - 'advanced/display size': 0, - 'advanced/double click live': False, - 'advanced/enable exit confirmation': True, - 'advanced/expand service item': False, - 'advanced/hide mouse': True, - 'advanced/is portable': False, - 'advanced/max recent files': 20, - 'advanced/print file meta data': False, - 'advanced/print notes': False, - 'advanced/print slide text': False, - 'advanced/recent file count': 4, - 'advanced/save current plugin': False, - 'advanced/slide limits': SlideLimits.End, - 'advanced/single click preview': False, - 'advanced/x11 bypass wm': X11_BYPASS_DEFAULT, - 'crashreport/last directory': '', - 'formattingTags/html_tags': '', - 'core/audio repeat list': False, - 'core/auto open': False, - 'core/auto preview': False, - 'core/audio start paused': True, - 'core/auto unblank': False, - 'core/blank warning': False, - 'core/ccli number': '', - 'core/has run wizard': False, - 'core/language': '[en]', - 'core/last version test': '', - 'core/loop delay': 5, - 'core/recent files': [], - 'core/save prompt': False, - 'core/screen blank': False, - 'core/show splash': True, - 'core/songselect password': '', - 'core/songselect username': '', - 'core/update check': True, - 'core/view mode': 'default', - # The other display settings (display position and dimensions) are defined in the ScreenList class due to a - # circular dependency. - 'core/display on monitor': True, - 'core/override position': False, - 'images/background color': '#000000', - 'media/players': 'webkit', - 'media/override player': QtCore.Qt.Unchecked, - 'players/background color': '#000000', - 'servicemanager/last directory': '', - 'servicemanager/last file': '', - 'servicemanager/service theme': '', - 'SettingsImport/file_date_created': datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), - 'SettingsImport/Make_Changes': 'At_Own_RISK', - 'SettingsImport/type': 'OpenLP_settings_export', - 'SettingsImport/version': '', - 'shortcuts/aboutItem': [QtGui.QKeySequence('Ctrl+F1')], - 'shortcuts/addToService': [], - 'shortcuts/audioPauseItem': [], - 'shortcuts/displayTagItem': [], - 'shortcuts/blankScreen': [QtGui.QKeySequence(QtCore.Qt.Key_Period)], - 'shortcuts/collapse': [QtGui.QKeySequence(QtCore.Qt.Key_Minus)], - 'shortcuts/desktopScreen': [QtGui.QKeySequence('D')], - 'shortcuts/delete': [], - 'shortcuts/down': [QtGui.QKeySequence(QtCore.Qt.Key_Down)], - 'shortcuts/editSong': [], - 'shortcuts/escapeItem': [QtGui.QKeySequence(QtCore.Qt.Key_Escape)], - 'shortcuts/expand': [QtGui.QKeySequence(QtCore.Qt.Key_Plus)], - 'shortcuts/exportThemeItem': [], - 'shortcuts/fileNewItem': [QtGui.QKeySequence('Ctrl+N')], - 'shortcuts/fileSaveAsItem': [QtGui.QKeySequence('Ctrl+Shift+S')], - 'shortcuts/fileExitItem': [QtGui.QKeySequence('Alt+F4')], - 'shortcuts/fileSaveItem': [QtGui.QKeySequence('Ctrl+S')], - 'shortcuts/fileOpenItem': [QtGui.QKeySequence('Ctrl+O')], - 'shortcuts/goLive': [], - 'shortcuts/importThemeItem': [], - 'shortcuts/importBibleItem': [], - 'shortcuts/listViewBiblesDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], - 'shortcuts/listViewBiblesPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.Key_Return)], - 'shortcuts/listViewBiblesLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], - 'shortcuts/listViewBiblesServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), - QtGui.QKeySequence(QtCore.Qt.Key_Equal)], - 'shortcuts/listViewCustomDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], - 'shortcuts/listViewCustomPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.Key_Return)], - 'shortcuts/listViewCustomLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], - 'shortcuts/listViewCustomServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), - QtGui.QKeySequence(QtCore.Qt.Key_Equal)], - 'shortcuts/listViewImagesDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], - 'shortcuts/listViewImagesPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.Key_Return)], - 'shortcuts/listViewImagesLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], - 'shortcuts/listViewImagesServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), - QtGui.QKeySequence(QtCore.Qt.Key_Equal)], - 'shortcuts/listViewMediaDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], - 'shortcuts/listViewMediaPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.Key_Return)], - 'shortcuts/listViewMediaLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], - 'shortcuts/listViewMediaServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), - QtGui.QKeySequence(QtCore.Qt.Key_Equal)], - 'shortcuts/listViewPresentationsDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], - 'shortcuts/listViewPresentationsPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.Key_Return)], - 'shortcuts/listViewPresentationsLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], - 'shortcuts/listViewPresentationsServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), - QtGui.QKeySequence(QtCore.Qt.Key_Equal)], - 'shortcuts/listViewSongsDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], - 'shortcuts/listViewSongsPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.Key_Return)], - 'shortcuts/listViewSongsLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), - QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], - 'shortcuts/listViewSongsServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), - QtGui.QKeySequence(QtCore.Qt.Key_Equal)], - 'shortcuts/lockPanel': [], - 'shortcuts/modeDefaultItem': [], - 'shortcuts/modeLiveItem': [], - 'shortcuts/make_live': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), QtGui.QKeySequence(QtCore.Qt.Key_Return)], - 'shortcuts/moveUp': [QtGui.QKeySequence(QtCore.Qt.Key_PageUp)], - 'shortcuts/moveTop': [QtGui.QKeySequence(QtCore.Qt.Key_Home)], - 'shortcuts/modeSetupItem': [], - 'shortcuts/moveBottom': [QtGui.QKeySequence(QtCore.Qt.Key_End)], - 'shortcuts/moveDown': [QtGui.QKeySequence(QtCore.Qt.Key_PageDown)], - 'shortcuts/nextTrackItem': [], - 'shortcuts/nextItem_live': [QtGui.QKeySequence(QtCore.Qt.Key_Down), - QtGui.QKeySequence(QtCore.Qt.Key_PageDown)], - 'shortcuts/nextItem_preview': [], - 'shortcuts/nextService': [QtGui.QKeySequence(QtCore.Qt.Key_Right)], - 'shortcuts/newService': [], - 'shortcuts/offlineHelpItem': [], - 'shortcuts/onlineHelpItem': [QtGui.QKeySequence('Alt+F1')], - 'shortcuts/openService': [], - 'shortcuts/saveService': [], - 'shortcuts/previousItem_live': [QtGui.QKeySequence(QtCore.Qt.Key_Up), - QtGui.QKeySequence(QtCore.Qt.Key_PageUp)], - 'shortcuts/playbackPause': [], - 'shortcuts/playbackPlay': [], - 'shortcuts/playbackStop': [], - 'shortcuts/playSlidesLoop': [], - 'shortcuts/playSlidesOnce': [], - 'shortcuts/previousService': [QtGui.QKeySequence(QtCore.Qt.Key_Left)], - 'shortcuts/previousItem_preview': [], - 'shortcuts/printServiceItem': [QtGui.QKeySequence('Ctrl+P')], - 'shortcuts/songExportItem': [], - 'shortcuts/songUsageStatus': [QtGui.QKeySequence(QtCore.Qt.Key_F4)], - 'shortcuts/searchShortcut': [QtGui.QKeySequence('Ctrl+F')], - 'shortcuts/settingsShortcutsItem': [], - 'shortcuts/settingsImportItem': [], - 'shortcuts/settingsPluginListItem': [QtGui.QKeySequence('Alt+F7')], - 'shortcuts/songUsageDelete': [], - 'shortcuts/settingsConfigureItem': [], - 'shortcuts/shortcutAction_B': [QtGui.QKeySequence('B')], - 'shortcuts/shortcutAction_C': [QtGui.QKeySequence('C')], - 'shortcuts/shortcutAction_E': [QtGui.QKeySequence('E')], - 'shortcuts/shortcutAction_I': [QtGui.QKeySequence('I')], - 'shortcuts/shortcutAction_O': [QtGui.QKeySequence('O')], - 'shortcuts/shortcutAction_P': [QtGui.QKeySequence('P')], - 'shortcuts/shortcutAction_V': [QtGui.QKeySequence('V')], - 'shortcuts/shortcutAction_0': [QtGui.QKeySequence('0')], - 'shortcuts/shortcutAction_1': [QtGui.QKeySequence('1')], - 'shortcuts/shortcutAction_2': [QtGui.QKeySequence('2')], - 'shortcuts/shortcutAction_3': [QtGui.QKeySequence('3')], - 'shortcuts/shortcutAction_4': [QtGui.QKeySequence('4')], - 'shortcuts/shortcutAction_5': [QtGui.QKeySequence('5')], - 'shortcuts/shortcutAction_6': [QtGui.QKeySequence('6')], - 'shortcuts/shortcutAction_7': [QtGui.QKeySequence('7')], - 'shortcuts/shortcutAction_8': [QtGui.QKeySequence('8')], - 'shortcuts/shortcutAction_9': [QtGui.QKeySequence('9')], - 'shortcuts/settingsExportItem': [], - 'shortcuts/songUsageReport': [], - 'shortcuts/songImportItem': [], - 'shortcuts/themeScreen': [QtGui.QKeySequence('T')], - 'shortcuts/toolsReindexItem': [], - 'shortcuts/toolsFindDuplicates': [], - 'shortcuts/toolsAlertItem': [QtGui.QKeySequence('F7')], - 'shortcuts/toolsFirstTimeWizard': [], - 'shortcuts/toolsOpenDataFolder': [], - 'shortcuts/toolsAddToolItem': [], - 'shortcuts/updateThemeImages': [], - 'shortcuts/up': [QtGui.QKeySequence(QtCore.Qt.Key_Up)], - 'shortcuts/viewThemeManagerItem': [QtGui.QKeySequence('F10')], - 'shortcuts/viewMediaManagerItem': [QtGui.QKeySequence('F8')], - 'shortcuts/viewPreviewPanel': [QtGui.QKeySequence('F11')], - 'shortcuts/viewLivePanel': [QtGui.QKeySequence('F12')], - 'shortcuts/viewServiceManagerItem': [QtGui.QKeySequence('F9')], - 'shortcuts/webSiteItem': [], - 'themes/global theme': '', - 'themes/last directory': '', - 'themes/last directory export': '', - 'themes/last directory import': '', - 'themes/theme level': ThemeLevel.Song, - 'user interface/live panel': True, - 'user interface/live splitter geometry': QtCore.QByteArray(), - 'user interface/lock panel': False, - 'user interface/main window geometry': QtCore.QByteArray(), - 'user interface/main window position': QtCore.QPoint(0, 0), - 'user interface/main window splitter geometry': QtCore.QByteArray(), - 'user interface/main window state': QtCore.QByteArray(), - 'user interface/preview panel': True, - 'user interface/preview splitter geometry': QtCore.QByteArray() - } - __file_path__ = '' - __obsolete_settings__ = [ - # Changed during 1.9.x development. - ('bibles/bookname language', 'bibles/book name language', []), - ('general/enable slide loop', 'advanced/slide limits', [(SlideLimits.Wrap, True), (SlideLimits.End, False)]), - ('songs/ccli number', 'core/ccli number', []), - ('media/use phonon', '', []), - # Changed during 2.1.x development. - ('advanced/stylesheet fix', '', []), - ('bibles/last directory 1', 'bibles/last directory import', []), - ('media/background color', 'players/background color', []), - ('themes/last directory', 'themes/last directory import', []), - ('themes/last directory 1', 'themes/last directory export', []), - ('songs/last directory 1', 'songs/last directory import', []), - ('songusage/last directory 1', 'songusage/last directory export', []), - ('user interface/mainwindow splitter geometry', 'user interface/main window splitter geometry', []), - ('shortcuts/makeLive', 'shortcuts/make_live', []), - ('general/audio repeat list', 'core/audio repeat list', []), - ('general/auto open', 'core/auto open', []), - ('general/auto preview', 'core/auto preview', []), - ('general/audio start paused', 'core/audio start paused', []), - ('general/auto unblank', 'core/auto unblank', []), - ('general/blank warning', 'core/blank warning', []), - ('general/ccli number', 'core/ccli number', []), - ('general/has run wizard', 'core/has run wizard', []), - ('general/language', 'core/language', []), - ('general/last version test', 'core/last version test', []), - ('general/loop delay', 'core/loop delay', []), - ('general/recent files', 'core/recent files', []), - ('general/save prompt', 'core/save prompt', []), - ('general/screen blank', 'core/screen blank', []), - ('general/show splash', 'core/show splash', []), - ('general/songselect password', 'core/songselect password', []), - ('general/songselect username', 'core/songselect username', []), - ('general/update check', 'core/update check', []), - ('general/view mode', 'core/view mode', []), - ('general/display on monitor', 'core/display on monitor', []), - ('general/override position', 'core/override position', []), - ('general/x position', 'core/x position', []), - ('general/y position', 'core/y position', []), - ('general/monitor', 'core/monitor', []), - ('general/height', 'core/height', []), - ('general/monitor', 'core/monitor', []), - ('general/width', 'core/width', []) - ] - - @staticmethod - def extend_default_settings(default_values): - """ - Static method to merge the given ``default_values`` with the ``Settings.__default_settings__``. - - ``default_values`` - A dict with setting keys and their default values. - """ - Settings.__default_settings__ = dict(list(default_values.items()) + list(Settings.__default_settings__.items())) - - @staticmethod - def set_filename(ini_file): - """ - Sets the complete path to an Ini file to be used by Settings objects. - - Does not affect existing Settings objects. - """ - Settings.__file_path__ = ini_file - - @staticmethod - def set_up_default_values(): - """ - This static method is called on start up. It is used to perform any operation on the __default_settings__ dict. - """ - # Make sure the string is translated (when building the dict the string is not translated because the translate - # function was not set up as this stage). - Settings.__default_settings__['advanced/default service name'] = UiStrings().DefaultServiceName - - def __init__(self, *args): - """ - Constructor which checks if this should be a native settings object, or an INI file. - """ - if not args and Settings.__file_path__ and Settings.defaultFormat() == Settings.IniFormat: - QtCore.QSettings.__init__(self, Settings.__file_path__, Settings.IniFormat) - else: - QtCore.QSettings.__init__(self, *args) - - def get_default_value(self, key): - """ - Get the default value of the given key - """ - if self.group(): - key = self.group() + '/' + key - return Settings.__default_settings__[key] - - def remove_obsolete_settings(self): - """ - This method is only called to clean up the config. It removes old settings and it renames settings. See - ``__obsolete_settings__`` for more details. - """ - for old_key, new_key, rules in Settings.__obsolete_settings__: - # Once removed we don't have to do this again. - if self.contains(old_key): - if new_key: - # Get the value of the old_key. - old_value = super(Settings, self).value(old_key) - # When we want to convert the value, we have to figure out the default value (because we cannot get - # the default value from the central settings dict. - if rules: - default_value = rules[0][1] - old_value = self._convert_value(old_value, default_value) - # Iterate over our rules and check what the old_value should be "converted" to. - for new, old in rules: - # If the value matches with the condition (rule), then use the provided value. This is used to - # convert values. E. g. an old value 1 results in True, and 0 in False. - if old == old_value: - old_value = new - break - self.setValue(new_key, old_value) - self.remove(old_key) - - def value(self, key): - """ - Returns the value for the given ``key``. The returned ``value`` is of the same type as the default value in the - *Settings.__default_settings__* dict. - - ``key`` - The key to return the value from. - """ - # if group() is not empty the group has not been specified together with the key. - if self.group(): - default_value = Settings.__default_settings__[self.group() + '/' + key] - else: - default_value = Settings.__default_settings__[key] - setting = super(Settings, self).value(key, default_value) - return self._convert_value(setting, default_value) - - def _convert_value(self, setting, default_value): - """ - This converts the given ``setting`` to the type of the given ``default_value``. - - ``setting`` - The setting to convert. This could be ``true`` for example.Settings() - - ``default_value`` - Indication the type the setting should be converted to. For example ``True`` (type is boolean), meaning that - we convert the string ``true`` to a python boolean. - - **Note**, this method only converts a few types and might need to be extended if a certain type is missing! - """ - # On OS X (and probably on other platforms too) empty value from QSettings is represented as type - # PyQt4.QtCore.QPyNullVariant. This type has to be converted to proper 'None' Python type. - if isinstance(setting, QtCore.QPyNullVariant) and setting.isNull(): - setting = None - # Handle 'None' type (empty value) properly. - if setting is None: - # An empty string saved to the settings results in a None type being returned. - # Convert it to empty unicode string. - if isinstance(default_value, str): - return '' - # An empty list saved to the settings results in a None type being returned. - else: - return [] - # Convert the setting to the correct type. - if isinstance(default_value, bool): - if isinstance(setting, bool): - return setting - # Sometimes setting is string instead of a boolean. - return setting == 'true' - if isinstance(default_value, int): - return int(setting) - return setting - - def get_files_from_config(self, plugin): - """ - This removes the settings needed for old way we saved files (e. g. the image paths for the image plugin). A list - of file paths are returned. - - **Note**: Only a list of paths is returned; this does not convert anything! - - ``plugin`` - The Plugin object.The caller has to convert/save the list himself; o - """ - files_list = [] - # We need QSettings instead of Settings here to bypass our central settings dict. - # Do NOT do this anywhere else! - settings = QtCore.QSettings(self.fileName(), Settings.IniFormat) - settings.beginGroup(plugin.settings_section) - if settings.contains('%s count' % plugin.name): - # Get the count. - list_count = int(settings.value('%s count' % plugin.name, 0)) - if list_count: - for counter in range(list_count): - # The keys were named e. g.: "image 0" - item = settings.value('%s %d' % (plugin.name, counter), '') - if item: - files_list.append(item) - settings.remove('%s %d' % (plugin.name, counter)) - settings.remove('%s count' % plugin.name) - settings.endGroup() - return files_list diff --git a/openlp/core/lib/theme.py b/openlp/core/lib/theme.py index c10a59560..98e98ac6e 100644 --- a/openlp/core/lib/theme.py +++ b/openlp/core/lib/theme.py @@ -43,15 +43,6 @@ from openlp.core.lib import str_to_bool, ScreenList, get_text_file_string log = logging.getLogger(__name__) -class ThemeLevel(object): - """ - Provides an enumeration for the level a theme applies to - """ - Global = 1 - Service = 2 - Song = 3 - - class BackgroundType(object): """ Type enumeration for backgrounds. diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index 14ffdc2e8..631187505 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -33,7 +33,8 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, UiStrings, build_icon, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import Registry, build_icon from openlp.core.utils.actions import ActionList diff --git a/openlp/core/ui/aboutdialog.py b/openlp/core/ui/aboutdialog.py index e96553803..f825e9a63 100644 --- a/openlp/core/ui/aboutdialog.py +++ b/openlp/core/ui/aboutdialog.py @@ -29,7 +29,8 @@ from PyQt4 import QtGui -from openlp.core.lib import UiStrings, build_icon, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import build_icon from openlp.core.lib.ui import create_button, create_button_box diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index fbd44a9f8..50bdc57fa 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -36,10 +36,9 @@ import sys from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation -from openlp.core.lib import SettingsTab, Settings, UiStrings, translate, build_icon +from openlp.core.common import AppLocation, Settings, SlideLimits, UiStrings, translate +from openlp.core.lib import SettingsTab, build_icon from openlp.core.utils import format_time, get_images_filter -from openlp.core.lib import SlideLimits log = logging.getLogger(__name__) diff --git a/openlp/core/ui/exceptionform.py b/openlp/core/ui/exceptionform.py index 2dc034f71..b2427e009 100644 --- a/openlp/core/ui/exceptionform.py +++ b/openlp/core/ui/exceptionform.py @@ -85,7 +85,7 @@ try: except ImportError: VLC_VERSION = '-' -from openlp.core.lib import UiStrings, Settings, translate +from openlp.core.common import Settings, UiStrings, translate from openlp.core.utils import get_application_version from .exceptiondialog import Ui_ExceptionDialog diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index cbb5434f9..31d9cf198 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -41,8 +41,8 @@ from configparser import SafeConfigParser from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation, check_directory_exists -from openlp.core.lib import PluginStatus, Settings, Registry, build_icon, translate +from openlp.core.common import AppLocation, Settings, check_directory_exists +from openlp.core.lib import PluginStatus, Registry, build_icon, translate from openlp.core.utils import get_web_page from .firsttimewizard import Ui_FirstTimeWizard, FirstTimePage diff --git a/openlp/core/ui/formattingtagdialog.py b/openlp/core/ui/formattingtagdialog.py index 6d7dd2453..f7855e470 100644 --- a/openlp/core/ui/formattingtagdialog.py +++ b/openlp/core/ui/formattingtagdialog.py @@ -31,7 +31,8 @@ The UI widgets for the formatting tags window. """ from PyQt4 import QtCore, QtGui -from openlp.core.lib import UiStrings, translate, build_icon +from openlp.core.common import UiStrings, translate +from openlp.core.lib import build_icon from openlp.core.lib.ui import create_button_box diff --git a/openlp/core/ui/generaltab.py b/openlp/core/ui/generaltab.py index 42bba94d3..2e758ed34 100644 --- a/openlp/core/ui/generaltab.py +++ b/openlp/core/ui/generaltab.py @@ -33,7 +33,8 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, Settings, SettingsTab, ScreenList, UiStrings, translate +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import Registry, SettingsTab, ScreenList log = logging.getLogger(__name__) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index f2c1033ed..541e5002a 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -44,7 +44,8 @@ import sys from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL from PyQt4.phonon import Phonon -from openlp.core.lib import ServiceItem, Settings, ImageSource, Registry, build_html, expand_tags, \ +from openlp.core.common import Settings +from openlp.core.lib import ServiceItem, ImageSource, Registry, build_html, expand_tags, \ image_to_byte, translate from openlp.core.lib.theme import BackgroundType diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 4110c5e04..f397e3306 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -42,12 +42,12 @@ from datetime import datetime from PyQt4 import QtCore, QtGui from openlp.core.lib import Renderer, OpenLPDockWidget, PluginManager, ImageManager, PluginStatus, Registry, \ - Settings, ScreenList, build_icon, translate + ScreenList, build_icon, translate from openlp.core.lib.ui import UiStrings, create_action from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, SlideController, PluginForm, \ MediaDockManager, ShortcutListForm, FormattingTagForm -from openlp.core.common import AppLocation, check_directory_exists +from openlp.core.common import AppLocation, Settings, check_directory_exists from openlp.core.ui.media import MediaController from openlp.core.utils import LanguageManager, add_actions, get_application_version from openlp.core.utils.actions import ActionList, CategoryOrder diff --git a/openlp/core/ui/media/__init__.py b/openlp/core/ui/media/__init__.py index 19771862f..02c22fc68 100644 --- a/openlp/core/ui/media/__init__.py +++ b/openlp/core/ui/media/__init__.py @@ -31,7 +31,7 @@ The :mod:`~openlp.core.ui.media` module contains classes and objects for media p """ import logging -from openlp.core.lib import Settings +from openlp.core.common import Settings from PyQt4 import QtCore diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index 83b9630fc..eb2d932ee 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -35,7 +35,8 @@ import os import datetime from PyQt4 import QtCore, QtGui -from openlp.core.lib import OpenLPToolbar, Settings, Registry, UiStrings, translate +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import OpenLPToolbar, Registry from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.media import MediaState, MediaInfo, MediaType, get_media_players, set_media_players from openlp.core.ui.media.mediaplayer import MediaPlayer diff --git a/openlp/core/ui/media/phononplayer.py b/openlp/core/ui/media/phononplayer.py index 0ea0bf2ff..fadd8a694 100644 --- a/openlp/core/ui/media/phononplayer.py +++ b/openlp/core/ui/media/phononplayer.py @@ -36,7 +36,8 @@ from datetime import datetime from PyQt4 import QtGui from PyQt4.phonon import Phonon -from openlp.core.lib import Settings, translate +from openlp.core.common import Settings +from openlp.core.lib import translate from openlp.core.ui.media import MediaState from openlp.core.ui.media.mediaplayer import MediaPlayer diff --git a/openlp/core/ui/media/playertab.py b/openlp/core/ui/media/playertab.py index b01f37ac7..4aa9feb0f 100644 --- a/openlp/core/ui/media/playertab.py +++ b/openlp/core/ui/media/playertab.py @@ -31,7 +31,8 @@ The :mod:`~openlp.core.ui.media.playertab` module holds the configuration tab fo """ from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, SettingsTab, Settings, UiStrings, translate +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import Registry, SettingsTab from openlp.core.lib.ui import create_button from openlp.core.ui.media import get_media_players, set_media_players diff --git a/openlp/core/ui/media/vlcplayer.py b/openlp/core/ui/media/vlcplayer.py index 2055f287b..139751603 100644 --- a/openlp/core/ui/media/vlcplayer.py +++ b/openlp/core/ui/media/vlcplayer.py @@ -37,7 +37,8 @@ import sys from PyQt4 import QtGui -from openlp.core.lib import Settings, translate +from openlp.core.common import Settings +from openlp.core.lib import translate from openlp.core.ui.media import MediaState from openlp.core.ui.media.mediaplayer import MediaPlayer diff --git a/openlp/core/ui/media/webkitplayer.py b/openlp/core/ui/media/webkitplayer.py index 3983a1e8d..c8cae2d13 100644 --- a/openlp/core/ui/media/webkitplayer.py +++ b/openlp/core/ui/media/webkitplayer.py @@ -33,7 +33,8 @@ from PyQt4 import QtGui import logging -from openlp.core.lib import Settings, translate +from openlp.core.common import Settings +from openlp.core.lib import translate from openlp.core.ui.media import MediaState from openlp.core.ui.media.mediaplayer import MediaPlayer diff --git a/openlp/core/ui/plugindialog.py b/openlp/core/ui/plugindialog.py index d0bc0f103..fe7a185d6 100644 --- a/openlp/core/ui/plugindialog.py +++ b/openlp/core/ui/plugindialog.py @@ -31,7 +31,7 @@ The UI widgets of the plugin view dialog #""" from PyQt4 import QtCore, QtGui -from openlp.core.lib import UiStrings, translate +from openlp.core.common import UiStrings, translate from openlp.core.lib.ui import create_button_box diff --git a/openlp/core/ui/printservicedialog.py b/openlp/core/ui/printservicedialog.py index 6f007cf64..13308d6aa 100644 --- a/openlp/core/ui/printservicedialog.py +++ b/openlp/core/ui/printservicedialog.py @@ -31,7 +31,8 @@ The UI widgets of the print service dialog. """ from PyQt4 import QtCore, QtGui -from openlp.core.lib import SpellTextEdit, UiStrings, build_icon, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import SpellTextEdit, build_icon class ZoomSize(object): diff --git a/openlp/core/ui/printserviceform.py b/openlp/core/ui/printserviceform.py index 153b6bed9..6c2dab2be 100644 --- a/openlp/core/ui/printserviceform.py +++ b/openlp/core/ui/printserviceform.py @@ -36,7 +36,8 @@ import os from PyQt4 import QtCore, QtGui from lxml import html -from openlp.core.lib import Settings, UiStrings, Registry, translate, get_text_file_string +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import Registry, get_text_file_string from openlp.core.ui.printservicedialog import Ui_PrintServiceDialog, ZoomSize from openlp.core.common import AppLocation diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index ee4fa850f..20989bb90 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -42,10 +42,10 @@ log = logging.getLogger(__name__) from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation, check_directory_exists -from openlp.core.lib import OpenLPToolbar, ServiceItem, ItemCapabilities, Settings, PluginStatus, Registry, \ - UiStrings, build_icon, translate -from openlp.core.lib.theme import ThemeLevel +from openlp.core.common import AppLocation, Settings, check_directory_exists, UiStrings, translate +from openlp.core.lib import OpenLPToolbar, ServiceItem, ItemCapabilities, PluginStatus, Registry, \ + build_icon +from openlp.core.common import ThemeLevel from openlp.core.lib.ui import critical_error_message_box, create_widget_action, find_and_set_in_combo_box from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm from openlp.core.ui.printserviceform import PrintServiceForm diff --git a/openlp/core/ui/shortcutlistform.py b/openlp/core/ui/shortcutlistform.py index f49b66678..efe876e3e 100644 --- a/openlp/core/ui/shortcutlistform.py +++ b/openlp/core/ui/shortcutlistform.py @@ -33,8 +33,8 @@ import re from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, Settings -from openlp.core.utils import translate +from openlp.core.lib import Registry +from openlp.core.common import Settings, translate from openlp.core.utils.actions import ActionList from .shortcutlistdialog import Ui_ShortcutListDialog diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index a04af6525..171a24f16 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -37,8 +37,9 @@ from collections import deque from PyQt4 import QtCore, QtGui -from openlp.core.lib import OpenLPToolbar, ItemCapabilities, ServiceItem, ImageSource, SlideLimits, \ - ServiceItemAction, Settings, Registry, UiStrings, ScreenList, build_icon, build_html, translate +from openlp.core.common import Settings, SlideLimits, UiStrings, translate +from openlp.core.lib import OpenLPToolbar, ItemCapabilities, ServiceItem, ImageSource, \ + ServiceItemAction, Registry, ScreenList, build_icon, build_html from openlp.core.ui import HideMode, MainDisplay, Display, DisplayControllerType from openlp.core.lib.ui import create_action from openlp.core.utils.actions import ActionList, CategoryOrder diff --git a/openlp/core/ui/starttimedialog.py b/openlp/core/ui/starttimedialog.py index dfd794f26..24e11c14e 100644 --- a/openlp/core/ui/starttimedialog.py +++ b/openlp/core/ui/starttimedialog.py @@ -31,7 +31,7 @@ The UI widgets for the time dialog """ from PyQt4 import QtCore, QtGui -from openlp.core.lib import UiStrings, translate +from openlp.core.common import UiStrings, translate from openlp.core.lib.ui import create_button_box diff --git a/openlp/core/ui/starttimeform.py b/openlp/core/ui/starttimeform.py index 0a0867b3f..308453978 100644 --- a/openlp/core/ui/starttimeform.py +++ b/openlp/core/ui/starttimeform.py @@ -33,7 +33,8 @@ from PyQt4 import QtGui from .starttimedialog import Ui_StartTimeDialog -from openlp.core.lib import UiStrings, Registry, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import Registry from openlp.core.lib.ui import critical_error_message_box diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index fe92d679b..46f632827 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -34,7 +34,8 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.lib import UiStrings, Registry, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import Registry from openlp.core.lib.theme import BackgroundType, BackgroundGradientType from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui import ThemeLayoutForm diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 8dd0727ea..daee4c320 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -38,9 +38,9 @@ import re from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation, check_directory_exists -from openlp.core.lib import ImageSource, OpenLPToolbar, Registry, Settings, UiStrings, get_text_file_string, \ - build_icon, translate, check_item_selected, create_thumb, validate_thumb +from openlp.core.common import AppLocation, Settings, check_directory_exists, UiStrings, translate +from openlp.core.lib import ImageSource, OpenLPToolbar, Registry, get_text_file_string, \ + build_icon, check_item_selected, create_thumb, validate_thumb from openlp.core.lib.theme import ThemeXML, BackgroundType from openlp.core.lib.ui import critical_error_message_box, create_widget_action from openlp.core.ui import FileRenameForm, ThemeForm, ThemeManagerHelper diff --git a/openlp/core/ui/themestab.py b/openlp/core/ui/themestab.py index c3c93f3af..be06f6ffc 100644 --- a/openlp/core/ui/themestab.py +++ b/openlp/core/ui/themestab.py @@ -33,8 +33,8 @@ The Themes configuration tab from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, Settings, SettingsTab, UiStrings, translate -from openlp.core.lib.theme import ThemeLevel +from openlp.core.common import Settings, ThemeLevel, UiStrings, translate +from openlp.core.lib import Registry, SettingsTab from openlp.core.lib.ui import find_and_set_in_combo_box diff --git a/openlp/core/ui/themewizard.py b/openlp/core/ui/themewizard.py index f0674e924..d681a4428 100644 --- a/openlp/core/ui/themewizard.py +++ b/openlp/core/ui/themewizard.py @@ -31,7 +31,8 @@ The Create/Edit theme wizard """ from PyQt4 import QtCore, QtGui -from openlp.core.lib import UiStrings, build_icon, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import build_icon from openlp.core.lib.theme import HorizontalType, BackgroundType, BackgroundGradientType from openlp.core.lib.ui import add_welcome_page, create_valign_selection_widgets diff --git a/openlp/core/ui/wizard.py b/openlp/core/ui/wizard.py index 3a8669b1c..255695a65 100644 --- a/openlp/core/ui/wizard.py +++ b/openlp/core/ui/wizard.py @@ -32,9 +32,10 @@ The :mod:``wizard`` module provides generic wizard tools for OpenLP. import logging import os -from PyQt4 import QtCore, QtGui +from PyQt4 import QtGui -from openlp.core.lib import Registry, Settings, UiStrings, build_icon, translate +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import Registry, build_icon from openlp.core.lib.ui import add_welcome_page log = logging.getLogger(__name__) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index d07153a2a..c75e8782a 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -43,8 +43,8 @@ import urllib.parse from PyQt4 import QtGui, QtCore -from openlp.core.common import AppLocation -from openlp.core.lib import Registry, Settings +from openlp.core.common import AppLocation, Settings +from openlp.core.lib import Registry if sys.platform != 'win32' and sys.platform != 'darwin': diff --git a/openlp/core/utils/actions.py b/openlp/core/utils/actions.py index 6feeda276..82619a6e7 100644 --- a/openlp/core/utils/actions.py +++ b/openlp/core/utils/actions.py @@ -34,7 +34,7 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import Settings +from openlp.core.common import Settings log = logging.getLogger(__name__) diff --git a/openlp/core/utils/languagemanager.py b/openlp/core/utils/languagemanager.py index d6b3cd668..63f2e6f24 100644 --- a/openlp/core/utils/languagemanager.py +++ b/openlp/core/utils/languagemanager.py @@ -35,8 +35,8 @@ import sys from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation -from openlp.core.lib import Settings, translate +from openlp.core.common import AppLocation, Settings +from openlp.core.lib import translate log = logging.getLogger(__name__) diff --git a/openlp/plugins/alerts/alertsplugin.py b/openlp/plugins/alerts/alertsplugin.py index b13230196..1dcdb13c7 100644 --- a/openlp/plugins/alerts/alertsplugin.py +++ b/openlp/plugins/alerts/alertsplugin.py @@ -31,7 +31,8 @@ import logging from PyQt4 import QtGui -from openlp.core.lib import Plugin, Settings, StringContent, build_icon, translate +from openlp.core.common import Settings +from openlp.core.lib import Plugin, StringContent, build_icon, translate from openlp.core.lib.db import Manager from openlp.core.lib.ui import create_action, UiStrings from openlp.core.lib.theme import VerticalType diff --git a/openlp/plugins/alerts/lib/alertstab.py b/openlp/plugins/alerts/lib/alertstab.py index f57caaf7c..5a1512c4b 100644 --- a/openlp/plugins/alerts/lib/alertstab.py +++ b/openlp/plugins/alerts/lib/alertstab.py @@ -29,7 +29,8 @@ from PyQt4 import QtGui -from openlp.core.lib import SettingsTab, Settings, UiStrings, translate +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import SettingsTab from openlp.core.lib.ui import create_valign_selection_widgets diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index 93bb5d565..f99d8138b 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -34,8 +34,7 @@ import os from PyQt4 import QtGui -from openlp.core.common import AppLocation -from openlp.core.lib import Settings, UiStrings, translate +from openlp.core.common import AppLocation, Settings, UiStrings, translate from openlp.core.lib.db import delete_database from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index ca74d6666..cc164363b 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -36,8 +36,8 @@ from tempfile import gettempdir from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation, check_directory_exists -from openlp.core.lib import Registry, Settings, UiStrings, translate +from openlp.core.common import AppLocation, UiStrings, Settings, check_directory_exists, translate +from openlp.core.lib import Registry from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings from openlp.core.utils import delete_file diff --git a/openlp/plugins/bibles/forms/booknamedialog.py b/openlp/plugins/bibles/forms/booknamedialog.py index 90a5bae40..605a4fb95 100644 --- a/openlp/plugins/bibles/forms/booknamedialog.py +++ b/openlp/plugins/bibles/forms/booknamedialog.py @@ -29,7 +29,7 @@ from PyQt4 import QtCore, QtGui -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import create_button_box class Ui_BookNameDialog(object): diff --git a/openlp/plugins/bibles/forms/booknameform.py b/openlp/plugins/bibles/forms/booknameform.py index 04a0e2fe7..1fb359c86 100644 --- a/openlp/plugins/bibles/forms/booknameform.py +++ b/openlp/plugins/bibles/forms/booknameform.py @@ -36,7 +36,7 @@ import re from PyQt4.QtGui import QDialog from PyQt4 import QtCore -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import critical_error_message_box from openlp.plugins.bibles.forms.booknamedialog import Ui_BookNameDialog from openlp.plugins.bibles.lib import BibleStrings diff --git a/openlp/plugins/bibles/forms/editbibledialog.py b/openlp/plugins/bibles/forms/editbibledialog.py index 6e608d8df..6c832f5ee 100644 --- a/openlp/plugins/bibles/forms/editbibledialog.py +++ b/openlp/plugins/bibles/forms/editbibledialog.py @@ -29,7 +29,8 @@ from PyQt4 import QtCore, QtGui -from openlp.core.lib import build_icon, translate +from openlp.core.common import translate +from openlp.core.lib import build_icon from openlp.core.lib.ui import create_button_box from openlp.plugins.bibles.lib import LanguageSelection, BibleStrings from openlp.plugins.bibles.lib.db import BiblesResourcesDB diff --git a/openlp/plugins/bibles/forms/editbibleform.py b/openlp/plugins/bibles/forms/editbibleform.py index e0163a8b8..5e2c94f79 100644 --- a/openlp/plugins/bibles/forms/editbibleform.py +++ b/openlp/plugins/bibles/forms/editbibleform.py @@ -33,7 +33,8 @@ import re from PyQt4 import QtGui -from openlp.core.lib import Registry, UiStrings, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import Registry from openlp.core.lib.ui import critical_error_message_box from .editbibledialog import Ui_EditBibleDialog from openlp.plugins.bibles.lib import BibleStrings diff --git a/openlp/plugins/bibles/forms/languagedialog.py b/openlp/plugins/bibles/forms/languagedialog.py index 533848187..c69eb8828 100644 --- a/openlp/plugins/bibles/forms/languagedialog.py +++ b/openlp/plugins/bibles/forms/languagedialog.py @@ -29,7 +29,7 @@ from PyQt4 import QtGui -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import create_button_box class Ui_LanguageDialog(object): diff --git a/openlp/plugins/bibles/forms/languageform.py b/openlp/plugins/bibles/forms/languageform.py index 88d9906cd..dcfb14462 100644 --- a/openlp/plugins/bibles/forms/languageform.py +++ b/openlp/plugins/bibles/forms/languageform.py @@ -34,7 +34,7 @@ import logging from PyQt4.QtGui import QDialog -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import critical_error_message_box from openlp.plugins.bibles.forms.languagedialog import \ Ui_LanguageDialog diff --git a/openlp/plugins/bibles/lib/__init__.py b/openlp/plugins/bibles/lib/__init__.py index df816d436..38575a974 100644 --- a/openlp/plugins/bibles/lib/__init__.py +++ b/openlp/plugins/bibles/lib/__init__.py @@ -33,7 +33,8 @@ plugin. import logging import re -from openlp.core.lib import Settings, translate +from openlp.core.common import Settings +from openlp.core.lib import translate log = logging.getLogger(__name__) diff --git a/openlp/plugins/bibles/lib/biblestab.py b/openlp/plugins/bibles/lib/biblestab.py index dd95d9b33..807cb2195 100644 --- a/openlp/plugins/bibles/lib/biblestab.py +++ b/openlp/plugins/bibles/lib/biblestab.py @@ -31,7 +31,8 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, SettingsTab, Settings, UiStrings, translate +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import Registry, SettingsTab from openlp.core.lib.ui import find_and_set_in_combo_box from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, update_reference_separators, \ get_reference_separator, LanguageSelection diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index a05d0c301..fc7c31d15 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -30,8 +30,8 @@ import logging import os -from openlp.core.common import AppLocation -from openlp.core.lib import Registry, Settings, translate +from openlp.core.common import AppLocation, Settings +from openlp.core.lib import Registry, translate from openlp.core.utils import delete_file from openlp.plugins.bibles.lib import parse_reference, get_reference_separator, LanguageSelection from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 4ccd37df1..437dfd65e 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -31,8 +31,9 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, ServiceItemContext, Settings, UiStrings, \ - create_separated_list, translate +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, ServiceItemContext, \ + create_separated_list from openlp.core.lib.searchedit import SearchEdit from openlp.core.lib.ui import set_case_insensitive_completer, create_horizontal_adjusting_combo_box, \ critical_error_message_box, find_and_set_in_combo_box, build_icon diff --git a/openlp/plugins/custom/forms/editcustomdialog.py b/openlp/plugins/custom/forms/editcustomdialog.py index 20adefa9a..106b3e339 100644 --- a/openlp/plugins/custom/forms/editcustomdialog.py +++ b/openlp/plugins/custom/forms/editcustomdialog.py @@ -29,7 +29,8 @@ from PyQt4 import QtGui -from openlp.core.lib import UiStrings, build_icon, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import build_icon from openlp.core.lib.ui import create_button_box, create_button diff --git a/openlp/plugins/custom/forms/editcustomslidedialog.py b/openlp/plugins/custom/forms/editcustomslidedialog.py index 80b3c8cc9..bf000d308 100644 --- a/openlp/plugins/custom/forms/editcustomslidedialog.py +++ b/openlp/plugins/custom/forms/editcustomslidedialog.py @@ -29,7 +29,8 @@ from PyQt4 import QtGui -from openlp.core.lib import SpellTextEdit, UiStrings, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import SpellTextEdit from openlp.core.lib.ui import create_button, create_button_box class Ui_CustomSlideEditDialog(object): diff --git a/openlp/plugins/custom/forms/editcustomslideform.py b/openlp/plugins/custom/forms/editcustomslideform.py index 65a8deb68..181f6c6af 100644 --- a/openlp/plugins/custom/forms/editcustomslideform.py +++ b/openlp/plugins/custom/forms/editcustomslideform.py @@ -30,7 +30,7 @@ import logging -from PyQt4 import QtCore, QtGui +from PyQt4 import QtGui from .editcustomslidedialog import Ui_CustomSlideEditDialog diff --git a/openlp/plugins/custom/lib/customtab.py b/openlp/plugins/custom/lib/customtab.py index f62c4547d..c66711f49 100644 --- a/openlp/plugins/custom/lib/customtab.py +++ b/openlp/plugins/custom/lib/customtab.py @@ -33,7 +33,8 @@ for the Custom Slides plugin, which is inserted into the configuration dialog. from PyQt4 import QtCore, QtGui -from openlp.core.lib import SettingsTab, Settings, translate +from openlp.core.common import Settings, translate +from openlp.core.lib import SettingsTab class CustomTab(SettingsTab): diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index f5b518ce8..386045b40 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -32,8 +32,9 @@ import logging from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_, func, and_ -from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, ServiceItemContext, Settings, PluginStatus,\ - UiStrings, check_item_selected, translate +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, ServiceItemContext, PluginStatus,\ + check_item_selected from openlp.plugins.custom.forms.editcustomform import EditCustomForm from openlp.plugins.custom.lib import CustomXMLParser, CustomXMLBuilder from openlp.plugins.custom.lib.db import CustomSlide diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index a6712d941..b82cfa184 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -31,10 +31,11 @@ from PyQt4 import QtGui import logging -from openlp.core.lib import Plugin, StringContent, Registry, ImageSource, Settings, build_icon, translate +from openlp.core.common import Settings +from openlp.core.lib import Plugin, StringContent, Registry, ImageSource, build_icon, translate from openlp.core.lib.db import Manager from openlp.plugins.images.lib import ImageMediaItem, ImageTab -from openlp.plugins.images.lib.db import init_schema, ImageFilenames +from openlp.plugins.images.lib.db import init_schema log = logging.getLogger(__name__) diff --git a/openlp/plugins/images/lib/imagetab.py b/openlp/plugins/images/lib/imagetab.py index b408c1361..20e810b7e 100644 --- a/openlp/plugins/images/lib/imagetab.py +++ b/openlp/plugins/images/lib/imagetab.py @@ -29,7 +29,8 @@ from PyQt4 import QtGui -from openlp.core.lib import Registry, SettingsTab, Settings, UiStrings, translate +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import SettingsTab class ImageTab(SettingsTab): diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index ce7d55e17..976a3d47e 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -32,9 +32,9 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation, check_directory_exists -from openlp.core.lib import ItemCapabilities, MediaManagerItem, Registry, ServiceItemContext, Settings, \ - StringContent, TreeWidgetWithDnD, UiStrings, build_icon, check_item_selected, create_thumb, translate, \ +from openlp.core.common import AppLocation, Settings, UiStrings, check_directory_exists, translate +from openlp.core.lib import ItemCapabilities, MediaManagerItem, Registry, ServiceItemContext, \ + StringContent, TreeWidgetWithDnD, build_icon, check_item_selected, create_thumb, \ validate_thumb from openlp.core.lib.ui import create_widget_action, critical_error_message_box from openlp.core.utils import delete_file, get_locale_key, get_images_filter diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index dc6b1456f..3d2d5b26e 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -32,9 +32,9 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation, check_directory_exists +from openlp.core.common import AppLocation, Settings, check_directory_exists, UiStrings, translate from openlp.core.lib import ItemCapabilities, MediaManagerItem,MediaType, Registry, ServiceItem, ServiceItemContext, \ - Settings, UiStrings, build_icon, check_item_selected, translate + build_icon, check_item_selected from openlp.core.lib.ui import critical_error_message_box, create_horizontal_adjusting_combo_box from openlp.core.ui import DisplayController, Display, DisplayControllerType from openlp.core.ui.media import get_media_players, set_media_players diff --git a/openlp/plugins/media/lib/mediatab.py b/openlp/plugins/media/lib/mediatab.py index 7798b2cf3..40b6a1ea8 100644 --- a/openlp/plugins/media/lib/mediatab.py +++ b/openlp/plugins/media/lib/mediatab.py @@ -29,7 +29,8 @@ from PyQt4 import QtGui -from openlp.core.lib import Settings, SettingsTab, UiStrings, translate +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import SettingsTab class MediaQ_check_box(QtGui.QCheckBox): diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index 896ff95d1..cd432c54c 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -31,7 +31,7 @@ import logging from PyQt4 import QtCore -from openlp.core.lib import Plugin, Registry, StringContent, Settings, build_icon, translate +from openlp.core.lib import Plugin, Registry, StringContent, build_icon, translate from openlp.plugins.media.lib import MediaMediaItem, MediaTab diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 695baddc5..ce0325c7e 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -32,8 +32,9 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.lib import MediaManagerItem, Registry, ItemCapabilities, ServiceItemContext, Settings, UiStrings, \ - build_icon, check_item_selected, create_thumb, translate, validate_thumb +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import MediaManagerItem, Registry, ItemCapabilities, ServiceItemContext, \ + build_icon, check_item_selected, create_thumb, validate_thumb from openlp.core.lib.ui import critical_error_message_box, create_horizontal_adjusting_combo_box from openlp.core.utils import get_locale_key from openlp.plugins.presentations.lib import MessageListener diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index 08584038e..17911606c 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -33,8 +33,8 @@ import shutil from PyQt4 import QtCore -from openlp.core.common import AppLocation, check_directory_exists -from openlp.core.lib import Registry, Settings, create_thumb, validate_thumb +from openlp.core.common import AppLocation, Settings, check_directory_exists +from openlp.core.lib import Registry, create_thumb, validate_thumb log = logging.getLogger(__name__) diff --git a/openlp/plugins/presentations/lib/presentationtab.py b/openlp/plugins/presentations/lib/presentationtab.py index fed02ce75..50b066850 100644 --- a/openlp/plugins/presentations/lib/presentationtab.py +++ b/openlp/plugins/presentations/lib/presentationtab.py @@ -29,7 +29,8 @@ from PyQt4 import QtGui -from openlp.core.lib import Settings, SettingsTab, UiStrings, translate +from openlp.core.common import Settings, UiStrings, translate +from openlp.core.lib import SettingsTab class PresentationTab(SettingsTab): diff --git a/openlp/plugins/remotes/lib/httprouter.py b/openlp/plugins/remotes/lib/httprouter.py index 42b45abc6..ce13ed812 100644 --- a/openlp/plugins/remotes/lib/httprouter.py +++ b/openlp/plugins/remotes/lib/httprouter.py @@ -124,9 +124,8 @@ from urllib.parse import urlparse, parse_qs from mako.template import Template from PyQt4 import QtCore -from openlp.core.common import AppLocation -from openlp.core.lib import Registry, Settings, PluginStatus, StringContent, image_to_byte -from openlp.core.utils import translate +from openlp.core.common import AppLocation, Settings, translate +from openlp.core.lib import Registry, PluginStatus, StringContent, image_to_byte log = logging.getLogger(__name__) diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index a8453fb2b..0ac77115c 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -40,8 +40,7 @@ import logging from PyQt4 import QtCore -from openlp.core.common import AppLocation -from openlp.core.lib import Settings +from openlp.core.common import AppLocation, Settings from openlp.plugins.remotes.lib import HttpRouter diff --git a/openlp/plugins/remotes/lib/remotetab.py b/openlp/plugins/remotes/lib/remotetab.py index d7ae97342..3953d777f 100644 --- a/openlp/plugins/remotes/lib/remotetab.py +++ b/openlp/plugins/remotes/lib/remotetab.py @@ -31,8 +31,8 @@ import os.path from PyQt4 import QtCore, QtGui, QtNetwork -from openlp.core.common import AppLocation -from openlp.core.lib import Settings, SettingsTab, translate +from openlp.core.common import AppLocation, Settings, translate +from openlp.core.lib import SettingsTab ZERO_URL = '0.0.0.0' diff --git a/openlp/plugins/songs/forms/editsongdialog.py b/openlp/plugins/songs/forms/editsongdialog.py index 16e680587..e867aca37 100644 --- a/openlp/plugins/songs/forms/editsongdialog.py +++ b/openlp/plugins/songs/forms/editsongdialog.py @@ -29,7 +29,8 @@ from PyQt4 import QtCore, QtGui -from openlp.core.lib import UiStrings, build_icon, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import build_icon from openlp.core.lib.ui import create_button_box, create_button from openlp.plugins.songs.lib.ui import SongStrings diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 83b4c8d04..ed4676929 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -38,8 +38,8 @@ import shutil from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation, check_directory_exists -from openlp.core.lib import Registry, PluginStatus, MediaType, UiStrings, translate, create_separated_list +from openlp.core.common import AppLocation, UiStrings, check_directory_exists, translate +from openlp.core.lib import Registry, PluginStatus, MediaType, create_separated_list from openlp.core.lib.ui import set_case_insensitive_completer, critical_error_message_box, find_and_set_in_combo_box from openlp.plugins.songs.lib import VerseType, clean_song from openlp.plugins.songs.lib.db import Book, Song, Author, Topic, MediaFile diff --git a/openlp/plugins/songs/forms/songexportform.py b/openlp/plugins/songs/forms/songexportform.py index 26c07395c..f0b9262a7 100644 --- a/openlp/plugins/songs/forms/songexportform.py +++ b/openlp/plugins/songs/forms/songexportform.py @@ -34,7 +34,8 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, UiStrings, create_separated_list, build_icon, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import Registry, create_separated_list, build_icon from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings from openlp.plugins.songs.lib.db import Song diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index f1f63ffb5..2105e5e35 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -35,7 +35,9 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, Settings, UiStrings, translate +from openlp.core.common import UiStrings, translate +from openlp.core.common import Settings +from openlp.core.lib import Registry from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings from openlp.plugins.songs.lib.importer import SongFormat, SongFormatSelect diff --git a/openlp/plugins/songs/forms/songmaintenancedialog.py b/openlp/plugins/songs/forms/songmaintenancedialog.py index ea908fb0f..3e0363772 100644 --- a/openlp/plugins/songs/forms/songmaintenancedialog.py +++ b/openlp/plugins/songs/forms/songmaintenancedialog.py @@ -29,7 +29,8 @@ from PyQt4 import QtCore, QtGui -from openlp.core.lib import UiStrings, build_icon +from openlp.core.common import UiStrings +from openlp.core.lib import build_icon from openlp.core.lib.ui import create_button_box from openlp.plugins.songs.lib.ui import SongStrings diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 67d9ee3ad..142cca1e7 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -32,7 +32,8 @@ import os from PyQt4 import QtGui, QtCore from sqlalchemy.sql import and_ -from openlp.core.lib import Registry, UiStrings, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import Registry from openlp.core.lib.ui import critical_error_message_box from openlp.plugins.songs.forms.authorsform import AuthorsForm from openlp.plugins.songs.forms.topicsform import TopicsForm diff --git a/openlp/plugins/songs/lib/importer.py b/openlp/plugins/songs/lib/importer.py index 8e7a9f36e..acdfddae7 100644 --- a/openlp/plugins/songs/lib/importer.py +++ b/openlp/plugins/songs/lib/importer.py @@ -32,7 +32,7 @@ The :mod:`importer` modules provides the general song import functionality. import os import logging -from openlp.core.lib import translate, UiStrings +from openlp.core.common import translate, UiStrings from openlp.core.ui.wizard import WizardStrings from .opensongimport import OpenSongImport from .easyslidesimport import EasySlidesImport diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index a708948ae..b8b1b5dcd 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -35,9 +35,9 @@ import shutil from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_ -from openlp.core.common import AppLocation, check_directory_exists -from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, PluginStatus, ServiceItemContext, Settings, \ - UiStrings, translate, check_item_selected, create_separated_list +from openlp.core.common import AppLocation, Settings, check_directory_exists, UiStrings, translate +from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, PluginStatus, ServiceItemContext, \ + check_item_selected, create_separated_list from openlp.core.lib.ui import create_widget_action from openlp.plugins.songs.forms.editsongform import EditSongForm from openlp.plugins.songs.forms.songmaintenanceform import SongMaintenanceForm diff --git a/openlp/plugins/songs/lib/olpimport.py b/openlp/plugins/songs/lib/olpimport.py index e95f78232..19078c9ec 100644 --- a/openlp/plugins/songs/lib/olpimport.py +++ b/openlp/plugins/songs/lib/olpimport.py @@ -36,7 +36,7 @@ from sqlalchemy import create_engine, MetaData, Table from sqlalchemy.orm import class_mapper, mapper, relation, scoped_session, sessionmaker from sqlalchemy.orm.exc import UnmappedClassError -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.db import BaseModel from openlp.core.ui.wizard import WizardStrings from openlp.plugins.songs.lib import clean_song diff --git a/openlp/plugins/songs/lib/oooimport.py b/openlp/plugins/songs/lib/oooimport.py index f74c022a7..bb7654d01 100644 --- a/openlp/plugins/songs/lib/oooimport.py +++ b/openlp/plugins/songs/lib/oooimport.py @@ -51,6 +51,7 @@ except ImportError: PAGE_AFTER = 5 PAGE_BOTH = 6 + class OooImport(SongImport): """ Import songs from Impress/Powerpoint docs using Impress diff --git a/openlp/plugins/songs/lib/openlyricsexport.py b/openlp/plugins/songs/lib/openlyricsexport.py index ef62a64f0..8f927dd8c 100644 --- a/openlp/plugins/songs/lib/openlyricsexport.py +++ b/openlp/plugins/songs/lib/openlyricsexport.py @@ -35,8 +35,8 @@ import os from lxml import etree -from openlp.core.common import check_directory_exists -from openlp.core.lib import Registry, translate +from openlp.core.common import check_directory_exists, translate +from openlp.core.lib import Registry from openlp.core.utils import clean_filename from openlp.plugins.songs.lib.xml import OpenLyrics diff --git a/openlp/plugins/songs/lib/opensongimport.py b/openlp/plugins/songs/lib/opensongimport.py index 669f861e3..3e60c9994 100644 --- a/openlp/plugins/songs/lib/opensongimport.py +++ b/openlp/plugins/songs/lib/opensongimport.py @@ -33,13 +33,14 @@ import re from lxml import objectify from lxml.etree import Error, LxmlError -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.plugins.songs.lib import VerseType from openlp.plugins.songs.lib.songimport import SongImport from openlp.plugins.songs.lib.ui import SongStrings log = logging.getLogger(__name__) + class OpenSongImport(SongImport): """ Import songs exported from OpenSong diff --git a/openlp/plugins/songs/lib/powersongimport.py b/openlp/plugins/songs/lib/powersongimport.py index 7ab802505..88cea0b72 100644 --- a/openlp/plugins/songs/lib/powersongimport.py +++ b/openlp/plugins/songs/lib/powersongimport.py @@ -34,7 +34,7 @@ import logging import fnmatch import os -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.plugins.songs.lib.songimport import SongImport log = logging.getLogger(__name__) diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 378f18272..ead897e0e 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -34,8 +34,8 @@ import os from PyQt4 import QtCore -from openlp.core.common import AppLocation, check_directory_exists -from openlp.core.lib import Registry, translate +from openlp.core.common import AppLocation, check_directory_exists, translate +from openlp.core.lib import Registry from openlp.core.ui.wizard import WizardStrings from openlp.plugins.songs.lib import clean_song, VerseType from openlp.plugins.songs.lib.db import Song, Author, Topic, Book, MediaFile diff --git a/openlp/plugins/songs/lib/songproimport.py b/openlp/plugins/songs/lib/songproimport.py index 5673eaa34..a7384afd3 100644 --- a/openlp/plugins/songs/lib/songproimport.py +++ b/openlp/plugins/songs/lib/songproimport.py @@ -35,6 +35,7 @@ import re from openlp.plugins.songs.lib import strip_rtf from openlp.plugins.songs.lib.songimport import SongImport + class SongProImport(SongImport): """ The :class:`SongProImport` class provides the ability to import song files diff --git a/openlp/plugins/songs/lib/songshowplusimport.py b/openlp/plugins/songs/lib/songshowplusimport.py index 35cd44b8a..a82ae0c98 100644 --- a/openlp/plugins/songs/lib/songshowplusimport.py +++ b/openlp/plugins/songs/lib/songshowplusimport.py @@ -27,8 +27,8 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ -The :mod:`songshowplusimport` module provides the functionality for importing -SongShow Plus songs into the OpenLP database. +The :mod:`songshowplusimport` module provides the functionality for importing SongShow Plus songs into the OpenLP +database. """ import chardet import os @@ -56,6 +56,7 @@ CUSTOM_VERSE = 37 log = logging.getLogger(__name__) + class SongShowPlusImport(SongImport): """ The :class:`SongShowPlusImport` class provides the ability to import song files from SongShow Plus. diff --git a/openlp/plugins/songs/lib/songstab.py b/openlp/plugins/songs/lib/songstab.py index f2a36e0c8..c422f1231 100644 --- a/openlp/plugins/songs/lib/songstab.py +++ b/openlp/plugins/songs/lib/songstab.py @@ -29,7 +29,8 @@ from PyQt4 import QtCore, QtGui -from openlp.core.lib import Settings, SettingsTab, translate +from openlp.core.common import Settings, translate +from openlp.core.lib import SettingsTab class SongsTab(SettingsTab): diff --git a/openlp/plugins/songs/lib/ui.py b/openlp/plugins/songs/lib/ui.py index de864b470..ce876fe81 100644 --- a/openlp/plugins/songs/lib/ui.py +++ b/openlp/plugins/songs/lib/ui.py @@ -32,6 +32,7 @@ for the songs plugin. """ from openlp.core.lib import translate + class SongStrings(object): """ Provide standard strings for use throughout the songs plugin. diff --git a/openlp/plugins/songs/lib/worshipcenterproimport.py b/openlp/plugins/songs/lib/worshipcenterproimport.py index b1de90634..a58ace982 100644 --- a/openlp/plugins/songs/lib/worshipcenterproimport.py +++ b/openlp/plugins/songs/lib/worshipcenterproimport.py @@ -34,7 +34,7 @@ import logging import pyodbc -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.plugins.songs.lib.songimport import SongImport log = logging.getLogger(__name__) diff --git a/openlp/plugins/songs/lib/wowimport.py b/openlp/plugins/songs/lib/wowimport.py index 3f06b4df8..8e9023e2f 100644 --- a/openlp/plugins/songs/lib/wowimport.py +++ b/openlp/plugins/songs/lib/wowimport.py @@ -33,7 +33,7 @@ Worship songs into the OpenLP database. import os import logging -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.plugins.songs.lib.songimport import SongImport BLOCK_TYPES = ('V', 'C', 'B') diff --git a/openlp/plugins/songs/lib/xml.py b/openlp/plugins/songs/lib/xml.py index e788948b6..de1d33a22 100644 --- a/openlp/plugins/songs/lib/xml.py +++ b/openlp/plugins/songs/lib/xml.py @@ -68,7 +68,8 @@ import re from lxml import etree, objectify -from openlp.core.lib import FormattingTags, translate +from openlp.core.common import translate +from openlp.core.lib import FormattingTags from openlp.plugins.songs.lib import VerseType, clean_song from openlp.plugins.songs.lib.db import Author, Book, Song, Topic from openlp.core.utils import get_application_version diff --git a/openlp/plugins/songs/lib/zionworximport.py b/openlp/plugins/songs/lib/zionworximport.py index 50839f832..315f99708 100644 --- a/openlp/plugins/songs/lib/zionworximport.py +++ b/openlp/plugins/songs/lib/zionworximport.py @@ -33,7 +33,7 @@ ZionWorx songs into the OpenLP database. import csv import logging -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.plugins.songs.lib.songimport import SongImport log = logging.getLogger(__name__) diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 3418dd7e4..6e6f7ea77 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -38,7 +38,8 @@ import sqlite3 from PyQt4 import QtCore, QtGui -from openlp.core.lib import Plugin, StringContent, UiStrings, build_icon, translate +from openlp.core.common import UiStrings, translate +from openlp.core.lib import Plugin, StringContent, build_icon from openlp.core.lib.db import Manager from openlp.core.lib.ui import create_action from openlp.core.utils.actions import ActionList diff --git a/openlp/plugins/songusage/forms/songusagedeletedialog.py b/openlp/plugins/songusage/forms/songusagedeletedialog.py index a47afb9f4..4c7b57285 100644 --- a/openlp/plugins/songusage/forms/songusagedeletedialog.py +++ b/openlp/plugins/songusage/forms/songusagedeletedialog.py @@ -29,7 +29,7 @@ from PyQt4 import QtCore, QtGui -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import create_button_box diff --git a/openlp/plugins/songusage/forms/songusagedeleteform.py b/openlp/plugins/songusage/forms/songusagedeleteform.py index 4ae9756b3..babd9d178 100644 --- a/openlp/plugins/songusage/forms/songusagedeleteform.py +++ b/openlp/plugins/songusage/forms/songusagedeleteform.py @@ -27,9 +27,10 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -from PyQt4 import QtCore, QtGui +from PyQt4 import QtGui -from openlp.core.lib import Registry, translate +from openlp.core.common import translate +from openlp.core.lib import Registry from openlp.plugins.songusage.lib.db import SongUsageItem from .songusagedeletedialog import Ui_SongUsageDeleteDialog diff --git a/openlp/plugins/songusage/forms/songusagedetaildialog.py b/openlp/plugins/songusage/forms/songusagedetaildialog.py index efe84a7c8..278feebf8 100644 --- a/openlp/plugins/songusage/forms/songusagedetaildialog.py +++ b/openlp/plugins/songusage/forms/songusagedetaildialog.py @@ -29,7 +29,8 @@ from PyQt4 import QtCore, QtGui -from openlp.core.lib import build_icon, translate +from openlp.core.common import translate +from openlp.core.lib import build_icon from openlp.core.lib.ui import create_button_box diff --git a/openlp/plugins/songusage/forms/songusagedetailform.py b/openlp/plugins/songusage/forms/songusagedetailform.py index e5925da78..6ff73b068 100644 --- a/openlp/plugins/songusage/forms/songusagedetailform.py +++ b/openlp/plugins/songusage/forms/songusagedetailform.py @@ -33,8 +33,8 @@ import os from PyQt4 import QtGui from sqlalchemy.sql import and_ -from openlp.core.common import check_directory_exists -from openlp.core.lib import Registry, Settings, translate +from openlp.core.common import Settings, check_directory_exists, translate +from openlp.core.lib import Registry from openlp.plugins.songusage.lib.db import SongUsageItem from .songusagedetaildialog import Ui_SongUsageDetailDialog diff --git a/openlp/plugins/songusage/songusageplugin.py b/openlp/plugins/songusage/songusageplugin.py index bed0e5be3..077b81155 100644 --- a/openlp/plugins/songusage/songusageplugin.py +++ b/openlp/plugins/songusage/songusageplugin.py @@ -32,7 +32,8 @@ from datetime import datetime from PyQt4 import QtCore, QtGui -from openlp.core.lib import Plugin, Registry, Settings, StringContent, build_icon, translate +from openlp.core.common import Settings, translate +from openlp.core.lib import Plugin, Registry, StringContent, build_icon from openlp.core.lib.db import Manager from openlp.core.lib.ui import create_action from openlp.core.utils.actions import ActionList diff --git a/tests/functional/openlp_core_common/test_applocation.py b/tests/functional/openlp_core_common/test_applocation.py index 7ce891bd9..28db96e43 100644 --- a/tests/functional/openlp_core_common/test_applocation.py +++ b/tests/functional/openlp_core_common/test_applocation.py @@ -46,7 +46,7 @@ class TestAppLocation(TestCase): """ Test the AppLocation.get_data_path() method """ - with patch('openlp.core.lib.Settings') as mocked_class, \ + with patch('openlp.core.common.Settings') as mocked_class, \ patch('openlp.core.common.AppLocation.get_directory') as mocked_get_directory, \ patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists, \ patch('openlp.core.common.applocation.os') as mocked_os: @@ -59,6 +59,7 @@ class TestAppLocation(TestCase): # WHEN: we call AppLocation.get_data_path() data_path = AppLocation.get_data_path() + print(data_path) # THEN: check that all the correct methods were called, and the result is correct mocked_settings.contains.assert_called_with('advanced/data path') @@ -70,7 +71,7 @@ class TestAppLocation(TestCase): """ Test the AppLocation.get_data_path() method when a custom location is set in the settings """ - with patch('openlp.core.lib.Settings') as mocked_class,\ + with patch('openlp.core.common.Settings') as mocked_class,\ patch('openlp.core.common.applocation.os') as mocked_os: # GIVEN: A mocked out Settings class which returns a custom data location mocked_settings = mocked_class.return_value diff --git a/tests/functional/openlp_core_lib/test_settings.py b/tests/functional/openlp_core_common/test_settings.py similarity index 99% rename from tests/functional/openlp_core_lib/test_settings.py rename to tests/functional/openlp_core_common/test_settings.py index 25647a6e1..f51cb7379 100644 --- a/tests/functional/openlp_core_lib/test_settings.py +++ b/tests/functional/openlp_core_common/test_settings.py @@ -35,7 +35,7 @@ from tempfile import mkstemp from PyQt4 import QtGui -from openlp.core.lib import Settings +from openlp.core.common import Settings class TestSettings(TestCase): diff --git a/tests/functional/openlp_core_lib/test_uistrings.py b/tests/functional/openlp_core_common/test_uistrings.py similarity index 98% rename from tests/functional/openlp_core_lib/test_uistrings.py rename to tests/functional/openlp_core_common/test_uistrings.py index fbfe07c78..b7f5ecc23 100644 --- a/tests/functional/openlp_core_lib/test_uistrings.py +++ b/tests/functional/openlp_core_common/test_uistrings.py @@ -31,7 +31,7 @@ Package to test the openlp.core.lib.uistrings package. """ from unittest import TestCase -from openlp.core.lib import UiStrings +from openlp.core.common import UiStrings class TestUiStrings(TestCase): diff --git a/tests/functional/openlp_core_lib/test_formattingtags.py b/tests/functional/openlp_core_lib/test_formattingtags.py index a200318ff..53d7519c7 100644 --- a/tests/functional/openlp_core_lib/test_formattingtags.py +++ b/tests/functional/openlp_core_lib/test_formattingtags.py @@ -59,7 +59,7 @@ class TestFormattingTags(TestCase): Test the FormattingTags class' get_html_tags static method. """ with patch('openlp.core.lib.translate') as mocked_translate, \ - patch('openlp.core.lib.settings') as mocked_settings, \ + patch('openlp.core.common.settings') as mocked_settings, \ patch('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 @@ -80,7 +80,7 @@ class TestFormattingTags(TestCase): FormattingTags class - test the get_html_tags(), add_html_tags() and remove_html_tag() methods. """ with patch('openlp.core.lib.translate') as mocked_translate, \ - patch('openlp.core.lib.settings') as mocked_settings, \ + patch('openlp.core.common.settings') as mocked_settings, \ patch('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 diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 6ba7eddbb..361b8d2cb 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -36,8 +36,8 @@ from datetime import datetime, timedelta from PyQt4 import QtCore, QtGui -from openlp.core.common import check_directory_exists -from openlp.core.lib import str_to_bool, create_thumb, translate, get_text_file_string, \ +from openlp.core.common import check_directory_exists, translate +from openlp.core.lib import str_to_bool, create_thumb, get_text_file_string, \ build_icon, image_to_byte, check_item_selected, validate_thumb, create_separated_list, clean_tags, expand_tags from tests.functional import MagicMock, patch diff --git a/tests/functional/openlp_core_lib/test_pluginmanager.py b/tests/functional/openlp_core_lib/test_pluginmanager.py index eb6d80f8c..725efd29e 100644 --- a/tests/functional/openlp_core_lib/test_pluginmanager.py +++ b/tests/functional/openlp_core_lib/test_pluginmanager.py @@ -31,8 +31,9 @@ Package to test the openlp.core.lib.pluginmanager package. """ from unittest import TestCase +from openlp.core.common import Settings from openlp.core.lib.pluginmanager import PluginManager -from openlp.core.lib import Settings, Registry, PluginStatus +from openlp.core.lib import Registry, PluginStatus from tests.functional import MagicMock diff --git a/tests/functional/openlp_core_utils/test_actions.py b/tests/functional/openlp_core_utils/test_actions.py index 42a7c7079..6b4972b37 100644 --- a/tests/functional/openlp_core_utils/test_actions.py +++ b/tests/functional/openlp_core_utils/test_actions.py @@ -35,7 +35,7 @@ from unittest import TestCase from PyQt4 import QtGui, QtCore -from openlp.core.lib import Settings +from openlp.core.common import Settings from openlp.core.utils import ActionList diff --git a/tests/functional/openlp_plugins/remotes/test_remotetab.py b/tests/functional/openlp_plugins/remotes/test_remotetab.py index cd32479d4..067c5cff1 100644 --- a/tests/functional/openlp_plugins/remotes/test_remotetab.py +++ b/tests/functional/openlp_plugins/remotes/test_remotetab.py @@ -36,7 +36,7 @@ from tempfile import mkstemp from PyQt4 import QtGui -from openlp.core.lib import Settings +from openlp.core.common import Settings from openlp.plugins.remotes.lib.remotetab import RemoteTab from tests.functional import patch @@ -105,7 +105,7 @@ class TestRemoteTab(TestCase): Test the set_urls function with standard defaults """ # GIVEN: A mocked location - with patch('openlp.core.lib.Settings') as mocked_class, \ + with patch('openlp.core.common.Settings') as mocked_class, \ patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ patch('openlp.core.common.check_directory_exists') as mocked_check_directory_exists, \ patch('openlp.core.common.applocation.os') as mocked_os: @@ -133,7 +133,7 @@ class TestRemoteTab(TestCase): Test the set_urls function with certificate available """ # GIVEN: A mocked location - with patch('openlp.core.lib.Settings') as mocked_class, \ + with patch('openlp.core.common.Settings') as mocked_class, \ patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ patch('openlp.core.common.check_directory_exists') as mocked_check_directory_exists, \ patch('openlp.core.common.applocation.os') as mocked_os: diff --git a/tests/functional/openlp_plugins/remotes/test_router.py b/tests/functional/openlp_plugins/remotes/test_router.py index 9b1b1dbb3..a9ba16bf8 100644 --- a/tests/functional/openlp_plugins/remotes/test_router.py +++ b/tests/functional/openlp_plugins/remotes/test_router.py @@ -35,7 +35,7 @@ from tempfile import mkstemp from PyQt4 import QtGui -from openlp.core.lib import Settings +from openlp.core.common import Settings from openlp.plugins.remotes.lib.httpserver import HttpRouter from tests.functional import MagicMock diff --git a/tests/functional/openlp_plugins/songs/test_mediaitem.py b/tests/functional/openlp_plugins/songs/test_mediaitem.py index 39f3146de..45c62469c 100644 --- a/tests/functional/openlp_plugins/songs/test_mediaitem.py +++ b/tests/functional/openlp_plugins/songs/test_mediaitem.py @@ -7,7 +7,8 @@ from unittest import TestCase from PyQt4 import QtCore, QtGui -from openlp.core.lib import Registry, ServiceItem, Settings +from openlp.core.common import Settings +from openlp.core.lib import Registry, ServiceItem from openlp.plugins.songs.lib.mediaitem import SongMediaItem from tests.functional import patch, MagicMock diff --git a/tests/interfaces/openlp_core_lib/test_pluginmanager.py b/tests/interfaces/openlp_core_lib/test_pluginmanager.py index dcff55e19..184b04808 100644 --- a/tests/interfaces/openlp_core_lib/test_pluginmanager.py +++ b/tests/interfaces/openlp_core_lib/test_pluginmanager.py @@ -10,8 +10,9 @@ from unittest import TestCase from mock import MagicMock from PyQt4 import QtGui +from openlp.core.common import Settings from openlp.core.lib.pluginmanager import PluginManager -from openlp.core.lib import Registry, Settings +from openlp.core.lib import Registry class TestPluginManager(TestCase): From b9e2a2cdc1313f5505f124eb11f6d92efd78dfb6 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 13 Oct 2013 22:07:28 +0100 Subject: [PATCH 26/46] Missed imports --- openlp/core/lib/db.py | 3 +-- openlp/core/lib/serviceitem.py | 4 ++-- openlp/core/lib/theme.py | 1 - openlp/core/ui/filerenameform.py | 3 ++- openlp/core/ui/firsttimeform.py | 4 ++-- openlp/core/ui/firsttimelanguagedialog.py | 2 +- openlp/core/ui/firsttimewizard.py | 2 +- openlp/core/ui/formattingtagcontroller.py | 4 ++-- openlp/core/ui/formattingtagform.py | 3 ++- openlp/core/ui/maindisplay.py | 5 ++--- openlp/core/ui/mainwindow.py | 4 ++-- openlp/core/ui/pluginform.py | 3 ++- openlp/core/ui/serviceitemeditdialog.py | 2 +- openlp/core/ui/serviceitemeditform.py | 2 +- openlp/core/ui/servicemanager.py | 6 ++---- openlp/core/ui/servicenoteform.py | 3 ++- openlp/core/ui/settingsdialog.py | 3 ++- openlp/core/ui/shortcutlistdialog.py | 3 ++- openlp/core/ui/slidecontroller.py | 4 ++-- openlp/core/ui/themelayoutdialog.py | 2 +- openlp/core/ui/thememanager.py | 4 ++-- openlp/core/utils/__init__.py | 2 +- openlp/core/utils/languagemanager.py | 3 +-- openlp/plugins/alerts/alertsplugin.py | 4 ++-- openlp/plugins/alerts/forms/alertdialog.py | 3 ++- openlp/plugins/alerts/forms/alertform.py | 2 +- openlp/plugins/alerts/lib/alertsmanager.py | 3 ++- openlp/plugins/bibles/lib/csvbible.py | 2 +- openlp/plugins/bibles/lib/db.py | 4 ++-- openlp/plugins/bibles/lib/http.py | 3 ++- openlp/plugins/bibles/lib/manager.py | 4 ++-- openlp/plugins/bibles/lib/mediaitem.py | 3 +-- openlp/plugins/bibles/lib/opensong.py | 2 +- openlp/plugins/bibles/lib/osis.py | 3 +-- openlp/plugins/bibles/lib/versereferencelist.py | 1 + openlp/plugins/images/forms/addgroupdialog.py | 2 +- openlp/plugins/images/forms/addgroupform.py | 2 +- openlp/plugins/images/forms/choosegroupdialog.py | 2 +- openlp/plugins/images/imageplugin.py | 4 ++-- openlp/plugins/images/lib/mediaitem.py | 3 +-- openlp/plugins/media/mediaplugin.py | 3 ++- openlp/plugins/presentations/lib/mediaitem.py | 2 +- openlp/plugins/presentations/presentationplugin.py | 4 ++-- 43 files changed, 65 insertions(+), 63 deletions(-) diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index 6bbca9b5c..429c30262 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -41,8 +41,7 @@ from sqlalchemy.pool import NullPool from alembic.migration import MigrationContext from alembic.operations import Operations -from openlp.core.common import AppLocation, Settings -from openlp.core.lib import translate +from openlp.core.common import AppLocation, Settings, translate from openlp.core.lib.ui import critical_error_message_box from openlp.core.utils import delete_file diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index c1438840b..789854c78 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -39,8 +39,8 @@ import uuid from PyQt4 import QtGui -from openlp.core.common import Settings -from openlp.core.lib import ImageSource, Registry, build_icon, clean_tags, expand_tags, translate +from openlp.core.common import Settings, translate +from openlp.core.lib import ImageSource, Registry, build_icon, clean_tags, expand_tags log = logging.getLogger(__name__) diff --git a/openlp/core/lib/theme.py b/openlp/core/lib/theme.py index 98e98ac6e..e8918e4d1 100644 --- a/openlp/core/lib/theme.py +++ b/openlp/core/lib/theme.py @@ -510,7 +510,6 @@ class ThemeXML(object): """ Create the attributes with the correct data types and name format """ - #print(master, element, value) reject, master, element, value = self._translate_tags(master, element, value) if reject: return diff --git a/openlp/core/ui/filerenameform.py b/openlp/core/ui/filerenameform.py index 79268f560..90fb8c648 100644 --- a/openlp/core/ui/filerenameform.py +++ b/openlp/core/ui/filerenameform.py @@ -34,7 +34,8 @@ from PyQt4 import QtGui from .filerenamedialog import Ui_FileRenameDialog -from openlp.core.lib import translate, Registry +from openlp.core.common import translate +from openlp.core.lib import Registry class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog): diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 31d9cf198..e48395000 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -41,8 +41,8 @@ from configparser import SafeConfigParser from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation, Settings, check_directory_exists -from openlp.core.lib import PluginStatus, Registry, build_icon, translate +from openlp.core.common import AppLocation, Settings, check_directory_exists, translate +from openlp.core.lib import PluginStatus, Registry, build_icon from openlp.core.utils import get_web_page from .firsttimewizard import Ui_FirstTimeWizard, FirstTimePage diff --git a/openlp/core/ui/firsttimelanguagedialog.py b/openlp/core/ui/firsttimelanguagedialog.py index 59dd95053..793d0adab 100644 --- a/openlp/core/ui/firsttimelanguagedialog.py +++ b/openlp/core/ui/firsttimelanguagedialog.py @@ -31,7 +31,7 @@ The UI widgets of the language selection dialog. """ from PyQt4 import QtGui -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import create_button_box diff --git a/openlp/core/ui/firsttimewizard.py b/openlp/core/ui/firsttimewizard.py index 35a27d494..ac51de955 100644 --- a/openlp/core/ui/firsttimewizard.py +++ b/openlp/core/ui/firsttimewizard.py @@ -33,7 +33,7 @@ from PyQt4 import QtCore, QtGui import sys -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import add_welcome_page diff --git a/openlp/core/ui/formattingtagcontroller.py b/openlp/core/ui/formattingtagcontroller.py index 9b891849b..f2c081c51 100644 --- a/openlp/core/ui/formattingtagcontroller.py +++ b/openlp/core/ui/formattingtagcontroller.py @@ -33,8 +33,8 @@ cannot be changed. """ import re - -from openlp.core.lib import FormattingTags, translate +from openlp.core.common import translate +from openlp.core.lib import FormattingTags class FormattingTagController(object): diff --git a/openlp/core/ui/formattingtagform.py b/openlp/core/ui/formattingtagform.py index c6906fc95..420a9c2a2 100644 --- a/openlp/core/ui/formattingtagform.py +++ b/openlp/core/ui/formattingtagform.py @@ -34,7 +34,8 @@ Base Tags cannot be changed. from PyQt4 import QtGui -from openlp.core.lib import FormattingTags, translate +from openlp.core.common import translate +from openlp.core.lib import FormattingTags from openlp.core.ui.formattingtagdialog import Ui_FormattingTagDialog from openlp.core.ui.formattingtagcontroller import FormattingTagController diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 541e5002a..919087569 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -44,9 +44,8 @@ import sys from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL from PyQt4.phonon import Phonon -from openlp.core.common import Settings -from openlp.core.lib import ServiceItem, ImageSource, Registry, build_html, expand_tags, \ - image_to_byte, translate +from openlp.core.common import Settings, translate +from openlp.core.lib import ServiceItem, ImageSource, Registry, build_html, expand_tags, image_to_byte from openlp.core.lib.theme import BackgroundType from openlp.core.lib import ScreenList diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index f397e3306..3382d281d 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -42,12 +42,12 @@ from datetime import datetime from PyQt4 import QtCore, QtGui from openlp.core.lib import Renderer, OpenLPDockWidget, PluginManager, ImageManager, PluginStatus, Registry, \ - ScreenList, build_icon, translate + ScreenList, build_icon from openlp.core.lib.ui import UiStrings, create_action from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, SlideController, PluginForm, \ MediaDockManager, ShortcutListForm, FormattingTagForm -from openlp.core.common import AppLocation, Settings, check_directory_exists +from openlp.core.common import AppLocation, Settings, check_directory_exists, translate from openlp.core.ui.media import MediaController from openlp.core.utils import LanguageManager, add_actions, get_application_version from openlp.core.utils.actions import ActionList, CategoryOrder diff --git a/openlp/core/ui/pluginform.py b/openlp/core/ui/pluginform.py index f0c7dfaf7..504f04d59 100644 --- a/openlp/core/ui/pluginform.py +++ b/openlp/core/ui/pluginform.py @@ -34,7 +34,8 @@ import os from PyQt4 import QtGui -from openlp.core.lib import PluginStatus, Registry, translate +from openlp.core.common import translate +from openlp.core.lib import PluginStatus, Registry from .plugindialog import Ui_PluginViewDialog log = logging.getLogger(__name__) diff --git a/openlp/core/ui/serviceitemeditdialog.py b/openlp/core/ui/serviceitemeditdialog.py index 72b48d8f5..938366d6d 100644 --- a/openlp/core/ui/serviceitemeditdialog.py +++ b/openlp/core/ui/serviceitemeditdialog.py @@ -31,7 +31,7 @@ The UI widgets for the service item edit dialog """ from PyQt4 import QtGui -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import create_button_box, create_button diff --git a/openlp/core/ui/serviceitemeditform.py b/openlp/core/ui/serviceitemeditform.py index ad4168bfd..3e4b053cc 100644 --- a/openlp/core/ui/serviceitemeditform.py +++ b/openlp/core/ui/serviceitemeditform.py @@ -29,7 +29,7 @@ """ The service item edit dialog """ -from PyQt4 import QtCore, QtGui +from PyQt4 import QtGui from openlp.core.lib import Registry from .serviceitemeditdialog import Ui_ServiceItemEditDialog diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 20989bb90..58904fd98 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -42,10 +42,8 @@ log = logging.getLogger(__name__) from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation, Settings, check_directory_exists, UiStrings, translate -from openlp.core.lib import OpenLPToolbar, ServiceItem, ItemCapabilities, PluginStatus, Registry, \ - build_icon -from openlp.core.common import ThemeLevel +from openlp.core.common import AppLocation, Settings, ThemeLevel, check_directory_exists, UiStrings, translate +from openlp.core.lib import OpenLPToolbar, ServiceItem, ItemCapabilities, PluginStatus, Registry, build_icon from openlp.core.lib.ui import critical_error_message_box, create_widget_action, find_and_set_in_combo_box from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm from openlp.core.ui.printserviceform import PrintServiceForm diff --git a/openlp/core/ui/servicenoteform.py b/openlp/core/ui/servicenoteform.py index fed016bed..18998c78d 100644 --- a/openlp/core/ui/servicenoteform.py +++ b/openlp/core/ui/servicenoteform.py @@ -31,7 +31,8 @@ The :mod:`~openlp.core.ui.servicenoteform` module contains the `ServiceNoteForm` """ from PyQt4 import QtGui -from openlp.core.lib import SpellTextEdit, Registry, translate +from openlp.core.common import translate +from openlp.core.lib import SpellTextEdit, Registry from openlp.core.lib.ui import create_button_box diff --git a/openlp/core/ui/settingsdialog.py b/openlp/core/ui/settingsdialog.py index 87923630a..31b5c841c 100644 --- a/openlp/core/ui/settingsdialog.py +++ b/openlp/core/ui/settingsdialog.py @@ -31,7 +31,8 @@ The UI widgets of the settings dialog. """ from PyQt4 import QtCore, QtGui -from openlp.core.lib import translate, build_icon +from openlp.core.common import translate +from openlp.core.lib import build_icon from openlp.core.lib.ui import create_button_box diff --git a/openlp/core/ui/shortcutlistdialog.py b/openlp/core/ui/shortcutlistdialog.py index 7e2c091c8..c70311a4b 100644 --- a/openlp/core/ui/shortcutlistdialog.py +++ b/openlp/core/ui/shortcutlistdialog.py @@ -31,7 +31,8 @@ The list of shortcuts within a dialog. """ from PyQt4 import QtCore, QtGui -from openlp.core.lib import translate, build_icon +from openlp.core.common import translate +from openlp.core.lib import build_icon from openlp.core.lib.ui import create_button_box diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 171a24f16..043838f36 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -38,8 +38,8 @@ from collections import deque from PyQt4 import QtCore, QtGui from openlp.core.common import Settings, SlideLimits, UiStrings, translate -from openlp.core.lib import OpenLPToolbar, ItemCapabilities, ServiceItem, ImageSource, \ - ServiceItemAction, Registry, ScreenList, build_icon, build_html +from openlp.core.lib import OpenLPToolbar, ItemCapabilities, ServiceItem, ImageSource, ServiceItemAction, Registry, \ + ScreenList, build_icon, build_html from openlp.core.ui import HideMode, MainDisplay, Display, DisplayControllerType from openlp.core.lib.ui import create_action from openlp.core.utils.actions import ActionList, CategoryOrder diff --git a/openlp/core/ui/themelayoutdialog.py b/openlp/core/ui/themelayoutdialog.py index ae492941a..41b2dabd0 100644 --- a/openlp/core/ui/themelayoutdialog.py +++ b/openlp/core/ui/themelayoutdialog.py @@ -31,7 +31,7 @@ The layout of the theme """ from PyQt4 import QtGui -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import create_button_box diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index daee4c320..8e1838d5d 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -39,8 +39,8 @@ from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui from openlp.core.common import AppLocation, Settings, check_directory_exists, UiStrings, translate -from openlp.core.lib import ImageSource, OpenLPToolbar, Registry, get_text_file_string, \ - build_icon, check_item_selected, create_thumb, validate_thumb +from openlp.core.lib import ImageSource, OpenLPToolbar, Registry, get_text_file_string, build_icon, \ + check_item_selected, create_thumb, validate_thumb from openlp.core.lib.theme import ThemeXML, BackgroundType from openlp.core.lib.ui import critical_error_message_box, create_widget_action from openlp.core.ui import FileRenameForm, ThemeForm, ThemeManagerHelper diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index c75e8782a..6ceb592f4 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -54,7 +54,7 @@ if sys.platform != 'win32' and sys.platform != 'darwin': except ImportError: XDG_BASE_AVAILABLE = False -from openlp.core.lib import translate +from openlp.core.common import translate log = logging.getLogger(__name__) APPLICATION_VERSION = {} diff --git a/openlp/core/utils/languagemanager.py b/openlp/core/utils/languagemanager.py index 63f2e6f24..8208435d1 100644 --- a/openlp/core/utils/languagemanager.py +++ b/openlp/core/utils/languagemanager.py @@ -35,8 +35,7 @@ import sys from PyQt4 import QtCore, QtGui -from openlp.core.common import AppLocation, Settings -from openlp.core.lib import translate +from openlp.core.common import AppLocation, Settings, translate log = logging.getLogger(__name__) diff --git a/openlp/plugins/alerts/alertsplugin.py b/openlp/plugins/alerts/alertsplugin.py index 1dcdb13c7..f41b3490c 100644 --- a/openlp/plugins/alerts/alertsplugin.py +++ b/openlp/plugins/alerts/alertsplugin.py @@ -31,8 +31,8 @@ import logging from PyQt4 import QtGui -from openlp.core.common import Settings -from openlp.core.lib import Plugin, StringContent, build_icon, translate +from openlp.core.common import Settings, translate +from openlp.core.lib import Plugin, StringContent, build_icon from openlp.core.lib.db import Manager from openlp.core.lib.ui import create_action, UiStrings from openlp.core.lib.theme import VerticalType diff --git a/openlp/plugins/alerts/forms/alertdialog.py b/openlp/plugins/alerts/forms/alertdialog.py index 6f189237f..02f41c7f8 100644 --- a/openlp/plugins/alerts/forms/alertdialog.py +++ b/openlp/plugins/alerts/forms/alertdialog.py @@ -29,7 +29,8 @@ from PyQt4 import QtGui -from openlp.core.lib import build_icon, translate +from openlp.core.common import translate +from openlp.core.lib import build_icon from openlp.core.lib.ui import create_button, create_button_box diff --git a/openlp/plugins/alerts/forms/alertform.py b/openlp/plugins/alerts/forms/alertform.py index 97a8a5efa..d0f78e4cb 100644 --- a/openlp/plugins/alerts/forms/alertform.py +++ b/openlp/plugins/alerts/forms/alertform.py @@ -29,7 +29,7 @@ from PyQt4 import QtGui, QtCore -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.plugins.alerts.lib.db import AlertItem from .alertdialog import Ui_AlertDialog diff --git a/openlp/plugins/alerts/lib/alertsmanager.py b/openlp/plugins/alerts/lib/alertsmanager.py index 047f91674..88341b77a 100644 --- a/openlp/plugins/alerts/lib/alertsmanager.py +++ b/openlp/plugins/alerts/lib/alertsmanager.py @@ -35,7 +35,8 @@ import logging from PyQt4 import QtCore -from openlp.core.lib import Registry, translate +from openlp.core.common import translate +from openlp.core.lib import Registry log = logging.getLogger(__name__) diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/csvbible.py index 69ba12062..40ae13359 100644 --- a/openlp/plugins/bibles/lib/csvbible.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -60,7 +60,7 @@ import logging import chardet import csv -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 89ff8a61a..8aefcfa8b 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -38,8 +38,8 @@ from sqlalchemy import Column, ForeignKey, Table, or_, types, func from sqlalchemy.orm import class_mapper, mapper, relation from sqlalchemy.orm.exc import UnmappedClassError -from openlp.core.common import AppLocation -from openlp.core.lib import Registry, translate +from openlp.core.common import AppLocation, translate +from openlp.core.lib import Registry from openlp.core.lib.db import BaseModel, init_db, Manager from openlp.core.lib.ui import critical_error_message_box from openlp.core.utils import clean_filename diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 0fee09265..22ff6185a 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -38,7 +38,8 @@ from html.parser import HTMLParseError from bs4 import BeautifulSoup, NavigableString, Tag -from openlp.core.lib import Registry, translate +from openlp.core.common import translate +from openlp.core.lib import Registry from openlp.core.lib.ui import critical_error_message_box from openlp.core.utils import get_web_page from openlp.plugins.bibles.lib import SearchResults diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index fc7c31d15..f2feb238f 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -30,8 +30,8 @@ import logging import os -from openlp.core.common import AppLocation, Settings -from openlp.core.lib import Registry, translate +from openlp.core.common import AppLocation, Settings, translate +from openlp.core.lib import Registry from openlp.core.utils import delete_file from openlp.plugins.bibles.lib import parse_reference, get_reference_separator, LanguageSelection from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 437dfd65e..d0414d49c 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -32,8 +32,7 @@ import logging from PyQt4 import QtCore, QtGui from openlp.core.common import Settings, UiStrings, translate -from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, ServiceItemContext, \ - create_separated_list +from openlp.core.lib import Registry, MediaManagerItem, ItemCapabilities, ServiceItemContext, create_separated_list from openlp.core.lib.searchedit import SearchEdit from openlp.core.lib.ui import set_case_insensitive_completer, create_horizontal_adjusting_combo_box, \ critical_error_message_box, find_and_set_in_combo_box, build_icon diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index d2b156345..efe0044ef 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -30,7 +30,7 @@ import logging from lxml import etree, objectify -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import critical_error_message_box from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index c2ce24da6..a0aabb5a2 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -33,8 +33,7 @@ import chardet import codecs import re -from openlp.core.common import AppLocation -from openlp.core.lib import translate +from openlp.core.common import AppLocation, translate from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB log = logging.getLogger(__name__) diff --git a/openlp/plugins/bibles/lib/versereferencelist.py b/openlp/plugins/bibles/lib/versereferencelist.py index 1f2d761e0..e8daada46 100644 --- a/openlp/plugins/bibles/lib/versereferencelist.py +++ b/openlp/plugins/bibles/lib/versereferencelist.py @@ -27,6 +27,7 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### + class VerseReferenceList(object): """ The VerseReferenceList class encapsulates a list of verse references, but maintains the order in which they were diff --git a/openlp/plugins/images/forms/addgroupdialog.py b/openlp/plugins/images/forms/addgroupdialog.py index e76332287..95e2118f4 100644 --- a/openlp/plugins/images/forms/addgroupdialog.py +++ b/openlp/plugins/images/forms/addgroupdialog.py @@ -29,7 +29,7 @@ from PyQt4 import QtGui -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import create_button_box diff --git a/openlp/plugins/images/forms/addgroupform.py b/openlp/plugins/images/forms/addgroupform.py index 29bad676d..fafac53aa 100644 --- a/openlp/plugins/images/forms/addgroupform.py +++ b/openlp/plugins/images/forms/addgroupform.py @@ -29,7 +29,7 @@ from PyQt4 import QtGui -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import critical_error_message_box from openlp.plugins.images.forms.addgroupdialog import Ui_AddGroupDialog diff --git a/openlp/plugins/images/forms/choosegroupdialog.py b/openlp/plugins/images/forms/choosegroupdialog.py index ec87df2bb..76b0d7849 100644 --- a/openlp/plugins/images/forms/choosegroupdialog.py +++ b/openlp/plugins/images/forms/choosegroupdialog.py @@ -29,7 +29,7 @@ from PyQt4 import QtCore, QtGui -from openlp.core.lib import translate +from openlp.core.common import translate from openlp.core.lib.ui import create_button_box diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index b82cfa184..137610c1f 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -31,8 +31,8 @@ from PyQt4 import QtGui import logging -from openlp.core.common import Settings -from openlp.core.lib import Plugin, StringContent, Registry, ImageSource, build_icon, translate +from openlp.core.common import Settings, translate +from openlp.core.lib import Plugin, StringContent, Registry, ImageSource, build_icon from openlp.core.lib.db import Manager from openlp.plugins.images.lib import ImageMediaItem, ImageTab from openlp.plugins.images.lib.db import init_schema diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 976a3d47e..f1e0bfdb4 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -34,8 +34,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.common import AppLocation, Settings, UiStrings, check_directory_exists, translate from openlp.core.lib import ItemCapabilities, MediaManagerItem, Registry, ServiceItemContext, \ - StringContent, TreeWidgetWithDnD, build_icon, check_item_selected, create_thumb, \ - validate_thumb + StringContent, TreeWidgetWithDnD, build_icon, check_item_selected, create_thumb, validate_thumb from openlp.core.lib.ui import create_widget_action, critical_error_message_box from openlp.core.utils import delete_file, get_locale_key, get_images_filter from openlp.plugins.images.forms import AddGroupForm, ChooseGroupForm diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index cd432c54c..d6a943832 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -31,7 +31,8 @@ import logging from PyQt4 import QtCore -from openlp.core.lib import Plugin, Registry, StringContent, build_icon, translate +from openlp.core.common import translate +from openlp.core.lib import Plugin, Registry, StringContent, build_icon from openlp.plugins.media.lib import MediaMediaItem, MediaTab diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index ce0325c7e..e5aea43c5 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -33,7 +33,7 @@ import os from PyQt4 import QtCore, QtGui from openlp.core.common import Settings, UiStrings, translate -from openlp.core.lib import MediaManagerItem, Registry, ItemCapabilities, ServiceItemContext, \ +from openlp.core.lib import MediaManagerItem, Registry, ItemCapabilities, ServiceItemContext,\ build_icon, check_item_selected, create_thumb, validate_thumb from openlp.core.lib.ui import critical_error_message_box, create_horizontal_adjusting_combo_box from openlp.core.utils import get_locale_key diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index e37312095..c6565100c 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -35,8 +35,8 @@ import logging from PyQt4 import QtCore -from openlp.core.common import AppLocation -from openlp.core.lib import Plugin, StringContent, build_icon, translate +from openlp.core.common import AppLocation, translate +from openlp.core.lib import Plugin, StringContent, build_icon from openlp.plugins.presentations.lib import PresentationController, PresentationMediaItem, PresentationTab From 4f3291b2ee0d596c89e9fb43c8dd768ee774489a Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 14 Oct 2013 06:01:01 +0100 Subject: [PATCH 27/46] Fixes to tests --- tests/functional/openlp_core_common/test_applocation.py | 6 +++--- tests/functional/openlp_core_lib/test_theme.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/functional/openlp_core_common/test_applocation.py b/tests/functional/openlp_core_common/test_applocation.py index 28db96e43..0dcb2e6b1 100644 --- a/tests/functional/openlp_core_common/test_applocation.py +++ b/tests/functional/openlp_core_common/test_applocation.py @@ -46,7 +46,7 @@ class TestAppLocation(TestCase): """ Test the AppLocation.get_data_path() method """ - with patch('openlp.core.common.Settings') as mocked_class, \ + with patch('openlp.core.common.applocation.Settings') as mocked_class, \ patch('openlp.core.common.AppLocation.get_directory') as mocked_get_directory, \ patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists, \ patch('openlp.core.common.applocation.os') as mocked_os: @@ -71,7 +71,7 @@ class TestAppLocation(TestCase): """ Test the AppLocation.get_data_path() method when a custom location is set in the settings """ - with patch('openlp.core.common.Settings') as mocked_class,\ + with patch('openlp.core.common.applocation.Settings') as mocked_class,\ patch('openlp.core.common.applocation.os') as mocked_os: # GIVEN: A mocked out Settings class which returns a custom data location mocked_settings = mocked_class.return_value @@ -200,4 +200,4 @@ class TestAppLocation(TestCase): frozen_path = get_frozen_path('frozen', 'not frozen') # THEN: The frozen parameter is returned - self.assertEqual('frozen', frozen_path, 'Should return "frozen"') \ No newline at end of file + self.assertEqual('frozen', frozen_path, 'Should return "frozen"') diff --git a/tests/functional/openlp_core_lib/test_theme.py b/tests/functional/openlp_core_lib/test_theme.py index e533b1b8d..5f6bbc4e9 100644 --- a/tests/functional/openlp_core_lib/test_theme.py +++ b/tests/functional/openlp_core_lib/test_theme.py @@ -62,4 +62,4 @@ class TestTheme(TestCase): # THEN: We should get some default behaviours self.assertTrue(default_theme.background_border_color == '#000000', 'The theme should have a black border') - self.assertTrue(default_theme.background_type == 'solid', 'There theme should have a solid backgrounds') \ No newline at end of file + self.assertTrue(default_theme.background_type == 'solid', 'There theme should have a solid backgrounds') From a8e1d5005ca963393fe672c76e1a5911b47edef2 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Mon, 14 Oct 2013 23:05:17 +0100 Subject: [PATCH 28/46] made get_data private --- tests/helpers/songfileimport.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/helpers/songfileimport.py b/tests/helpers/songfileimport.py index f2e87da86..faf18999f 100644 --- a/tests/helpers/songfileimport.py +++ b/tests/helpers/songfileimport.py @@ -95,16 +95,16 @@ class SongImportTestHelper(TestCase): # WHEN: Importing the source file importer.import_source = [source_file_name] - add_verse_calls = self.get_data(result_data, 'verses') - author_calls = self.get_data(result_data, 'authors') - ccli_number = self.get_data(result_data, 'ccli_number') - comments = self.get_data(result_data, 'comments') - song_book_name = self.get_data(result_data, 'song_book_name') - song_copyright = self.get_data(result_data, 'copyright') - song_number = self.get_data(result_data, 'song_number') - title = self.get_data(result_data, 'title') - topics = self.get_data(result_data, 'topics') - verse_order_list = self.get_data(result_data, 'verse_order_list') + add_verse_calls = self._get_data(result_data, 'verses') + author_calls = self._get_data(result_data, 'authors') + ccli_number = self._get_data(result_data, 'ccli_number') + comments = self._get_data(result_data, 'comments') + song_book_name = self._get_data(result_data, 'song_book_name') + song_copyright = self._get_data(result_data, 'copyright') + song_number = self._get_data(result_data, 'song_number') + title = self._get_data(result_data, 'title') + topics = self._get_data(result_data, 'topics') + verse_order_list = self._get_data(result_data, 'verse_order_list') # THEN: doImport should return none, the song data should be as expected, and finish should have been # called. @@ -135,7 +135,7 @@ class SongImportTestHelper(TestCase): % (source_file_name, verse_order_list)) self.mocked_finish.assert_called_with() - def get_data(self, data, key): + def _get_data(self, data, key): if key in data: return data[key] return '' From 0f183af84dfef47709689d1d29d2cc46fb8b5dea Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 15 Oct 2013 20:17:53 +0100 Subject: [PATCH 29/46] Missed file --- openlp/core/common/settings.py | 498 +++++++++++++++++++++++++++++++++ 1 file changed, 498 insertions(+) create mode 100644 openlp/core/common/settings.py diff --git a/openlp/core/common/settings.py b/openlp/core/common/settings.py new file mode 100644 index 000000000..0b5aebc69 --- /dev/null +++ b/openlp/core/common/settings.py @@ -0,0 +1,498 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +This class contains the core default settings. +""" +import datetime +import logging +import os +import sys + +from PyQt4 import QtCore, QtGui + +from openlp.core.common import ThemeLevel, SlideLimits, UiStrings + + +log = logging.getLogger(__name__) + + +# Fix for bug #1014422. +X11_BYPASS_DEFAULT = True +if sys.platform.startswith('linux'): + # Default to False on Gnome. + X11_BYPASS_DEFAULT = bool(not os.environ.get('GNOME_DESKTOP_SESSION_ID')) + # Default to False on Xfce. + if os.environ.get('DESKTOP_SESSION') == 'xfce': + X11_BYPASS_DEFAULT = False + + +class Settings(QtCore.QSettings): + """ + Class to wrap QSettings. + + * Exposes all the methods of QSettings. + * Adds functionality for OpenLP Portable. If the ``defaultFormat`` is set to + ``IniFormat``, and the path to the Ini file is set using ``set_filename``, + then the Settings constructor (without any arguments) will create a Settings + object for accessing settings stored in that Ini file. + + ``__default_settings__`` + This dict contains all core settings with their default values. + + ``__obsolete_settings__`` + Each entry is structured in the following way:: + + (u'general/enable slide loop', u'advanced/slide limits', + [(SlideLimits.Wrap, True), (SlideLimits.End, False)]) + + The first entry is the *old key*; it will be removed. + + The second entry is the *new key*; we will add it to the config. If this is just an empty string, we just remove + the old key. + + The last entry is a list containing two-pair tuples. If the list is empty, no conversion is made. Otherwise each + pair describes how to convert the old setting's value:: + + (SlideLimits.Wrap, True) + + This means, that if the value of ``general/enable slide loop`` is equal (``==``) ``True`` then we set + ``advanced/slide limits`` to ``SlideLimits.Wrap``. **NOTE**, this means that the rules have to cover all cases! + So, if the type of the old value is bool, then there must be two rules. + """ + __default_settings__ = { + 'advanced/add page break': False, + 'advanced/alternate rows': not sys.platform.startswith('win'), + 'advanced/current media plugin': -1, + 'advanced/data path': '', + 'advanced/default color': '#ffffff', + 'advanced/default image': ':/graphics/openlp-splash-screen.png', + # 7 stands for now, 0 to 6 is Monday to Sunday. + 'advanced/default service day': 7, + 'advanced/default service enabled': True, + 'advanced/default service hour': 11, + 'advanced/default service minute': 0, + 'advanced/default service name': UiStrings().DefaultServiceName, + 'advanced/display size': 0, + 'advanced/double click live': False, + 'advanced/enable exit confirmation': True, + 'advanced/expand service item': False, + 'advanced/hide mouse': True, + 'advanced/is portable': False, + 'advanced/max recent files': 20, + 'advanced/print file meta data': False, + 'advanced/print notes': False, + 'advanced/print slide text': False, + 'advanced/recent file count': 4, + 'advanced/save current plugin': False, + 'advanced/slide limits': SlideLimits.End, + 'advanced/single click preview': False, + 'advanced/x11 bypass wm': X11_BYPASS_DEFAULT, + 'crashreport/last directory': '', + 'formattingTags/html_tags': '', + 'core/audio repeat list': False, + 'core/auto open': False, + 'core/auto preview': False, + 'core/audio start paused': True, + 'core/auto unblank': False, + 'core/blank warning': False, + 'core/ccli number': '', + 'core/has run wizard': False, + 'core/language': '[en]', + 'core/last version test': '', + 'core/loop delay': 5, + 'core/recent files': [], + 'core/save prompt': False, + 'core/screen blank': False, + 'core/show splash': True, + 'core/songselect password': '', + 'core/songselect username': '', + 'core/update check': True, + 'core/view mode': 'default', + # The other display settings (display position and dimensions) are defined in the ScreenList class due to a + # circular dependency. + 'core/display on monitor': True, + 'core/override position': False, + 'images/background color': '#000000', + 'media/players': 'webkit', + 'media/override player': QtCore.Qt.Unchecked, + 'players/background color': '#000000', + 'servicemanager/last directory': '', + 'servicemanager/last file': '', + 'servicemanager/service theme': '', + 'SettingsImport/file_date_created': datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), + 'SettingsImport/Make_Changes': 'At_Own_RISK', + 'SettingsImport/type': 'OpenLP_settings_export', + 'SettingsImport/version': '', + 'shortcuts/aboutItem': [QtGui.QKeySequence('Ctrl+F1')], + 'shortcuts/addToService': [], + 'shortcuts/audioPauseItem': [], + 'shortcuts/displayTagItem': [], + 'shortcuts/blankScreen': [QtGui.QKeySequence(QtCore.Qt.Key_Period)], + 'shortcuts/collapse': [QtGui.QKeySequence(QtCore.Qt.Key_Minus)], + 'shortcuts/desktopScreen': [QtGui.QKeySequence('D')], + 'shortcuts/delete': [], + 'shortcuts/down': [QtGui.QKeySequence(QtCore.Qt.Key_Down)], + 'shortcuts/editSong': [], + 'shortcuts/escapeItem': [QtGui.QKeySequence(QtCore.Qt.Key_Escape)], + 'shortcuts/expand': [QtGui.QKeySequence(QtCore.Qt.Key_Plus)], + 'shortcuts/exportThemeItem': [], + 'shortcuts/fileNewItem': [QtGui.QKeySequence('Ctrl+N')], + 'shortcuts/fileSaveAsItem': [QtGui.QKeySequence('Ctrl+Shift+S')], + 'shortcuts/fileExitItem': [QtGui.QKeySequence('Alt+F4')], + 'shortcuts/fileSaveItem': [QtGui.QKeySequence('Ctrl+S')], + 'shortcuts/fileOpenItem': [QtGui.QKeySequence('Ctrl+O')], + 'shortcuts/goLive': [], + 'shortcuts/importThemeItem': [], + 'shortcuts/importBibleItem': [], + 'shortcuts/listViewBiblesDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], + 'shortcuts/listViewBiblesPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.Key_Return)], + 'shortcuts/listViewBiblesLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], + 'shortcuts/listViewBiblesServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), + QtGui.QKeySequence(QtCore.Qt.Key_Equal)], + 'shortcuts/listViewCustomDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], + 'shortcuts/listViewCustomPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.Key_Return)], + 'shortcuts/listViewCustomLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], + 'shortcuts/listViewCustomServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), + QtGui.QKeySequence(QtCore.Qt.Key_Equal)], + 'shortcuts/listViewImagesDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], + 'shortcuts/listViewImagesPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.Key_Return)], + 'shortcuts/listViewImagesLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], + 'shortcuts/listViewImagesServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), + QtGui.QKeySequence(QtCore.Qt.Key_Equal)], + 'shortcuts/listViewMediaDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], + 'shortcuts/listViewMediaPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.Key_Return)], + 'shortcuts/listViewMediaLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], + 'shortcuts/listViewMediaServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), + QtGui.QKeySequence(QtCore.Qt.Key_Equal)], + 'shortcuts/listViewPresentationsDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], + 'shortcuts/listViewPresentationsPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.Key_Return)], + 'shortcuts/listViewPresentationsLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], + 'shortcuts/listViewPresentationsServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), + QtGui.QKeySequence(QtCore.Qt.Key_Equal)], + 'shortcuts/listViewSongsDeleteItem': [QtGui.QKeySequence(QtCore.Qt.Key_Delete)], + 'shortcuts/listViewSongsPreviewItem': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.Key_Return)], + 'shortcuts/listViewSongsLiveItem': [QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Enter), + QtGui.QKeySequence(QtCore.Qt.ShiftModifier | QtCore.Qt.Key_Return)], + 'shortcuts/listViewSongsServiceItem': [QtGui.QKeySequence(QtCore.Qt.Key_Plus), + QtGui.QKeySequence(QtCore.Qt.Key_Equal)], + 'shortcuts/lockPanel': [], + 'shortcuts/modeDefaultItem': [], + 'shortcuts/modeLiveItem': [], + 'shortcuts/make_live': [QtGui.QKeySequence(QtCore.Qt.Key_Enter), QtGui.QKeySequence(QtCore.Qt.Key_Return)], + 'shortcuts/moveUp': [QtGui.QKeySequence(QtCore.Qt.Key_PageUp)], + 'shortcuts/moveTop': [QtGui.QKeySequence(QtCore.Qt.Key_Home)], + 'shortcuts/modeSetupItem': [], + 'shortcuts/moveBottom': [QtGui.QKeySequence(QtCore.Qt.Key_End)], + 'shortcuts/moveDown': [QtGui.QKeySequence(QtCore.Qt.Key_PageDown)], + 'shortcuts/nextTrackItem': [], + 'shortcuts/nextItem_live': [QtGui.QKeySequence(QtCore.Qt.Key_Down), + QtGui.QKeySequence(QtCore.Qt.Key_PageDown)], + 'shortcuts/nextItem_preview': [], + 'shortcuts/nextService': [QtGui.QKeySequence(QtCore.Qt.Key_Right)], + 'shortcuts/newService': [], + 'shortcuts/offlineHelpItem': [], + 'shortcuts/onlineHelpItem': [QtGui.QKeySequence('Alt+F1')], + 'shortcuts/openService': [], + 'shortcuts/saveService': [], + 'shortcuts/previousItem_live': [QtGui.QKeySequence(QtCore.Qt.Key_Up), + QtGui.QKeySequence(QtCore.Qt.Key_PageUp)], + 'shortcuts/playbackPause': [], + 'shortcuts/playbackPlay': [], + 'shortcuts/playbackStop': [], + 'shortcuts/playSlidesLoop': [], + 'shortcuts/playSlidesOnce': [], + 'shortcuts/previousService': [QtGui.QKeySequence(QtCore.Qt.Key_Left)], + 'shortcuts/previousItem_preview': [], + 'shortcuts/printServiceItem': [QtGui.QKeySequence('Ctrl+P')], + 'shortcuts/songExportItem': [], + 'shortcuts/songUsageStatus': [QtGui.QKeySequence(QtCore.Qt.Key_F4)], + 'shortcuts/searchShortcut': [QtGui.QKeySequence('Ctrl+F')], + 'shortcuts/settingsShortcutsItem': [], + 'shortcuts/settingsImportItem': [], + 'shortcuts/settingsPluginListItem': [QtGui.QKeySequence('Alt+F7')], + 'shortcuts/songUsageDelete': [], + 'shortcuts/settingsConfigureItem': [], + 'shortcuts/shortcutAction_B': [QtGui.QKeySequence('B')], + 'shortcuts/shortcutAction_C': [QtGui.QKeySequence('C')], + 'shortcuts/shortcutAction_E': [QtGui.QKeySequence('E')], + 'shortcuts/shortcutAction_I': [QtGui.QKeySequence('I')], + 'shortcuts/shortcutAction_O': [QtGui.QKeySequence('O')], + 'shortcuts/shortcutAction_P': [QtGui.QKeySequence('P')], + 'shortcuts/shortcutAction_V': [QtGui.QKeySequence('V')], + 'shortcuts/shortcutAction_0': [QtGui.QKeySequence('0')], + 'shortcuts/shortcutAction_1': [QtGui.QKeySequence('1')], + 'shortcuts/shortcutAction_2': [QtGui.QKeySequence('2')], + 'shortcuts/shortcutAction_3': [QtGui.QKeySequence('3')], + 'shortcuts/shortcutAction_4': [QtGui.QKeySequence('4')], + 'shortcuts/shortcutAction_5': [QtGui.QKeySequence('5')], + 'shortcuts/shortcutAction_6': [QtGui.QKeySequence('6')], + 'shortcuts/shortcutAction_7': [QtGui.QKeySequence('7')], + 'shortcuts/shortcutAction_8': [QtGui.QKeySequence('8')], + 'shortcuts/shortcutAction_9': [QtGui.QKeySequence('9')], + 'shortcuts/settingsExportItem': [], + 'shortcuts/songUsageReport': [], + 'shortcuts/songImportItem': [], + 'shortcuts/themeScreen': [QtGui.QKeySequence('T')], + 'shortcuts/toolsReindexItem': [], + 'shortcuts/toolsFindDuplicates': [], + 'shortcuts/toolsAlertItem': [QtGui.QKeySequence('F7')], + 'shortcuts/toolsFirstTimeWizard': [], + 'shortcuts/toolsOpenDataFolder': [], + 'shortcuts/toolsAddToolItem': [], + 'shortcuts/updateThemeImages': [], + 'shortcuts/up': [QtGui.QKeySequence(QtCore.Qt.Key_Up)], + 'shortcuts/viewThemeManagerItem': [QtGui.QKeySequence('F10')], + 'shortcuts/viewMediaManagerItem': [QtGui.QKeySequence('F8')], + 'shortcuts/viewPreviewPanel': [QtGui.QKeySequence('F11')], + 'shortcuts/viewLivePanel': [QtGui.QKeySequence('F12')], + 'shortcuts/viewServiceManagerItem': [QtGui.QKeySequence('F9')], + 'shortcuts/webSiteItem': [], + 'themes/global theme': '', + 'themes/last directory': '', + 'themes/last directory export': '', + 'themes/last directory import': '', + 'themes/theme level': ThemeLevel.Song, + 'user interface/live panel': True, + 'user interface/live splitter geometry': QtCore.QByteArray(), + 'user interface/lock panel': False, + 'user interface/main window geometry': QtCore.QByteArray(), + 'user interface/main window position': QtCore.QPoint(0, 0), + 'user interface/main window splitter geometry': QtCore.QByteArray(), + 'user interface/main window state': QtCore.QByteArray(), + 'user interface/preview panel': True, + 'user interface/preview splitter geometry': QtCore.QByteArray() + } + __file_path__ = '' + __obsolete_settings__ = [ + # Changed during 1.9.x development. + ('bibles/bookname language', 'bibles/book name language', []), + ('general/enable slide loop', 'advanced/slide limits', [(SlideLimits.Wrap, True), (SlideLimits.End, False)]), + ('songs/ccli number', 'core/ccli number', []), + ('media/use phonon', '', []), + # Changed during 2.1.x development. + ('advanced/stylesheet fix', '', []), + ('bibles/last directory 1', 'bibles/last directory import', []), + ('media/background color', 'players/background color', []), + ('themes/last directory', 'themes/last directory import', []), + ('themes/last directory 1', 'themes/last directory export', []), + ('songs/last directory 1', 'songs/last directory import', []), + ('songusage/last directory 1', 'songusage/last directory export', []), + ('user interface/mainwindow splitter geometry', 'user interface/main window splitter geometry', []), + ('shortcuts/makeLive', 'shortcuts/make_live', []), + ('general/audio repeat list', 'core/audio repeat list', []), + ('general/auto open', 'core/auto open', []), + ('general/auto preview', 'core/auto preview', []), + ('general/audio start paused', 'core/audio start paused', []), + ('general/auto unblank', 'core/auto unblank', []), + ('general/blank warning', 'core/blank warning', []), + ('general/ccli number', 'core/ccli number', []), + ('general/has run wizard', 'core/has run wizard', []), + ('general/language', 'core/language', []), + ('general/last version test', 'core/last version test', []), + ('general/loop delay', 'core/loop delay', []), + ('general/recent files', 'core/recent files', []), + ('general/save prompt', 'core/save prompt', []), + ('general/screen blank', 'core/screen blank', []), + ('general/show splash', 'core/show splash', []), + ('general/songselect password', 'core/songselect password', []), + ('general/songselect username', 'core/songselect username', []), + ('general/update check', 'core/update check', []), + ('general/view mode', 'core/view mode', []), + ('general/display on monitor', 'core/display on monitor', []), + ('general/override position', 'core/override position', []), + ('general/x position', 'core/x position', []), + ('general/y position', 'core/y position', []), + ('general/monitor', 'core/monitor', []), + ('general/height', 'core/height', []), + ('general/monitor', 'core/monitor', []), + ('general/width', 'core/width', []) + ] + + @staticmethod + def extend_default_settings(default_values): + """ + Static method to merge the given ``default_values`` with the ``Settings.__default_settings__``. + + ``default_values`` + A dict with setting keys and their default values. + """ + Settings.__default_settings__ = dict(list(default_values.items()) + list(Settings.__default_settings__.items())) + + @staticmethod + def set_filename(ini_file): + """ + Sets the complete path to an Ini file to be used by Settings objects. + + Does not affect existing Settings objects. + """ + Settings.__file_path__ = ini_file + + @staticmethod + def set_up_default_values(): + """ + This static method is called on start up. It is used to perform any operation on the __default_settings__ dict. + """ + # Make sure the string is translated (when building the dict the string is not translated because the translate + # function was not set up as this stage). + Settings.__default_settings__['advanced/default service name'] = UiStrings().DefaultServiceName + + def __init__(self, *args): + """ + Constructor which checks if this should be a native settings object, or an INI file. + """ + if not args and Settings.__file_path__ and Settings.defaultFormat() == Settings.IniFormat: + QtCore.QSettings.__init__(self, Settings.__file_path__, Settings.IniFormat) + else: + QtCore.QSettings.__init__(self, *args) + + def get_default_value(self, key): + """ + Get the default value of the given key + """ + if self.group(): + key = self.group() + '/' + key + return Settings.__default_settings__[key] + + def remove_obsolete_settings(self): + """ + This method is only called to clean up the config. It removes old settings and it renames settings. See + ``__obsolete_settings__`` for more details. + """ + for old_key, new_key, rules in Settings.__obsolete_settings__: + # Once removed we don't have to do this again. + if self.contains(old_key): + if new_key: + # Get the value of the old_key. + old_value = super(Settings, self).value(old_key) + # When we want to convert the value, we have to figure out the default value (because we cannot get + # the default value from the central settings dict. + if rules: + default_value = rules[0][1] + old_value = self._convert_value(old_value, default_value) + # Iterate over our rules and check what the old_value should be "converted" to. + for new, old in rules: + # If the value matches with the condition (rule), then use the provided value. This is used to + # convert values. E. g. an old value 1 results in True, and 0 in False. + if old == old_value: + old_value = new + break + self.setValue(new_key, old_value) + self.remove(old_key) + + def value(self, key): + """ + Returns the value for the given ``key``. The returned ``value`` is of the same type as the default value in the + *Settings.__default_settings__* dict. + + ``key`` + The key to return the value from. + """ + # if group() is not empty the group has not been specified together with the key. + if self.group(): + default_value = Settings.__default_settings__[self.group() + '/' + key] + else: + default_value = Settings.__default_settings__[key] + setting = super(Settings, self).value(key, default_value) + return self._convert_value(setting, default_value) + + def _convert_value(self, setting, default_value): + """ + This converts the given ``setting`` to the type of the given ``default_value``. + + ``setting`` + The setting to convert. This could be ``true`` for example.Settings() + + ``default_value`` + Indication the type the setting should be converted to. For example ``True`` (type is boolean), meaning that + we convert the string ``true`` to a python boolean. + + **Note**, this method only converts a few types and might need to be extended if a certain type is missing! + """ + # On OS X (and probably on other platforms too) empty value from QSettings is represented as type + # PyQt4.QtCore.QPyNullVariant. This type has to be converted to proper 'None' Python type. + if isinstance(setting, QtCore.QPyNullVariant) and setting.isNull(): + setting = None + # Handle 'None' type (empty value) properly. + if setting is None: + # An empty string saved to the settings results in a None type being returned. + # Convert it to empty unicode string. + if isinstance(default_value, str): + return '' + # An empty list saved to the settings results in a None type being returned. + else: + return [] + # Convert the setting to the correct type. + if isinstance(default_value, bool): + if isinstance(setting, bool): + return setting + # Sometimes setting is string instead of a boolean. + return setting == 'true' + if isinstance(default_value, int): + return int(setting) + return setting + + def get_files_from_config(self, plugin): + """ + This removes the settings needed for old way we saved files (e. g. the image paths for the image plugin). A list + of file paths are returned. + + **Note**: Only a list of paths is returned; this does not convert anything! + + ``plugin`` + The Plugin object.The caller has to convert/save the list himself; o + """ + files_list = [] + # We need QSettings instead of Settings here to bypass our central settings dict. + # Do NOT do this anywhere else! + settings = QtCore.QSettings(self.fileName(), Settings.IniFormat) + settings.beginGroup(plugin.settings_section) + if settings.contains('%s count' % plugin.name): + # Get the count. + list_count = int(settings.value('%s count' % plugin.name, 0)) + if list_count: + for counter in range(list_count): + # The keys were named e. g.: "image 0" + item = settings.value('%s %d' % (plugin.name, counter), '') + if item: + files_list.append(item) + settings.remove('%s %d' % (plugin.name, counter)) + settings.remove('%s count' % plugin.name) + settings.endGroup() + return files_list From ba0808f551a18892557f35b7a2e6dda190565832 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 18 Oct 2013 19:10:47 +0100 Subject: [PATCH 30/46] Fix up json --- openlp/core/lib/json/theme.json | 102 ++++++++++-------- openlp/core/lib/theme.py | 23 +++- .../functional/openlp_core_lib/test_theme.py | 6 ++ 3 files changed, 83 insertions(+), 48 deletions(-) diff --git a/openlp/core/lib/json/theme.json b/openlp/core/lib/json/theme.json index 9991f2b53..e8862d0b4 100644 --- a/openlp/core/lib/json/theme.json +++ b/openlp/core/lib/json/theme.json @@ -1,49 +1,59 @@ { - "background_border_color": "#000000", - "background_color": "#000000", - "background_direction": "vertical", - "background_end_color": "#000000", - "background_filename": "", - "background_start_color": "#000000", - "background_type": "solid", - "display_horizontal_align": 0, - "display_slide_transition": false, - "display_vertical_align": 0, - "font_footer_bold": false, - "font_footer_color": "#FFFFFF", - "font_footer_height": 78, - "font_footer_italics": false, - "font_footer_line_adjustment": 0, - "font_footer_location": "", - "font_footer_name": "Arial", - "font_footer_outline": false, - "font_footer_outline_color": "#000000", - "font_footer_outline_size": 2, - "font_footer_override": false, - "font_footer_shadow": true, - "font_footer_shadow_color": "#000000", - "font_footer_shadow_size": 5, - "font_footer_size": 12, - "font_footer_width": 1004, - "font_footer_x": 10, - "font_footer_y": 690, - "font_main_bold": false, - "font_main_color": "#FFFFFF", - "font_main_height": 690, - "font_main_italics": false, - "font_main_line_adjustment": 0, - "font_main_location": "", - "font_main_name": "Arial", - "font_main_outline": false, - "font_main_outline_color": "#000000", - "font_main_outline_size": 2, - "font_main_override": false, - "font_main_shadow": true, - "font_main_shadow_color": "#000000", - "font_main_shadow_size": 5, - "font_main_size": 40, - "font_main_width": 1004, - "font_main_x": 10, - "font_main_y": 10, + "background" : { + "border_color": "#000000", + "color": "#000000", + "direction": "vertical", + "end_color": "#000000", + "filename": "", + "start_color": "#000000", + "type": "solid" + }, + "display" :{ + "horizontal_align": 0, + "slide_transition": false, + "vertical_align": 0 + }, + "font": { + "footer": { + "bold": false, + "color": "#FFFFFF", + "height": 78, + "italics": false, + "line_adjustment": 0, + "location": "", + "name": "Arial", + "outline": false, + "outline_color": "#000000", + "outline_size": 2, + "override": false, + "shadow": true, + "shadow_color": "#000000", + "shadow_size": 5, + "size": 12, + "width": 1004, + "x": 10, + "y": 690 + }, + "main": { + "bold": false, + "color": "#FFFFFF", + "height": 690, + "italics": false, + "line_adjustment": 0, + "location": "", + "name": "Arial", + "outline": false, + "outline_color": "#000000", + "outline_size": 2, + "override": false, + "shadow": true, + "shadow_color": "#000000", + "shadow_size": 5, + "size": 40, + "width": 1004, + "x": 10, + "y": 10 + } + }, "theme_name": "" } diff --git a/openlp/core/lib/theme.py b/openlp/core/lib/theme.py index e8918e4d1..86b126ed8 100644 --- a/openlp/core/lib/theme.py +++ b/openlp/core/lib/theme.py @@ -169,8 +169,27 @@ class ThemeXML(object): json_file = os.path.join(json_dir, 'theme.json') jsn = get_text_file_string(json_file) jsn = json.loads(jsn) - for key, value in jsn.items(): - setattr(self, key, value) + self.expand_json(jsn) + + def expand_json(self, var, prev=None): + """ + Expand the json objects and make into variables. + + ``var`` + The array list to be processed. + + ``prev`` + The preceding string to add to the key to make the variable. + """ + for key, value in var.items(): + if prev: + key = prev + "_" + key + else: + key = key + if isinstance(value, dict): + self.expand_json(value, key) + else: + setattr(self, key, value) def extend_image_filename(self, path): """ diff --git a/tests/functional/openlp_core_lib/test_theme.py b/tests/functional/openlp_core_lib/test_theme.py index 5f6bbc4e9..27097ca29 100644 --- a/tests/functional/openlp_core_lib/test_theme.py +++ b/tests/functional/openlp_core_lib/test_theme.py @@ -63,3 +63,9 @@ class TestTheme(TestCase): # THEN: We should get some default behaviours self.assertTrue(default_theme.background_border_color == '#000000', 'The theme should have a black border') self.assertTrue(default_theme.background_type == 'solid', 'There theme should have a solid backgrounds') + self.assertTrue(default_theme.background_type == 'solid', 'There theme should have a solid backgrounds') + self.assertTrue(default_theme.display_vertical_align == 0, + 'There theme should have display_vertical_align of 0') + self.assertTrue(default_theme.font_footer_name == "Arial", + 'There theme should has font_footer_name of Arial') + self.assertTrue(default_theme.font_main_bold is False, 'There theme should has font_main_bold of false') \ No newline at end of file From 28a94a06fb44d06d0d497600cf3ab2f51f972a76 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 18 Oct 2013 19:11:17 +0100 Subject: [PATCH 31/46] Duplicate line --- tests/functional/openlp_core_lib/test_theme.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/functional/openlp_core_lib/test_theme.py b/tests/functional/openlp_core_lib/test_theme.py index 27097ca29..1ece64b34 100644 --- a/tests/functional/openlp_core_lib/test_theme.py +++ b/tests/functional/openlp_core_lib/test_theme.py @@ -63,7 +63,6 @@ class TestTheme(TestCase): # THEN: We should get some default behaviours self.assertTrue(default_theme.background_border_color == '#000000', 'The theme should have a black border') self.assertTrue(default_theme.background_type == 'solid', 'There theme should have a solid backgrounds') - self.assertTrue(default_theme.background_type == 'solid', 'There theme should have a solid backgrounds') self.assertTrue(default_theme.display_vertical_align == 0, 'There theme should have display_vertical_align of 0') self.assertTrue(default_theme.font_footer_name == "Arial", From ea8497d559e33319efb5b08bef1a13db8e8b9081 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 21 Oct 2013 09:38:18 +0200 Subject: [PATCH 32/46] no need for MagicMock --- tests/functional/openlp_core_lib/test_htmlbuilder.py | 6 +++--- .../openlp_plugins/songs/forms/test_editsongform.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py index ec8e3a4a3..0ffab5458 100644 --- a/tests/functional/openlp_core_lib/test_htmlbuilder.py +++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py @@ -216,9 +216,9 @@ class Htmbuilder(TestCase): is_live = False background = None plugin = MagicMock() - plugin.get_display_css = MagicMock(return_value='plugin CSS') - plugin.get_display_javascript = MagicMock(return_value='plugin JS') - plugin.get_display_html = MagicMock(return_value='plugin HTML') + plugin.get_display_css.return_value = 'plugin CSS' + plugin.get_display_javascript.return_value = 'plugin JS' + plugin.get_display_html.return_value = 'plugin HTML' plugins = [plugin] # WHEN: Create the html. diff --git a/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py b/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py index 405ba5cf6..75907e3c8 100644 --- a/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py +++ b/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py @@ -55,9 +55,9 @@ class TestEditSongForm(TestCase): self.form.verse_list_widget.rowCount = MagicMock(return_value=2) # Mock out the verse. first_verse = MagicMock() - first_verse.data = MagicMock(return_value='V1') + first_verse.data.return_value = 'V1' second_verse = MagicMock() - second_verse.data = MagicMock(return_value= 'V2') + second_verse.data.return_value = 'V2' self.form.verse_list_widget.item = MagicMock(side_effect=[first_verse, second_verse]) self.form._extract_verse_order = MagicMock(return_value=given_verse_order.split()) @@ -76,9 +76,9 @@ class TestEditSongForm(TestCase): self.form.verse_list_widget.rowCount = MagicMock(return_value=2) # Mock out the verse. first_verse = MagicMock() - first_verse.data = MagicMock(return_value='V1') + first_verse.data.return_value = 'V1' second_verse = MagicMock() - second_verse.data = MagicMock(return_value= 'V2') + second_verse.data.return_value = 'V2' self.form.verse_list_widget.item = MagicMock(side_effect=[first_verse, second_verse]) self.form._extract_verse_order = MagicMock(return_value=[given_verse_order]) @@ -98,7 +98,7 @@ class TestEditSongForm(TestCase): self.form.verse_list_widget.rowCount = MagicMock(return_value=1) # Mock out the verse. (We want a verse type to be returned). mocked_verse = MagicMock() - mocked_verse.data = MagicMock(return_value='V1') + mocked_verse.data.return_value = 'V1' self.form.verse_list_widget.item = MagicMock(return_value=mocked_verse) self.form._extract_verse_order = MagicMock(return_value=[]) self.form.verse_order_edit.text = MagicMock(return_value=given_verse_order) From 24dba5264017ed541de15d9c957024a40599c449 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Tue, 22 Oct 2013 17:09:10 +0200 Subject: [PATCH 33/46] Fix Import, use system-independent path --- .../songs/test_songbeamerimport.py | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py index e6b1c4570..b6c5b2f1b 100644 --- a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py +++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py @@ -1,14 +1,44 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### + """ This module contains tests for the Songbeamer song importer. """ import os from unittest import TestCase -from mock import patch, MagicMock +from tests.functional import MagicMock, patch from openlp.plugins.songs.lib.songbeamerimport import SongBeamerImport -TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../resources/songbeamersongs')) +TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), + '..', '..', '..', 'resources', 'songbeamersongs')) SONG_TEST_DATA = {'Lobsinget dem Herrn.sng': {'title': 'GL 1 - Lobsinget dem Herrn', 'verses': From b1873016c9a4b7e32239dde155a0cc53450528fb Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 23 Oct 2013 20:25:46 +0100 Subject: [PATCH 34/46] Move and tests --- openlp/core/ui/thememanager.py | 26 ++--- openlp/core/ui/thememanagerhelper.py | 26 ++++- .../functional/openlp_core_common/__init__.py | 29 +++++- .../openlp_core_common/test_applocation.py | 1 - .../functional/openlp_core_lib/test_theme.py | 10 +- .../openlp_core_ui/test_thememanagerhelper.py | 99 +++++++++++++++++++ 6 files changed, 167 insertions(+), 24 deletions(-) create mode 100644 tests/interfaces/openlp_core_ui/test_thememanagerhelper.py diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 8e1838d5d..7e55a8b2c 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -33,7 +33,6 @@ import os import zipfile import shutil import logging -import re from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui @@ -59,7 +58,7 @@ class ThemeManager(QtGui.QWidget, ThemeManagerHelper): """ super(ThemeManager, self).__init__(parent) Registry().register('theme_manager', self) - Registry().register_function('bootstrap_initialise', self.load_first_time_themes) + Registry().register_function('bootstrap_initialise', self.initialise) Registry().register_function('bootstrap_post_set_up', self._push_themes) self.settings_section = 'themes' self.theme_form = ThemeForm(self) @@ -135,15 +134,7 @@ class ThemeManager(QtGui.QWidget, ThemeManagerHelper): Registry().register_function('theme_update_global', self.change_global_from_tab) # Variables self.theme_list = [] - self.path = AppLocation.get_section_data_path(self.settings_section) - check_directory_exists(self.path) - self.thumb_path = os.path.join(self.path, 'thumbnails') - check_directory_exists(self.thumb_path) - self.theme_form.path = self.path self.old_background_image = None - self.bad_v1_name_chars = re.compile(r'[%+\[\]]') - # Last little bits of setting up - self.global_theme = Settings().value(self.settings_section + '/global theme') def check_list_state(self, item): """ @@ -392,6 +383,7 @@ class ThemeManager(QtGui.QWidget, ThemeManagerHelper): """ Imports any themes on start up and makes sure there is at least one theme """ + log.debug('load_first_time_themes called') self.application.set_busy_cursor() files = AppLocation.get_files(self.settings_section, '.otz') for theme_file in files: @@ -410,8 +402,8 @@ class ThemeManager(QtGui.QWidget, ThemeManagerHelper): def load_themes(self): """ - Loads the theme lists and triggers updates across the whole system - using direct calls or core functions and events for the plugins. + Loads the theme lists and triggers updates across the whole system using direct calls or core functions and + events for the plugins. The plugins will call back in to get the real list if they want it. """ log.debug('Load themes from dir') @@ -636,18 +628,18 @@ class ThemeManager(QtGui.QWidget, ThemeManagerHelper): self.main_window.finished_progress_bar() self.load_themes() - def generate_image(self, theme_data, forcePage=False): + def generate_image(self, theme_data, force_page=False): """ Call the renderer to build a Sample Image ``theme_data`` The theme to generated a preview for. - ``forcePage`` + ``force_page`` Flag to tell message lines per page need to be generated. """ log.debug('generate_image \n%s ', theme_data) - return self.renderer.generate_preview(theme_data, forcePage) + return self.renderer.generate_preview(theme_data, force_page) def get_preview_image(self, theme): """ @@ -672,7 +664,7 @@ class ThemeManager(QtGui.QWidget, ThemeManagerHelper): theme.extend_image_filename(path) return theme - def _validate_theme_action(self, select_text, confirm_title, confirm_text, testPlugin=True, confirm=True): + def _validate_theme_action(self, select_text, confirm_title, confirm_text, test_plugin=True, confirm=True): """ Check to see if theme has been selected and the destructive action is allowed. @@ -694,7 +686,7 @@ class ThemeManager(QtGui.QWidget, ThemeManagerHelper): message=translate('OpenLP.ThemeManager', 'You are unable to delete the default theme.')) return False # check for use in the system else where. - if testPlugin: + if test_plugin: for plugin in self.plugin_manager.plugins: if plugin.uses_theme(theme): critical_error_message_box(translate('OpenLP.ThemeManager', 'Validation Error'), diff --git a/openlp/core/ui/thememanagerhelper.py b/openlp/core/ui/thememanagerhelper.py index 8fa02bde5..bc04b3bd9 100644 --- a/openlp/core/ui/thememanagerhelper.py +++ b/openlp/core/ui/thememanagerhelper.py @@ -29,10 +29,34 @@ """ The Theme Controller helps manages adding, deleteing and modifying of themes. """ +import logging +import os + +from openlp.core.common import AppLocation, Settings, check_directory_exists + +log = logging.getLogger(__name__) class ThemeManagerHelper(object): """ Manages the non ui theme functions. """ - pass \ No newline at end of file + def initialise(self): + """ + Setup the manager + """ + log.debug('initialise called') + self.global_theme = Settings().value(self.settings_section + '/global theme') + self.build_theme_path() + self.load_first_time_themes() + + def build_theme_path(self): + """ + Set up the theme path variables + """ + log.debug('build theme path called') + self.path = AppLocation.get_section_data_path(self.settings_section) + check_directory_exists(self.path) + self.thumb_path = os.path.join(self.path, 'thumbnails') + check_directory_exists(self.thumb_path) + self.theme_form.path = self.path \ No newline at end of file diff --git a/tests/functional/openlp_core_common/__init__.py b/tests/functional/openlp_core_common/__init__.py index f87606f07..64d028205 100644 --- a/tests/functional/openlp_core_common/__init__.py +++ b/tests/functional/openlp_core_common/__init__.py @@ -1 +1,28 @@ -__author__ = 'tim' +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### diff --git a/tests/functional/openlp_core_common/test_applocation.py b/tests/functional/openlp_core_common/test_applocation.py index 0dcb2e6b1..0683bb050 100644 --- a/tests/functional/openlp_core_common/test_applocation.py +++ b/tests/functional/openlp_core_common/test_applocation.py @@ -59,7 +59,6 @@ class TestAppLocation(TestCase): # WHEN: we call AppLocation.get_data_path() data_path = AppLocation.get_data_path() - print(data_path) # THEN: check that all the correct methods were called, and the result is correct mocked_settings.contains.assert_called_with('advanced/data path') diff --git a/tests/functional/openlp_core_lib/test_theme.py b/tests/functional/openlp_core_lib/test_theme.py index 1ece64b34..cf8d1f661 100644 --- a/tests/functional/openlp_core_lib/test_theme.py +++ b/tests/functional/openlp_core_lib/test_theme.py @@ -62,9 +62,11 @@ class TestTheme(TestCase): # THEN: We should get some default behaviours self.assertTrue(default_theme.background_border_color == '#000000', 'The theme should have a black border') - self.assertTrue(default_theme.background_type == 'solid', 'There theme should have a solid backgrounds') + self.assertTrue(default_theme.background_type == 'solid', 'The theme should have a solid backgrounds') self.assertTrue(default_theme.display_vertical_align == 0, - 'There theme should have display_vertical_align of 0') + 'The theme should have a display_vertical_align of 0') self.assertTrue(default_theme.font_footer_name == "Arial", - 'There theme should has font_footer_name of Arial') - self.assertTrue(default_theme.font_main_bold is False, 'There theme should has font_main_bold of false') \ No newline at end of file + 'The theme should have a font_footer_name of Arial') + self.assertTrue(default_theme.font_main_bold is False, 'The theme should have a font_main_bold of false') + self.assertTrue(len(default_theme.__dict__) == 47, 'The theme should have 47 variables') + diff --git a/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py b/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py new file mode 100644 index 000000000..eb964a045 --- /dev/null +++ b/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py @@ -0,0 +1,99 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +Interface tests to test the thememanagerhelper class and related methods. +""" +import os +from unittest import TestCase +from tempfile import mkstemp + +from openlp.core.common import AppLocation, get_frozen_path +from openlp.core.common import Settings +from openlp.core.ui import ThemeManagerHelper +from tests.functional import patch, MagicMock + + +class TestThemeManagerHelper(TestCase): + """ + Test the functions in the ThemeManagerHelp[er module + """ + def setUp(self): + """ + Create the UI + """ + fd, self.ini_file = mkstemp('.ini') + Settings().set_filename(self.ini_file) + self.helper = ThemeManagerHelper() + self.helper.settings_section = "themes" + + def tearDown(self): + """ + Delete all the C++ objects at the end so that we don't have a segfault + """ + os.unlink(self.ini_file) + os.unlink(Settings().fileName()) + + def test_initialise(self): + """ + Test the thememanagerhelper initialise - basic test + """ + # GIVEN: A new a call to initialise + Settings().setValue('themes/global theme', 'my_theme') + self.helper.build_theme_path = MagicMock() + self.helper.load_first_time_themes = MagicMock() + + # WHEN: the initialistion is run + self.helper.initialise() + + # THEN: + self.assertEqual(1, self.helper.build_theme_path.call_count, + 'The function build_theme_path should have been called') + self.assertEqual(1, self.helper.load_first_time_themes.call_count, + 'The function load_first_time_themes should have been called') + self.assertEqual(self.helper.global_theme , 'my_theme', + 'The global theme should have been set to my_theme') + + def test_build_theme_path(self): + """ + Test the thememanagerhelper build_theme_path - basic test + """ + # GIVEN: A new a call to initialise + with patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists: + # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() + mocked_check_directory_exists.return_value = True + Settings().setValue('themes/global theme', 'my_theme') + + self.helper.theme_form = MagicMock() + #self.helper.load_first_time_themes = MagicMock() + + # WHEN: the build_theme_path is run + self.helper.build_theme_path() + + # THEN: + A=1 \ No newline at end of file From 636dead5c3fd16ed5848727edc8390944d68066f Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Sat, 26 Oct 2013 19:25:07 +0200 Subject: [PATCH 35/46] Fix vim header (textwidth=120) --- copyright.txt | 2 +- tests/functional/openlp_plugins/songs/test_songbeamerimport.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/copyright.txt b/copyright.txt index f56b7712d..64d028205 100644 --- a/copyright.txt +++ b/copyright.txt @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py index b6c5b2f1b..7fbb0a101 100644 --- a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py +++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### # OpenLP - Open Source Lyrics Projection # @@ -26,7 +26,6 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### - """ This module contains tests for the Songbeamer song importer. """ From f74697a987106128d0e5cd8332ce745c8b93efdd Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Sat, 26 Oct 2013 19:31:35 +0200 Subject: [PATCH 36/46] Try to fix encoding... --- tests/functional/openlp_plugins/songs/test_songbeamerimport.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py index 7fbb0a101..37d4a1223 100644 --- a/tests/functional/openlp_plugins/songs/test_songbeamerimport.py +++ b/tests/functional/openlp_plugins/songs/test_songbeamerimport.py @@ -53,7 +53,6 @@ SONG_TEST_DATA = {'Lobsinget dem Herrn.sng': 'song_number': "1"} } - class TestSongBeamerImport(TestCase): """ Test the functions in the :mod:`songbeamerimport` module. From f838a495094ba2758ed53c9f3c539d281a6fb205 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Sun, 27 Oct 2013 21:19:19 +0100 Subject: [PATCH 37/46] fixed bug #1245269 'Thursday is called Thurdsday' Fixes: https://launchpad.net/bugs/1245269 --- openlp/core/ui/advancedtab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index 50bdc57fa..83bd83e77 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -283,7 +283,7 @@ class AdvancedTab(SettingsTab): self.service_name_day.setItemText(0, translate('OpenLP.AdvancedTab', 'Monday')) self.service_name_day.setItemText(1, translate('OpenLP.AdvancedTab', 'Tuesday')) self.service_name_day.setItemText(2, translate('OpenLP.AdvancedTab', 'Wednesday')) - self.service_name_day.setItemText(3, translate('OpenLP.AdvancedTab', 'Thurdsday')) + self.service_name_day.setItemText(3, translate('OpenLP.AdvancedTab', 'Thursday')) self.service_name_day.setItemText(4, translate('OpenLP.AdvancedTab', 'Friday')) self.service_name_day.setItemText(5, translate('OpenLP.AdvancedTab', 'Saturday')) self.service_name_day.setItemText(6, translate('OpenLP.AdvancedTab', 'Sunday')) From d09747a33a91c52d1ce4774c525d92f1f4bd145e Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 30 Oct 2013 22:34:23 +0200 Subject: [PATCH 38/46] Fixed the problems with the exception form. Not sure how to test it though... --- openlp/core/__init__.py | 3 ++- openlp/core/ui/exceptionform.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 7d198db5e..4bb0f0d28 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -184,7 +184,8 @@ class OpenLP(QtGui.QApplication): ``traceback`` A traceback object with the details of where the exception occurred. """ - log.exception(''.join(format_exception(exctype, value, traceback))) + # We can't log.exception here because the last exception no longer exists, we're actually busy handling it. + log.critical(''.join(format_exception(exctype, value, traceback))) if not hasattr(self, 'exception_form'): self.exception_form = ExceptionForm() self.exception_form.exception_text_edit.setPlainText(''.join(format_exception(exctype, value, traceback))) diff --git a/openlp/core/ui/exceptionform.py b/openlp/core/ui/exceptionform.py index b2427e009..f1e57a545 100644 --- a/openlp/core/ui/exceptionform.py +++ b/openlp/core/ui/exceptionform.py @@ -101,7 +101,7 @@ class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog): """ Constructor. """ - super(ExceptionForm, self).__init__(self.main_window) + super(ExceptionForm, self).__init__() self.setupUi(self) self.settings_section = 'crashreport' From 20a1a2ad70d0be6f1341c3464596a847e4d41b7b Mon Sep 17 00:00:00 2001 From: Felipe Polo-Wood Date: Fri, 8 Nov 2013 13:26:27 -0500 Subject: [PATCH 39/46] Fixed router so response and headers are sent correctly Fixed tests so they run on Windows Added unit test for new method get_content_type --- openlp/plugins/remotes/lib/httprouter.py | 50 +++++++++++-------- .../openlp_plugins/remotes/test_remotetab.py | 3 +- .../openlp_plugins/remotes/test_router.py | 20 +++++++- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/openlp/plugins/remotes/lib/httprouter.py b/openlp/plugins/remotes/lib/httprouter.py index ce13ed812..eb2b68e6b 100644 --- a/openlp/plugins/remotes/lib/httprouter.py +++ b/openlp/plugins/remotes/lib/httprouter.py @@ -346,30 +346,14 @@ class HttpRouter(object): path = os.path.normpath(os.path.join(self.html_dir, file_name)) if not path.startswith(self.html_dir): return self.do_not_found() - ext = os.path.splitext(file_name)[1] - html = None - if ext == '.html': - self.send_header('Content-type', 'text/html') - variables = self.template_vars - html = Template(filename=path, input_encoding='utf-8', output_encoding='utf-8').render(**variables) - elif ext == '.css': - self.send_header('Content-type', 'text/css') - elif ext == '.js': - self.send_header('Content-type', 'application/javascript') - elif ext == '.jpg': - self.send_header('Content-type', 'image/jpeg') - elif ext == '.gif': - self.send_header('Content-type', 'image/gif') - elif ext == '.ico': - self.send_header('Content-type', 'image/x-icon') - elif ext == '.png': - self.send_header('Content-type', 'image/png') - else: - self.send_header('Content-type', 'text/plain') + content = None + ext, content_type = self.get_content_type(path) file_handle = None try: - if html: - content = html + if ext == '.html': + variables = self.template_vars + content = Template(filename=path, input_encoding='utf-8', + output_encoding='utf-8').render(**variables) else: file_handle = open(path, 'rb') log.debug('Opened %s' % path) @@ -380,8 +364,30 @@ class HttpRouter(object): finally: if file_handle: file_handle.close() + self.send_response(200) + self.send_header('Content-type', content_type) + self.end_headers() return content + def get_content_type(self, file_name): + """ + Examines the extension of the file and determines + what header to send back + Returns the extension found + """ + content_type = 'text/plain' + file_types = {'.html': 'text/html', + '.css': 'text/css', + '.js': 'application/javascript', + '.jpg': 'image/jpeg', + '.gif': 'image/gif', + '.ico': 'image/x-icon', + '.png': 'image/png' + } + ext = os.path.splitext(file_name)[1] + content_type = file_types.get(ext, 'text/plain') + return ext, content_type + def poll(self): """ Poll OpenLP to determine the current slide number and item name. diff --git a/tests/functional/openlp_plugins/remotes/test_remotetab.py b/tests/functional/openlp_plugins/remotes/test_remotetab.py index 067c5cff1..52aeeee99 100644 --- a/tests/functional/openlp_plugins/remotes/test_remotetab.py +++ b/tests/functional/openlp_plugins/remotes/test_remotetab.py @@ -62,7 +62,7 @@ class TestRemoteTab(TestCase): """ Create the UI """ - fd, self.ini_file = mkstemp('.ini') + self.fd, self.ini_file = mkstemp('.ini') Settings().set_filename(self.ini_file) self.application = QtGui.QApplication.instance() Settings().extend_default_settings(__default_settings__) @@ -76,6 +76,7 @@ class TestRemoteTab(TestCase): del self.application del self.parent del self.form + os.close(self.fd) os.unlink(self.ini_file) def get_ip_address_default_test(self): diff --git a/tests/functional/openlp_plugins/remotes/test_router.py b/tests/functional/openlp_plugins/remotes/test_router.py index a9ba16bf8..6762f7643 100644 --- a/tests/functional/openlp_plugins/remotes/test_router.py +++ b/tests/functional/openlp_plugins/remotes/test_router.py @@ -59,7 +59,7 @@ class TestRouter(TestCase): """ Create the UI """ - fd, self.ini_file = mkstemp('.ini') + self.fd, self.ini_file = mkstemp('.ini') Settings().set_filename(self.ini_file) self.application = QtGui.QApplication.instance() Settings().extend_default_settings(__default_settings__) @@ -70,6 +70,7 @@ class TestRouter(TestCase): Delete all the C++ objects at the end so that we don't have a segfault """ del self.application + os.close(self.fd) os.unlink(self.ini_file) def password_encrypter_test(self): @@ -109,4 +110,19 @@ class TestRouter(TestCase): assert function['function'] == mocked_function, \ 'The mocked function should match defined value.' assert function['secure'] == False, \ - 'The mocked function should not require any security.' \ No newline at end of file + 'The mocked function should not require any security.' + + def get_content_type_test(self): + """ + Test the get_content_type logic + """ + headers = [ ['test.html', 'text/html'], ['test.css', 'text/css'], + ['test.js', 'application/javascript'], ['test.jpg', 'image/jpeg'], + ['test.gif', 'image/gif'], ['test.ico', 'image/x-icon'], + ['test.png', 'image/png'], ['test.whatever', 'text/plain'], + ['test', 'text/plain'], ['', 'text/plain'], + ['/test/test.html', 'text/html'], + ['c:\\test\\test.html', 'text/html']] + for header in headers: + ext, content_type = self.router.get_content_type(header[0]) + self.assertEqual(content_type, header[1], 'Mismatch of content type') From 45bcbe92728fd5d822c3d86d9c3612827e3de4fe Mon Sep 17 00:00:00 2001 From: Felipe Polo-Wood Date: Sun, 10 Nov 2013 19:13:03 -0500 Subject: [PATCH 40/46] Moved the file_types to module level so they get processed once --- openlp/plugins/remotes/lib/httprouter.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/openlp/plugins/remotes/lib/httprouter.py b/openlp/plugins/remotes/lib/httprouter.py index eb2b68e6b..b3652d4df 100644 --- a/openlp/plugins/remotes/lib/httprouter.py +++ b/openlp/plugins/remotes/lib/httprouter.py @@ -128,6 +128,15 @@ from openlp.core.common import AppLocation, Settings, translate from openlp.core.lib import Registry, PluginStatus, StringContent, image_to_byte log = logging.getLogger(__name__) +file_types = { + '.html': 'text/html', + '.css': 'text/css', + '.js': 'application/javascript', + '.jpg': 'image/jpeg', + '.gif': 'image/gif', + '.ico': 'image/x-icon', + '.png': 'image/png' +} class HttpRouter(object): @@ -372,18 +381,10 @@ class HttpRouter(object): def get_content_type(self, file_name): """ Examines the extension of the file and determines - what header to send back - Returns the extension found + what the content_type should be, defaults to text/plain + Returns the extension and the content_type """ content_type = 'text/plain' - file_types = {'.html': 'text/html', - '.css': 'text/css', - '.js': 'application/javascript', - '.jpg': 'image/jpeg', - '.gif': 'image/gif', - '.ico': 'image/x-icon', - '.png': 'image/png' - } ext = os.path.splitext(file_name)[1] content_type = file_types.get(ext, 'text/plain') return ext, content_type From 649494589a0cf38694203b0f321ad08afb27cc7a Mon Sep 17 00:00:00 2001 From: Felipe Polo-Wood Date: Sun, 10 Nov 2013 19:55:06 -0500 Subject: [PATCH 41/46] Added unit tests for serve_file --- .../openlp_plugins/remotes/test_router.py | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/functional/openlp_plugins/remotes/test_router.py b/tests/functional/openlp_plugins/remotes/test_router.py index 6762f7643..5475405a0 100644 --- a/tests/functional/openlp_plugins/remotes/test_router.py +++ b/tests/functional/openlp_plugins/remotes/test_router.py @@ -37,7 +37,7 @@ from PyQt4 import QtGui from openlp.core.common import Settings from openlp.plugins.remotes.lib.httpserver import HttpRouter -from tests.functional import MagicMock +from mock import MagicMock, patch, mock_open __default_settings__ = { 'remotes/twelve hour': True, @@ -116,6 +116,7 @@ class TestRouter(TestCase): """ Test the get_content_type logic """ + # GIVEN: a set of files and their corresponding types headers = [ ['test.html', 'text/html'], ['test.css', 'text/css'], ['test.js', 'application/javascript'], ['test.jpg', 'image/jpeg'], ['test.gif', 'image/gif'], ['test.ico', 'image/x-icon'], @@ -123,6 +124,50 @@ class TestRouter(TestCase): ['test', 'text/plain'], ['', 'text/plain'], ['/test/test.html', 'text/html'], ['c:\\test\\test.html', 'text/html']] + # WHEN: calling each file type for header in headers: ext, content_type = self.router.get_content_type(header[0]) + # THEN: all types should match self.assertEqual(content_type, header[1], 'Mismatch of content type') + + def serve_file_without_params_test(self): + """ + Test the serve_file method without params + """ + # GIVEN: mocked environment + self.router.send_response = MagicMock() + self.router.send_header = MagicMock() + self.router.end_headers = MagicMock() + self.router.wfile = MagicMock() + self.router.html_dir = os.path.normpath('test/dir') + self.router.template_vars = MagicMock() + # WHEN: call serve_file with no file_name + self.router.serve_file() + # THEN: it should return a 404 + self.router.send_response.assert_called_once_with(404) + self.router.send_header.assert_called_once_with('Content-type','text/html') + self.assertEqual(self.router.end_headers.call_count, 1, + 'end_headers called once') + + def serve_file_with_valid_params_test(self): + """ + Test the serve_file method with an existing file + """ + # GIVEN: mocked environment + self.router.send_response = MagicMock() + self.router.send_header = MagicMock() + self.router.end_headers = MagicMock() + self.router.wfile = MagicMock() + self.router.html_dir = os.path.normpath('test/dir') + self.router.template_vars = MagicMock() + with patch('openlp.core.lib.os.path.exists') as mocked_exists, \ + patch('builtins.open', mock_open(read_data='123')): + mocked_exists.return_value = True + # WHEN: call serve_file with an existing html file + self.router.serve_file(os.path.normpath('test/dir/test.html')) + # THEN: it should return a 200 and the file + self.router.send_response.assert_called_once_with(200) + self.router.send_header.assert_called_once_with( + 'Content-type','text/html') + self.assertEqual(self.router.end_headers.call_count, 1, + 'end_headers called once') From e56414e22c3c82855e4eec426afb29acd6b535cb Mon Sep 17 00:00:00 2001 From: Felipe Polo-Wood Date: Thu, 14 Nov 2013 15:33:46 -0500 Subject: [PATCH 42/46] Fixed OS specific string Coding standard fixes --- openlp/plugins/remotes/lib/httprouter.py | 7 +++---- tests/functional/openlp_plugins/remotes/test_router.py | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/remotes/lib/httprouter.py b/openlp/plugins/remotes/lib/httprouter.py index b3652d4df..deba92c10 100644 --- a/openlp/plugins/remotes/lib/httprouter.py +++ b/openlp/plugins/remotes/lib/httprouter.py @@ -128,7 +128,7 @@ from openlp.core.common import AppLocation, Settings, translate from openlp.core.lib import Registry, PluginStatus, StringContent, image_to_byte log = logging.getLogger(__name__) -file_types = { +FILE_TYPES = { '.html': 'text/html', '.css': 'text/css', '.js': 'application/javascript', @@ -361,8 +361,7 @@ class HttpRouter(object): try: if ext == '.html': variables = self.template_vars - content = Template(filename=path, input_encoding='utf-8', - output_encoding='utf-8').render(**variables) + content = Template(filename=path, input_encoding='utf-8', output_encoding='utf-8').render(**variables) else: file_handle = open(path, 'rb') log.debug('Opened %s' % path) @@ -386,7 +385,7 @@ class HttpRouter(object): """ content_type = 'text/plain' ext = os.path.splitext(file_name)[1] - content_type = file_types.get(ext, 'text/plain') + content_type = FILE_TYPES.get(ext, 'text/plain') return ext, content_type def poll(self): diff --git a/tests/functional/openlp_plugins/remotes/test_router.py b/tests/functional/openlp_plugins/remotes/test_router.py index 5475405a0..4d7da2b91 100644 --- a/tests/functional/openlp_plugins/remotes/test_router.py +++ b/tests/functional/openlp_plugins/remotes/test_router.py @@ -37,7 +37,8 @@ from PyQt4 import QtGui from openlp.core.common import Settings from openlp.plugins.remotes.lib.httpserver import HttpRouter -from mock import MagicMock, patch, mock_open +from tests.functional import MagicMock, patch +from mock import mock_open __default_settings__ = { 'remotes/twelve hour': True, @@ -50,6 +51,7 @@ __default_settings__ = { 'remotes/ip address': '0.0.0.0' } +TEST_PATH = os.path.abspath(os.path.dirname(__file__)) class TestRouter(TestCase): """ @@ -122,8 +124,7 @@ class TestRouter(TestCase): ['test.gif', 'image/gif'], ['test.ico', 'image/x-icon'], ['test.png', 'image/png'], ['test.whatever', 'text/plain'], ['test', 'text/plain'], ['', 'text/plain'], - ['/test/test.html', 'text/html'], - ['c:\\test\\test.html', 'text/html']] + [os.path.join(TEST_PATH,'test.html'), 'text/html']] # WHEN: calling each file type for header in headers: ext, content_type = self.router.get_content_type(header[0]) From 81c2f1a4b3bd069ce69d0a1d1e98492259585807 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sat, 16 Nov 2013 21:04:16 +0000 Subject: [PATCH 43/46] updated tests --- openlp/core/lib/filedialog.py | 2 +- tests/functional/openlp_core_lib/test_file_dialog.py | 12 +++++++----- tests/functional/openlp_core_lib/test_htmlbuilder.py | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/openlp/core/lib/filedialog.py b/openlp/core/lib/filedialog.py index 03a8b8c47..bac1b5ce2 100644 --- a/openlp/core/lib/filedialog.py +++ b/openlp/core/lib/filedialog.py @@ -36,7 +36,7 @@ from urllib import parse from PyQt4 import QtGui -from openlp.core.lib import UiStrings +from openlp.core.common import UiStrings log = logging.getLogger(__name__) diff --git a/tests/functional/openlp_core_lib/test_file_dialog.py b/tests/functional/openlp_core_lib/test_file_dialog.py index 0a5736ff0..f42a865d7 100644 --- a/tests/functional/openlp_core_lib/test_file_dialog.py +++ b/tests/functional/openlp_core_lib/test_file_dialog.py @@ -1,12 +1,11 @@ """ Package to test the openlp.core.lib.filedialog package. """ -import copy from unittest import TestCase -from mock import MagicMock, call, patch +from openlp.core.common import UiStrings from openlp.core.lib.filedialog import FileDialog -from openlp.core.lib.uistrings import UiStrings +from tests.functional import MagicMock, patch class TestFileDialog(TestCase): """ @@ -64,8 +63,11 @@ class TestFileDialog(TestCase): # THEN: os.path.exists should have been called with known args. QmessageBox.information should have been # called. The returned result should corrilate with the input. - self.mocked_os.path.exists.assert_has_calls([call('/Valid File'), call('/url%20encoded%20file%20%231'), - call('/url encoded file #1'), call('/non-existing'), call('/non-existing')]) + self.mocked_os.path.exists.assert_callde_with('/Valid File') + self.mocked_os.path.exists.assert_callde_with('/url%20encoded%20file%20%231') + self.mocked_os.path.exists.assert_callde_with('/url encoded file #1') + self.mocked_os.path.exists.assert_callde_with('/non-existing') + self.mocked_os.path.exists.assert_callde_with('/non-existing') self.mocked_qt_gui.QmessageBox.information.called_with(self.mocked_parent, UiStrings().FileNotFound, UiStrings().FileNotFoundMessage % '/non-existing') self.assertEqual(result, ['/Valid File', '/url encoded file #1'], 'The returned file list is incorrect') \ No newline at end of file diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py index 0ffab5458..fafa277d7 100644 --- a/tests/functional/openlp_core_lib/test_htmlbuilder.py +++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py @@ -3,13 +3,13 @@ Package to test the openlp.core.lib.htmlbuilder module. """ from unittest import TestCase -from mock import MagicMock, patch from PyQt4 import QtCore from openlp.core.lib.htmlbuilder import build_html, build_background_css, build_lyrics_css, build_lyrics_outline_css, \ build_lyrics_format_css, build_footer_css from openlp.core.lib.theme import HorizontalType, VerticalType +from tests.functional import MagicMock, patch HTML = """ From f32409b5a528061adc9b1f7f1aba599ec012f04e Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 6 Dec 2013 19:00:37 +0000 Subject: [PATCH 44/46] format changes --- openlp/plugins/presentations/lib/messagelistener.py | 2 +- tests/interfaces/openlp_core_ui/test_thememanagerhelper.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index 6ab723c9e..43f93cf2c 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -316,7 +316,7 @@ class MessageListener(object): hide_mode = message[2] file = item.get_frame_path() self.handler = item.processor - if self.handler == self.media_item.Automatic: + if self.handler == self.media_item.automatic: self.handler = self.media_item.findControllerByType(file) if not self.handler: return diff --git a/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py b/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py index eb964a045..3209fa61a 100644 --- a/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py +++ b/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py @@ -73,11 +73,11 @@ class TestThemeManagerHelper(TestCase): # THEN: self.assertEqual(1, self.helper.build_theme_path.call_count, - 'The function build_theme_path should have been called') + 'The function build_theme_path should have been called') self.assertEqual(1, self.helper.load_first_time_themes.call_count, - 'The function load_first_time_themes should have been called') + 'The function load_first_time_themes should have been called only once') self.assertEqual(self.helper.global_theme , 'my_theme', - 'The global theme should have been set to my_theme') + 'The global theme should have been set to my_theme') def test_build_theme_path(self): """ From 9fd590bb7041b181351960af653983f422c3ee34 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 6 Dec 2013 19:07:02 +0000 Subject: [PATCH 45/46] clean up tests --- tests/interfaces/openlp_core_ui/test_thememanagerhelper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py b/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py index 3209fa61a..aa70edd51 100644 --- a/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py +++ b/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py @@ -33,7 +33,6 @@ import os from unittest import TestCase from tempfile import mkstemp -from openlp.core.common import AppLocation, get_frozen_path from openlp.core.common import Settings from openlp.core.ui import ThemeManagerHelper from tests.functional import patch, MagicMock @@ -76,7 +75,7 @@ class TestThemeManagerHelper(TestCase): 'The function build_theme_path should have been called') self.assertEqual(1, self.helper.load_first_time_themes.call_count, 'The function load_first_time_themes should have been called only once') - self.assertEqual(self.helper.global_theme , 'my_theme', + self.assertEqual(self.helper.global_theme, 'my_theme', 'The global theme should have been set to my_theme') def test_build_theme_path(self): @@ -96,4 +95,5 @@ class TestThemeManagerHelper(TestCase): self.helper.build_theme_path() # THEN: - A=1 \ No newline at end of file + self.assertEqual(self.helper.path, self.helper.theme_form.path, + 'The theme path and the main path should be the same value') \ No newline at end of file From 440cefa5f677d81b083e5c06b1134a254c54d4e5 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 6 Dec 2013 19:09:29 +0000 Subject: [PATCH 46/46] formatting --- tests/functional/openlp_core_lib/test_theme.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_theme.py b/tests/functional/openlp_core_lib/test_theme.py index cf8d1f661..abedc230b 100644 --- a/tests/functional/openlp_core_lib/test_theme.py +++ b/tests/functional/openlp_core_lib/test_theme.py @@ -64,9 +64,9 @@ class TestTheme(TestCase): self.assertTrue(default_theme.background_border_color == '#000000', 'The theme should have a black border') self.assertTrue(default_theme.background_type == 'solid', 'The theme should have a solid backgrounds') self.assertTrue(default_theme.display_vertical_align == 0, - 'The theme should have a display_vertical_align of 0') + 'The theme should have a display_vertical_align of 0') self.assertTrue(default_theme.font_footer_name == "Arial", - 'The theme should have a font_footer_name of Arial') + 'The theme should have a font_footer_name of Arial') self.assertTrue(default_theme.font_main_bold is False, 'The theme should have a font_main_bold of false') self.assertTrue(len(default_theme.__dict__) == 47, 'The theme should have 47 variables')