Migrate Display

Signed-off-by: Tim <tim.bentley@gmail.com>
This commit is contained in:
Tim Bentley 2020-02-01 21:12:07 +00:00
parent d08762426c
commit 020661059f
18 changed files with 97 additions and 99 deletions

View File

@ -241,6 +241,7 @@ class Settings(QtCore.QSettings):
'core/loop delay': 5,
'core/recent files': [],
'core/save prompt': False,
'core/screens': '{}',
'core/screen blank': False,
'core/show splash': True,
'core/logo background color': '#ffffff',

View File

@ -35,7 +35,6 @@ from openlp.core.common import ThemeLevel
from openlp.core.common.i18n import translate
from openlp.core.common.mixins import LogMixin
from openlp.core.common.registry import Registry, RegistryBase
from openlp.core.common.settings import Settings
from openlp.core.common.utils import wait_for
from openlp.core.display.screens import ScreenList
from openlp.core.display.window import DisplayWindow
@ -535,7 +534,7 @@ class ThemePreviewRenderer(LogMixin, DisplayWindow):
def generate_footer(self):
"""
"""
footer_template = Settings().value('songs/footer template')
footer_template = self.settings.value('songs/footer template')
# Keep this in sync with the list in songstab.py
vars = {
'title': TITLE,
@ -544,7 +543,7 @@ class ThemePreviewRenderer(LogMixin, DisplayWindow):
'Author who wrote the lyrics of a song'),
'authors_words': [AUTHOR],
'copyright': FOOTER_COPYRIGHT,
'ccli_license': Settings().value('core/ccli number'),
'ccli_license': self.settings.value('core/ccli number'),
'ccli_license_label': translate('SongsPlugin.MediaItem', 'CCLI License'),
'ccli_number': CCLI_NO,
}

View File

@ -30,7 +30,6 @@ from PyQt5 import QtCore, QtWidgets
from openlp.core.common import Singleton
from openlp.core.common.i18n import translate
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
log = logging.getLogger(__name__)
@ -215,6 +214,7 @@ class ScreenList(metaclass=Singleton):
screen_list.desktop.screenCountChanged.connect(screen_list.on_screen_count_changed)
screen_list.desktop.primaryScreenChanged.connect(screen_list.on_primary_screen_changed)
screen_list.update_screens()
cls.settings = Registry().get('settings')
screen_list.load_screen_settings()
return screen_list
@ -222,13 +222,7 @@ class ScreenList(metaclass=Singleton):
"""
Loads the screen size and the screen number from the 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 = {
'core/screens': '{}'
}
Settings.extend_default_settings(screen_settings)
screen_settings = Settings().value('core/screens')
screen_settings = self.settings.value('core/screens')
if screen_settings:
for number, screen_dict in screen_settings.items():
# Sometimes this loads as a string instead of an int
@ -244,7 +238,7 @@ class ScreenList(metaclass=Singleton):
"""
Saves the screen size and screen settings
"""
Settings().setValue('core/screens', {screen.number: screen.to_dict() for screen in self.screens})
self.settings.setValue('core/screens', {screen.number: screen.to_dict() for screen in self.screens})
def get_display_screen_list(self):
"""

View File

@ -24,7 +24,7 @@ Provide HTML Tag management and Formatting Tag access class
import json
from openlp.core.common.i18n import translate
from openlp.core.common.settings import Settings
from openlp.core.common.registry import Registry
class FormattingTags(object):
@ -49,7 +49,7 @@ class FormattingTags(object):
The tags to be saved..
"""
# Formatting Tags were also known as display tags.
Settings().setValue('formattingTags/html_tags', json.dumps(new_tags) if new_tags else '')
Registry().get('settings').setValue('formattingTags/html_tags', json.dumps(new_tags) if new_tags else '')
@staticmethod
def load_tags():
@ -152,7 +152,7 @@ class FormattingTags(object):
# Append the base tags.
FormattingTags.add_html_tags(base_tags)
FormattingTags.add_html_tags(temporary_tags)
user_expands_string = str(Settings().value('formattingTags/html_tags'))
user_expands_string = str(Registry().get('settings').value('formattingTags/html_tags'))
# If we have some user ones added them as well
if user_expands_string:
user_tags = json.loads(user_expands_string)

View File

@ -31,7 +31,6 @@ import time
from PyQt5 import QtCore
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.display.screens import ScreenList
from openlp.core.lib import image_to_byte, resize_image
from openlp.core.threading import ThreadWorker, run_thread
@ -339,7 +338,7 @@ class ImageManager(QtCore.QObject):
width = self.width if image.width == -1 else image.width
height = self.height if image.height == -1 else image.height
image.image = resize_image(image.path, width, height, image.background,
Settings().value('advanced/ignore aspect ratio'))
Registry().get('settings').value('advanced/ignore aspect ratio'))
# Set the priority to Lowest and stop here as we need to process more important images first.
if image.priority == Priority.Normal:
self._conversion_queue.modify_priority(image, Priority.Lowest)

View File

@ -29,7 +29,6 @@ from PyQt5 import QtCore, QtWidgets
from openlp.core.common.i18n import UiStrings, translate
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib import ServiceItemContext
from openlp.core.lib.plugin import StringContent
from openlp.core.lib.serviceitem import ServiceItem
@ -322,7 +321,7 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
"""
file_paths, selected_filter = FileDialog.getOpenFileNames(
self, self.on_new_prompt,
Settings().value(self.settings_section + '/last directory'),
self.settings.value(self.settings_section + '/last directory'),
self.on_new_file_masks)
log.info('New file(s) {file_paths}'.format(file_paths=file_paths))
if file_paths:
@ -385,8 +384,9 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
if target_group is None:
self.list_view.clear()
self.load_list(full_list, target_group)
Settings().setValue(self.settings_section + '/last directory', file_paths[0].parent)
Settings().setValue('{section}/{section} files'.format(section=self.settings_section), self.get_file_list())
self.settings.setValue(self.settings_section + '/last directory', file_paths[0].parent)
self.settings.setValue('{section}/{section} files'.
format(section=self.settings_section), self.get_file_list())
if duplicates_found:
critical_error_message_box(UiStrings().Duplicate,
translate('OpenLP.MediaManagerItem',
@ -470,10 +470,10 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
"""
Allows the list click action to be determined dynamically
"""
if Settings().value('advanced/double click live'):
if self.settings.value('advanced/double click live'):
if self.can_make_live:
self.on_live_click()
elif not Settings().value('advanced/single click preview'):
elif not self.settings.value('advanced/single click preview'):
# NOTE: The above check is necessary to prevent bug #1419300
if self.can_preview:
self.on_preview_click()
@ -482,7 +482,7 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
"""
Allows the change of current item in the list to be actioned
"""
if Settings().value('advanced/single click preview') and self.quick_preview_allowed \
if self.settings.value('advanced/single click preview') and self.quick_preview_allowed \
and self.list_view.selectedIndexes() and self.auto_select_id == -1:
self.on_preview_click(True)

View File

@ -27,7 +27,6 @@ from openlp.core.common.enum import PluginStatus
from openlp.core.common.i18n import UiStrings
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.registry import Registry, RegistryBase
from openlp.core.common.settings import Settings
from openlp.core.version import get_version
@ -164,14 +163,14 @@ class Plugin(RegistryBase, RegistryProperties):
"""
Sets the status of the plugin
"""
self.status = Settings().value(self.settings_section + '/status')
self.status = self.settings.value(self.settings_section + '/status')
def toggle_status(self, new_status):
"""
Changes the status of the plugin and remembers it
"""
self.status = new_status
Settings().setValue(self.settings_section + '/status', self.status)
self.settings.setValue(self.settings_section + '/status', self.status)
if new_status == PluginStatus.Active:
self.initialise()
elif new_status == PluginStatus.Inactive:

View File

@ -90,7 +90,7 @@ class SelectPlanForm(QtWidgets.QDialog, Ui_SelectPlanDialog):
"""
Close dialog.
:param r: The result of the dialog.
:param result_code: The result of the dialog.
"""
log.debug('Closing PlanningCenterForm')
return QtWidgets.QDialog.done(self, result_code)

View File

@ -58,6 +58,7 @@ class TestController(TestCase):
"""
Registry.create()
self.registry = Registry()
Registry().register('settings', Settings())
self.mocked_live_controller = MagicMock()
self.desktop = MagicMock()
self.desktop.primaryScreen.return_value = SCREEN['primary']
@ -79,7 +80,6 @@ class TestController(TestCase):
Registry().register('renderer', self.mocked_renderer)
flask_app.config['TESTING'] = True
self.client = flask_app.test_client()
Registry().register('settings', Settings())
def test_controller_text_empty(self):
"""

View File

@ -51,6 +51,7 @@ class TestScreenList(TestCase):
self.application = QtWidgets.QApplication.instance()
Registry.create()
Registry().register('settings', MagicMock())
self.application.setOrganizationName('OpenLP-tests')
self.application.setOrganizationDomain('openlp.org')
self.screens = ScreenList.create(self.desktop)

View File

@ -22,7 +22,6 @@
Package to test the openlp.core.lib.formattingtags package.
"""
import copy
from unittest import TestCase
from unittest.mock import patch
from openlp.core.lib.formattingtags import FormattingTags
@ -38,65 +37,57 @@ TAG = {
}
class TestFormattingTags(TestCase):
def test_get_html_tags_no_user_tags(mock_settings):
"""
Test the FormattingTags class' get_html_tags static method.
"""
with patch('openlp.core.lib.translate') as mocked_translate, \
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
mocked_settings.value.return_value = ''
mocked_json.load.return_value = []
def tearDown(self):
"""
Clean up the FormattingTags class.
"""
FormattingTags.html_expands = []
# WHEN: Get the display tags.
FormattingTags.load_tags()
old_tags_list = copy.deepcopy(FormattingTags.get_html_tags())
FormattingTags.load_tags()
new_tags_list = FormattingTags.get_html_tags()
def test_get_html_tags_no_user_tags(self):
"""
Test the FormattingTags class' get_html_tags static method.
"""
with patch('openlp.core.lib.translate') as mocked_translate, \
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
mocked_settings.value.return_value = ''
mocked_json.load.return_value = []
# THEN: Lists should be identical.
assert old_tags_list == new_tags_list, 'The formatting tag lists should be identical.'
# WHEN: Get the display tags.
FormattingTags.load_tags()
old_tags_list = copy.deepcopy(FormattingTags.get_html_tags())
FormattingTags.load_tags()
new_tags_list = FormattingTags.get_html_tags()
# THEN: Lists should be identical.
assert old_tags_list == new_tags_list, 'The formatting tag lists should be identical.'
def test_get_html_tags_with_user_tags(mock_settings):
"""
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.formattingtags.json') as mocked_json:
# GIVEN: Our mocked modules and functions.
mocked_translate.side_effect = lambda module, string_to_translate: string_to_translate
mock_settings.value.return_value = ''
mocked_json.loads.side_effect = [[], [TAG]]
def test_get_html_tags_with_user_tags(self):
"""
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.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
mocked_settings.value.return_value = ''
mocked_json.loads.side_effect = [[], [TAG]]
# WHEN: Get the display tags.
FormattingTags.load_tags()
old_tags_list = copy.deepcopy(FormattingTags.get_html_tags())
# WHEN: Get the display tags.
FormattingTags.load_tags()
old_tags_list = copy.deepcopy(FormattingTags.get_html_tags())
# WHEN: Add our tag and get the tags again.
FormattingTags.load_tags()
FormattingTags.add_html_tags([TAG])
new_tags_list = copy.deepcopy(FormattingTags.get_html_tags())
# WHEN: Add our tag and get the tags again.
FormattingTags.load_tags()
FormattingTags.add_html_tags([TAG])
new_tags_list = copy.deepcopy(FormattingTags.get_html_tags())
# THEN: Lists should not be identical.
assert old_tags_list != new_tags_list, 'The lists should be different.'
# THEN: Lists should not be identical.
assert old_tags_list != new_tags_list, 'The lists should be different.'
# THEN: Added tag and last tag should be the same.
new_tag = new_tags_list.pop()
assert TAG == new_tag, 'Tags should be identical.'
# THEN: Added tag and last tag should be the same.
new_tag = new_tags_list.pop()
assert TAG == new_tag, 'Tags should be identical.'
# WHEN: Remove the new tag.
FormattingTags.remove_html_tag(len(new_tags_list))
# WHEN: Remove the new tag.
FormattingTags.remove_html_tag(len(new_tags_list))
# THEN: The lists should now be identical.
assert old_tags_list == FormattingTags.get_html_tags(), 'The lists should be identical.'
# THEN: The lists should now be identical.
assert old_tags_list == FormattingTags.get_html_tags(), 'The lists should be identical.'

View File

@ -24,6 +24,7 @@ Package to test the openlp.core.lib.mediamanageritem package.
from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.common.registry import Registry
from openlp.core.lib.mediamanageritem import MediaManagerItem
from tests.helpers.testmixin import TestMixin
@ -36,20 +37,20 @@ class TestMediaManagerItem(TestCase, TestMixin):
"""
Mock out stuff for all the tests
"""
Registry.create()
self.setup_patcher = patch('openlp.core.lib.mediamanageritem.MediaManagerItem._setup')
self.mocked_setup = self.setup_patcher.start()
self.addCleanup(self.setup_patcher.stop)
@patch('openlp.core.lib.mediamanageritem.Settings')
@patch('openlp.core.lib.mediamanageritem.MediaManagerItem.on_preview_click')
def test_on_double_clicked(self, mocked_on_preview_click, MockedSettings):
def test_on_double_clicked(self, mocked_on_preview_click):
"""
Test that when an item is double-clicked then the item is previewed
"""
# GIVEN: A setting to enable "Double-click to go live" and a media manager item
mocked_settings = MagicMock()
mocked_settings.value.return_value = False
MockedSettings.return_value = mocked_settings
Registry().register('settings', mocked_settings)
mmi = MediaManagerItem(None)
mmi.can_preview = True
mmi.can_make_live = True
@ -79,16 +80,15 @@ class TestMediaManagerItem(TestCase, TestMixin):
assert mmi.can_make_live is True, 'There should be a make live by default'
assert mmi.can_add_to_service is True, 'There should be a add to service icon by default'
@patch('openlp.core.lib.mediamanageritem.Settings')
@patch('openlp.core.lib.mediamanageritem.MediaManagerItem.on_live_click')
def test_on_double_clicked_go_live(self, mocked_on_live_click, MockedSettings):
def test_on_double_clicked_go_live(self, mocked_on_live_click):
"""
Test that when "Double-click to go live" is enabled that the item goes live
"""
# GIVEN: A setting to enable "Double-click to go live" and a media manager item
mocked_settings = MagicMock()
mocked_settings.value.side_effect = lambda x: x == 'advanced/double click live'
MockedSettings.return_value = mocked_settings
Registry().register('settings', mocked_settings)
mmi = MediaManagerItem(None)
mmi.can_preview = True
mmi.can_make_live = True
@ -100,18 +100,16 @@ class TestMediaManagerItem(TestCase, TestMixin):
# THEN: on_live_click() should have been called
mocked_on_live_click.assert_called_with()
@patch('openlp.core.lib.mediamanageritem.Settings')
@patch('openlp.core.lib.mediamanageritem.MediaManagerItem.on_live_click')
@patch('openlp.core.lib.mediamanageritem.MediaManagerItem.on_preview_click')
def test_on_double_clicked_single_click_preview(self, mocked_on_preview_click, mocked_on_live_click,
MockedSettings):
def test_on_double_clicked_single_click_preview(self, mocked_on_preview_click, mocked_on_live_click):
"""
Test that when "Single-click preview" is enabled then nothing happens on double-click
"""
# GIVEN: A setting to enable "Double-click to go live" and a media manager item
mocked_settings = MagicMock()
mocked_settings.value.side_effect = lambda x: x == 'advanced/single click preview'
MockedSettings.return_value = mocked_settings
Registry().register('settings', mocked_settings)
mmi = MediaManagerItem(None)
mmi.can_preview = True
mmi.can_make_live = True

View File

@ -25,6 +25,7 @@ from unittest import TestCase
from unittest.mock import patch
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.plugins.media.mediaplugin import MediaPlugin
from tests.helpers.testmixin import TestMixin
@ -35,6 +36,7 @@ class TestMediaPlugin(TestCase, TestMixin):
"""
def setUp(self):
Registry.create()
Registry().register('settings', Settings())
@patch('openlp.plugins.media.mediaplugin.Plugin.initialise')
def test_initialise(self, mocked_initialise):

View File

@ -88,9 +88,9 @@ class TestPdfController(TestCase, TestMixin):
self.desktop.primaryScreen.return_value = SCREEN['primary']
self.desktop.screenCount.return_value = SCREEN['number']
self.desktop.screenGeometry.return_value = SCREEN['size']
self.screens = ScreenList.create(self.desktop)
Settings().extend_default_settings(__default_settings__)
Registry().register('settings', Settings())
self.screens = ScreenList.create(self.desktop)
self.temp_folder_path = Path(mkdtemp())
self.thumbnail_folder_path = Path(mkdtemp())
self.mock_plugin = MagicMock()

View File

@ -28,6 +28,7 @@ from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport
from tests.helpers.testmixin import TestMixin
@ -41,6 +42,7 @@ class TestOpenLyricsExport(TestCase, TestMixin):
Create the registry
"""
Registry.create()
Registry().register('settings', Settings())
self.temp_folder = Path(mkdtemp())
def tearDown(self):

View File

@ -92,6 +92,7 @@ class TestOpenLyricsImport(TestCase, TestMixin):
self.setup_application()
Registry.create()
self.build_settings()
Registry().register('settings', Settings())
def tearDown(self):
"""

View File

@ -56,8 +56,9 @@ class TestSettingsForm(TestCase, TestMixin):
self.desktop.primaryScreen.return_value = SCREEN['primary']
self.desktop.screenCount.return_value = SCREEN['number']
self.desktop.screenGeometry.return_value = SCREEN['size']
self.screens = ScreenList.create(self.desktop)
Registry.create()
Registry().register('settings', MagicMock())
self.screens = ScreenList.create(self.desktop)
self.form = settingsform.SettingsForm()
def tearDown(self):

View File

@ -235,7 +235,6 @@ class TestSelectPlanForm(TestCase, TestMixin):
# GIVEN: An SelectPlanForm instance with airplane mode enabled, resources available,
# mocked out "on_new_service_clicked"
with patch('PyQt5.QtWidgets.QDialog.exec'), \
patch('openlp.core.common.registry.Registry.get'), \
patch('openlp.plugins.planningcenter.lib.songimport.PlanningCenterSongImport.finish') \
as mock_song_import, \
patch('openlp.plugins.planningcenter.lib.customimport.CustomSlide') as mock_custom_slide_import, \
@ -245,6 +244,11 @@ class TestSelectPlanForm(TestCase, TestMixin):
mock_date.today.return_value = date(2019, 9, 29)
mock_date.side_effect = lambda *args, **kw: date(*args, **kw)
self.form.exec()
Registry().register('service_manager', MagicMock())
Registry().register('plugin_manager', MagicMock())
Registry().register('songs', MagicMock())
Registry().register('bibles', MagicMock())
Registry().register('custom', MagicMock())
# WHEN: The Service Type combo is set to index 1 and the Select Plan combo box is set to
# index 1 and the "Import New" button is clicked
self.form.service_type_combo_box.setCurrentIndex(1)
@ -262,7 +266,6 @@ class TestSelectPlanForm(TestCase, TestMixin):
# GIVEN: An SelectPlanForm instance with airplane mode enabled, resources available,
# mocked out "on_new_service_clicked"
with patch('PyQt5.QtWidgets.QDialog.exec'), \
patch('openlp.core.common.registry.Registry.get'), \
patch('openlp.plugins.planningcenter.lib.songimport.PlanningCenterSongImport.finish') \
as mock_song_import, \
patch('openlp.plugins.planningcenter.lib.customimport.CustomSlide') as mock_custom_slide_import, \
@ -272,6 +275,11 @@ class TestSelectPlanForm(TestCase, TestMixin):
mock_date.today.return_value = date(2019, 9, 29)
mock_date.side_effect = lambda *args, **kw: date(*args, **kw)
self.form.exec()
Registry().register('service_manager', MagicMock())
Registry().register('plugin_manager', MagicMock())
Registry().register('songs', MagicMock())
Registry().register('bibles', MagicMock())
Registry().register('custom', MagicMock())
# WHEN: The Service Type combo is set to index 1 and the Select Plan combo box is
# set to index 1 and the "Update" button is clicked
self.form.service_type_combo_box.setCurrentIndex(1)
@ -289,7 +297,6 @@ class TestSelectPlanForm(TestCase, TestMixin):
# GIVEN: An SelectPlanForm instance with airplane mode enabled, resources available,
# mocked out "on_new_service_clicked"
with patch('PyQt5.QtWidgets.QDialog.exec'), \
patch('openlp.core.common.registry.Registry.get') as mock_get, \
patch('openlp.plugins.planningcenter.lib.songimport.PlanningCenterSongImport.finish'), \
patch('openlp.plugins.planningcenter.lib.customimport.CustomSlide'), \
patch('openlp.plugins.planningcenter.forms.selectplanform.parse_reference') as mock_bible_import, \
@ -299,8 +306,11 @@ class TestSelectPlanForm(TestCase, TestMixin):
mock_date.side_effect = lambda *args, **kw: date(*args, **kw)
mock_bibles = {}
mock_bibles['other_bible'] = MagicMock()
mock_get.return_value.plugin.manager.get_bibles.return_value = mock_bibles
mock_get.return_value.version_combo_box.currentText.return_value = ''
Registry().register('service_manager', MagicMock())
Registry().register('plugin_manager', MagicMock())
Registry().register('songs', MagicMock())
Registry().register('bibles', MagicMock())
Registry().register('custom', MagicMock())
self.form.exec()
# WHEN: The Service Type combo is set to index 1 and the Select Plan combo box
# is set to index 1 and the "Import New" button is clicked