forked from openlp/openlp
Cleanups, add missing theme functionality
This commit is contained in:
parent
92d67468e2
commit
42e6640339
@ -49,7 +49,6 @@ class HttpWorker(ThreadWorker):
|
||||
"""
|
||||
address = Registry().get('settings_thread').value('api/ip address')
|
||||
port = Registry().get('settings_thread').value('api/port')
|
||||
Registry().execute('get_website_version')
|
||||
try:
|
||||
application.static_folder = str(AppLocation.get_section_data_path('remotes') / 'static')
|
||||
self.server = create_server(application, host=address, port=port)
|
||||
|
@ -18,7 +18,6 @@
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||
##########################################################################
|
||||
|
||||
import json
|
||||
|
||||
from openlp.core.common.registry import Registry
|
||||
|
@ -64,7 +64,7 @@ def service_set():
|
||||
id = int(data.get('id', -1))
|
||||
except ValueError:
|
||||
abort(400)
|
||||
Registry().get('service_manager').set_item(id)
|
||||
Registry().get('service_manager').servicemanager_set_item.emit(id)
|
||||
return '', 204
|
||||
|
||||
|
||||
|
@ -1179,6 +1179,8 @@ var Display = {
|
||||
footerStyle.color = Display._theme.font_footer_color;
|
||||
footerStyle["font-family"] = Display._theme.font_footer_name;
|
||||
footerStyle["font-size"] = "" + Display._theme.font_footer_size + "pt";
|
||||
footerStyle["font-style"] = !!Display._theme.font_footer_italics ? "italic" : "";
|
||||
footerStyle["font-weight"] = !!Display._theme.font_footer_bold ? "bold" : "";
|
||||
footerStyle["white-space"] = Display._theme.font_footer_wrap ? "normal" : "nowrap";
|
||||
Display._footerContainer.style.cssText = "";
|
||||
for (var footerKey in footerStyle) {
|
||||
|
@ -509,7 +509,7 @@ def get_start_tags(raw_text):
|
||||
return raw_text + ''.join(end_tags), ''.join(start_tags), ''.join(html_tags)
|
||||
|
||||
|
||||
class ThemePreviewRenderer(LogMixin, DisplayWindow):
|
||||
class ThemePreviewRenderer(DisplayWindow, LogMixin):
|
||||
"""
|
||||
A virtual display used for rendering thumbnails and other offscreen tasks
|
||||
"""
|
||||
|
@ -31,7 +31,7 @@ from PyQt5 import QtCore, QtWebChannel, QtWidgets
|
||||
from openlp.core.common.applocation import AppLocation
|
||||
from openlp.core.common.enum import ServiceItemType
|
||||
from openlp.core.common.i18n import translate
|
||||
from openlp.core.common.mixins import RegistryProperties
|
||||
from openlp.core.common.mixins import LogMixin, RegistryProperties
|
||||
from openlp.core.common.path import path_to_str
|
||||
from openlp.core.common.registry import Registry
|
||||
from openlp.core.common.utils import wait_for
|
||||
@ -118,7 +118,7 @@ class DisplayWatcher(QtCore.QObject):
|
||||
self.initialised.emit(is_initialised)
|
||||
|
||||
|
||||
class DisplayWindow(QtWidgets.QWidget, RegistryProperties):
|
||||
class DisplayWindow(QtWidgets.QWidget, RegistryProperties, LogMixin):
|
||||
"""
|
||||
This is a window to show the output
|
||||
"""
|
||||
|
@ -1273,7 +1273,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
|
||||
:param current_index: The combo box index for the selected item
|
||||
"""
|
||||
self.service_theme = self.theme_combo_box.currentText()
|
||||
self.settings.setValue(self.main_window.service_manager_settings_section + '/service theme', self.service_theme)
|
||||
self.settings.setValue('servicemanager/service theme', self.service_theme)
|
||||
self.regenerate_service_items(True)
|
||||
|
||||
def theme_change(self):
|
||||
@ -1289,7 +1289,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
|
||||
"""
|
||||
Set the theme for the current service remotely
|
||||
"""
|
||||
self.service_theme = self.settings.value(self.main_window.service_manager_settings_section + '/service theme')
|
||||
self.service_theme = self.settings.value('servicemanager/service theme')
|
||||
find_and_set_in_combo_box(self.theme_combo_box, self.service_theme)
|
||||
self.regenerate_service_items(True)
|
||||
|
||||
@ -1622,7 +1622,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
|
||||
find_and_set_in_combo_box(self.theme_combo_box, self.service_theme)
|
||||
self.regenerate_service_items()
|
||||
|
||||
def on_theme_change_action(self):
|
||||
def on_theme_change_action(self, field=None):
|
||||
"""
|
||||
Handles theme change events
|
||||
"""
|
||||
|
@ -296,6 +296,9 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties):
|
||||
"""
|
||||
self.footer_area_page.font_name = self.theme.font_footer_name
|
||||
self.footer_area_page.font_color = self.theme.font_footer_color
|
||||
self.footer_area_page.is_bold = self.theme.font_footer_bold
|
||||
self.footer_area_page.is_italic = self.theme.font_footer_italics
|
||||
self.footer_area_page.font_size = self.theme.font_footer_size
|
||||
|
||||
def set_position_page_values(self):
|
||||
"""
|
||||
@ -363,6 +366,7 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties):
|
||||
self.theme.background_filename = self.background_page.stream_mrl
|
||||
# main page
|
||||
self.theme.font_main_name = self.main_area_page.font_name
|
||||
self.theme.font_main_color = self.main_area_page.font_color
|
||||
self.theme.font_main_size = self.main_area_page.font_size
|
||||
self.theme.font_main_line_adjustment = self.main_area_page.line_spacing
|
||||
self.theme.font_main_outline_size = self.main_area_page.outline_size
|
||||
@ -371,7 +375,10 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties):
|
||||
self.theme.font_main_italics = self.main_area_page.is_italic
|
||||
# footer page
|
||||
self.theme.font_footer_name = self.footer_area_page.font_name
|
||||
self.theme.font_footer_color = self.footer_area_page.font_color
|
||||
self.theme.font_footer_size = self.footer_area_page.font_size
|
||||
self.theme.font_footer_bold = self.footer_area_page.is_bold
|
||||
self.theme.font_footer_italics = self.footer_area_page.is_italic
|
||||
# position page (main)
|
||||
self.theme.font_main_override = not self.area_position_page.use_main_default_location
|
||||
if self.theme.font_main_override:
|
||||
|
@ -141,7 +141,6 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
Constructor
|
||||
"""
|
||||
super(ThemeManager, self).__init__(parent)
|
||||
self.settings_section = 'themes'
|
||||
# Variables
|
||||
self._theme_list = {}
|
||||
self.old_background_image_path = None
|
||||
@ -165,7 +164,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
process the bootstrap initialise setup request
|
||||
"""
|
||||
self.setup_ui(self)
|
||||
self.global_theme = self.settings.value(self.settings_section + '/global theme')
|
||||
self.global_theme = self.settings.value('themes/global theme')
|
||||
self.build_theme_path()
|
||||
|
||||
def bootstrap_post_set_up(self):
|
||||
@ -206,7 +205,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
|
||||
:rtype: None
|
||||
"""
|
||||
self.theme_path = AppLocation.get_section_data_path(self.settings_section)
|
||||
self.theme_path = AppLocation.get_section_data_path('themes')
|
||||
self.thumb_path = self.theme_path / 'thumbnails'
|
||||
create_paths(self.theme_path, self.thumb_path)
|
||||
|
||||
@ -249,7 +248,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
"""
|
||||
Change the global theme when it is changed through the Themes settings tab
|
||||
"""
|
||||
self.global_theme = self.settings.value(self.settings_section + '/global theme')
|
||||
self.global_theme = self.settings.value('themes/global theme')
|
||||
self.log_debug('change_global_from_tab {text}'.format(text=self.global_theme))
|
||||
for count in range(0, self.theme_list_widget.count()):
|
||||
# reset the old name
|
||||
@ -282,7 +281,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
self.global_theme = self.theme_list_widget.item(count).text()
|
||||
name = translate('OpenLP.ThemeManager', '{text} (default)').format(text=self.global_theme)
|
||||
self.theme_list_widget.item(count).setText(name)
|
||||
self.settings.setValue(self.settings_section + '/global theme', self.global_theme)
|
||||
self.settings.setValue('themes/global theme', self.global_theme)
|
||||
Registry().execute('theme_update_global')
|
||||
self._push_themes()
|
||||
|
||||
@ -423,12 +422,12 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
FileDialog.getSaveFileName(self.main_window,
|
||||
translate('OpenLP.ThemeManager',
|
||||
'Save Theme - ({name})').format(name=theme_name),
|
||||
self.settings.value(self.settings_section + '/last directory export'),
|
||||
self.settings.value('themes/last directory export'),
|
||||
translate('OpenLP.ThemeManager', 'OpenLP Themes (*.otz)'),
|
||||
translate('OpenLP.ThemeManager', 'OpenLP Themes (*.otz)'))
|
||||
self.application.set_busy_cursor()
|
||||
if export_path:
|
||||
self.settings.setValue(self.settings_section + '/last directory export', export_path.parent)
|
||||
self.settings.setValue('themes/last directory export', export_path.parent)
|
||||
if self._export_theme(export_path.with_suffix('.otz'), theme_name):
|
||||
QtWidgets.QMessageBox.information(self,
|
||||
translate('OpenLP.ThemeManager', 'Theme Exported'),
|
||||
@ -472,7 +471,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
file_paths, filter_used = FileDialog.getOpenFileNames(
|
||||
self,
|
||||
translate('OpenLP.ThemeManager', 'Select Theme Import File'),
|
||||
self.settings.value(self.settings_section + '/last directory import'),
|
||||
self.settings.value('themes/last directory import'),
|
||||
translate('OpenLP.ThemeManager', 'OpenLP Themes (*.otz)'))
|
||||
self.log_info('New Themes {file_paths}'.format(file_paths=file_paths))
|
||||
if not file_paths:
|
||||
@ -481,7 +480,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
new_themes = []
|
||||
for file_path in file_paths:
|
||||
new_themes.append(self.unzip_theme(file_path, self.theme_path))
|
||||
self.settings.setValue(self.settings_section + '/last directory import', file_path.parent)
|
||||
self.settings.setValue('themes/last directory import', file_path.parent)
|
||||
self.update_preview_images(new_themes)
|
||||
self.load_themes()
|
||||
self.application.set_normal_cursor()
|
||||
@ -491,7 +490,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
Imports any themes on start up and makes sure there is at least one theme
|
||||
"""
|
||||
self.application.set_busy_cursor()
|
||||
theme_paths = AppLocation.get_files(self.settings_section, '.otz')
|
||||
theme_paths = AppLocation.get_files('themes', '.otz')
|
||||
new_themes = []
|
||||
for theme_path in theme_paths:
|
||||
theme_path = self.theme_path / theme_path
|
||||
@ -502,7 +501,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
theme = Theme()
|
||||
theme.theme_name = UiStrings().Default
|
||||
self.save_theme(theme)
|
||||
self.settings.setValue(self.settings_section + '/global theme', theme.theme_name)
|
||||
self.settings.setValue('themes/global theme', theme.theme_name)
|
||||
new_themes = [theme.theme_name]
|
||||
if new_themes:
|
||||
self.update_preview_images(new_themes)
|
||||
@ -516,7 +515,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
"""
|
||||
self._theme_list.clear()
|
||||
self.theme_list_widget.clear()
|
||||
files = AppLocation.get_files(self.settings_section, '/*.json')
|
||||
files = AppLocation.get_files('themes', '/*.json')
|
||||
# Sort the themes by its name considering language specific
|
||||
files.sort(key=lambda file_name: get_locale_key(str(file_name)))
|
||||
# now process the file list of png files
|
||||
@ -788,7 +787,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
|
||||
:param confirm: Do we display a confirm box before run checks.
|
||||
:return: True or False depending on the validity.
|
||||
"""
|
||||
self.global_theme = self.settings.value(self.settings_section + '/global theme')
|
||||
self.global_theme = self.settings.value('themes/global theme')
|
||||
if check_item_selected(self.theme_list_widget, select_text):
|
||||
item = self.theme_list_widget.currentItem()
|
||||
theme = item.text()
|
||||
|
@ -202,7 +202,7 @@ class ThemesTab(SettingsTab):
|
||||
['Bible Theme', 'Song Theme']
|
||||
"""
|
||||
# Reload as may have been triggered by the ThemeManager.
|
||||
self.global_theme = self.settings.value(self.settings_section + '/global theme')
|
||||
self.global_theme = self.settings.value('themes/global theme')
|
||||
self.default_combo_box.clear()
|
||||
self.default_combo_box.addItems(theme_list)
|
||||
find_and_set_in_combo_box(self.default_combo_box, self.global_theme)
|
||||
|
@ -113,7 +113,7 @@ def state_media(state):
|
||||
|
||||
|
||||
@pytest.yield_fixture()
|
||||
def tmp_folder():
|
||||
def temp_folder():
|
||||
t_folder = mkdtemp(prefix='openlp_')
|
||||
yield t_folder
|
||||
shutil.rmtree(t_folder, ignore_errors=True)
|
||||
|
@ -50,7 +50,7 @@ def test_service_set_calls_service_manager(flask_client, settings):
|
||||
Registry().register('service_manager', fake_service_manager)
|
||||
res = flask_client.post('/api/v2/service/show', json=dict(id=400))
|
||||
assert res.status_code == 204
|
||||
fake_service_manager.set_item.assert_called_once_with(400)
|
||||
fake_service_manager.servicemanager_set_item.emit.assert_called_once_with(400)
|
||||
|
||||
|
||||
def test_service_direction_requires_login(flask_client, settings):
|
||||
|
@ -146,12 +146,12 @@ def test_delete_database_with_db_file_name():
|
||||
assert result is False, 'The result of delete_file should be False (was rigged that way)'
|
||||
|
||||
|
||||
def test_skip_db_upgrade_with_no_database(tmp_folder):
|
||||
def test_skip_db_upgrade_with_no_database(temp_folder):
|
||||
"""
|
||||
Test the upgrade_db function does not try to update a missing database
|
||||
"""
|
||||
# GIVEN: Database URL that does not (yet) exist
|
||||
url = 'sqlite:///{tmp}/test_db.sqlite'.format(tmp=tmp_folder)
|
||||
url = 'sqlite:///{tmp}/test_db.sqlite'.format(tmp=temp_folder)
|
||||
mocked_upgrade = MagicMock()
|
||||
|
||||
# WHEN: We attempt to upgrade a non-existent database
|
||||
|
@ -23,7 +23,6 @@ Package to test the openlp.core.ui.thememanager package.
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from tempfile import mkdtemp
|
||||
from unittest.mock import ANY, Mock, MagicMock, patch, call
|
||||
@ -35,13 +34,6 @@ from openlp.core.ui.thememanager import ThemeManager
|
||||
from tests.utils.constants import RESOURCE_PATH
|
||||
|
||||
|
||||
@pytest.yield_fixture()
|
||||
def temp_folder():
|
||||
tmp_folder = mkdtemp()
|
||||
yield tmp_folder
|
||||
shutil.rmtree(tmp_folder)
|
||||
|
||||
|
||||
@patch('openlp.core.ui.thememanager.zipfile.ZipFile.__init__')
|
||||
@patch('openlp.core.ui.thememanager.zipfile.ZipFile.write')
|
||||
def test_export_theme(mocked_zipfile_write, mocked_zipfile_init, registry):
|
||||
|
@ -22,9 +22,7 @@
|
||||
For the Presentation tests
|
||||
"""
|
||||
import pytest
|
||||
import shutil
|
||||
from unittest.mock import MagicMock, patch
|
||||
from tempfile import mkdtemp
|
||||
|
||||
from openlp.core.common.registry import Registry
|
||||
from openlp.plugins.presentations.lib.mediaitem import PresentationMediaItem
|
||||
@ -43,9 +41,7 @@ def media_item(settings):
|
||||
|
||||
|
||||
@pytest.yield_fixture()
|
||||
def mock_plugin():
|
||||
def mock_plugin(temp_folder):
|
||||
m_plugin = MagicMock()
|
||||
temp_folder = mkdtemp()
|
||||
m_plugin.settings_section = temp_folder
|
||||
yield m_plugin
|
||||
shutil.rmtree(temp_folder)
|
||||
|
@ -21,10 +21,8 @@
|
||||
"""
|
||||
This module contains tests for the db submodule of the Songs plugin.
|
||||
"""
|
||||
import pytest
|
||||
import os
|
||||
import shutil
|
||||
from tempfile import mkdtemp
|
||||
|
||||
from openlp.core.lib.db import upgrade_db
|
||||
from openlp.plugins.songs.lib import upgrade
|
||||
@ -32,13 +30,6 @@ from openlp.plugins.songs.lib.db import Author, AuthorType, Book, Song
|
||||
from tests.utils.constants import TEST_RESOURCES_PATH
|
||||
|
||||
|
||||
@pytest.yield_fixture()
|
||||
def tmp_folder():
|
||||
t_folder = mkdtemp()
|
||||
yield t_folder
|
||||
shutil.rmtree(t_folder, ignore_errors=True)
|
||||
|
||||
|
||||
def test_add_author():
|
||||
"""
|
||||
Test adding an author to a song
|
||||
@ -194,13 +185,13 @@ def test_add_songbooks():
|
||||
assert len(song.songbook_entries) == 2, 'There should be two Songbook entries.'
|
||||
|
||||
|
||||
def test_upgrade_old_song_db(settings, tmp_folder):
|
||||
def test_upgrade_old_song_db(settings, temp_folder):
|
||||
"""
|
||||
Test that we can upgrade an old song db to the current schema
|
||||
"""
|
||||
# GIVEN: An old song db
|
||||
old_db_path = os.path.join(TEST_RESOURCES_PATH, "songs", 'songs-1.9.7.sqlite')
|
||||
old_db_tmp_path = os.path.join(tmp_folder, 'songs-1.9.7.sqlite')
|
||||
old_db_tmp_path = os.path.join(temp_folder, 'songs-1.9.7.sqlite')
|
||||
shutil.copyfile(old_db_path, old_db_tmp_path)
|
||||
db_url = 'sqlite:///' + old_db_tmp_path
|
||||
|
||||
@ -211,13 +202,13 @@ def test_upgrade_old_song_db(settings, tmp_folder):
|
||||
assert updated_to_version == latest_version, 'The song DB should have been upgrade to the latest version'
|
||||
|
||||
|
||||
def test_upgrade_invalid_song_db(settings, tmp_folder):
|
||||
def test_upgrade_invalid_song_db(settings, temp_folder):
|
||||
"""
|
||||
Test that we can upgrade an invalid song db to the current schema
|
||||
"""
|
||||
# GIVEN: A song db with invalid version
|
||||
invalid_db_path = os.path.join(TEST_RESOURCES_PATH, "songs", 'songs-2.2-invalid.sqlite')
|
||||
invalid_db_tmp_path = os.path.join(tmp_folder, 'songs-2.2-invalid.sqlite')
|
||||
invalid_db_tmp_path = os.path.join(temp_folder, 'songs-2.2-invalid.sqlite')
|
||||
shutil.copyfile(invalid_db_path, invalid_db_tmp_path)
|
||||
db_url = 'sqlite:///' + invalid_db_tmp_path
|
||||
|
||||
|
@ -85,13 +85,13 @@ def add_records(projector_db, test):
|
||||
return added
|
||||
|
||||
|
||||
def test_upgrade_old_projector_db(tmp_folder):
|
||||
def test_upgrade_old_projector_db(temp_folder):
|
||||
"""
|
||||
Test that we can upgrade a version 1 db to the current schema
|
||||
"""
|
||||
# GIVEN: An old prjector db
|
||||
old_db = os.path.join(TEST_RESOURCES_PATH, "projector", TEST_DB_PJLINK1)
|
||||
tmp_db = os.path.join(tmp_folder, TEST_DB)
|
||||
tmp_db = os.path.join(temp_folder, TEST_DB)
|
||||
shutil.copyfile(old_db, tmp_db)
|
||||
db_url = 'sqlite:///{db}'.format(db=tmp_db)
|
||||
|
||||
@ -103,11 +103,11 @@ def test_upgrade_old_projector_db(tmp_folder):
|
||||
|
||||
|
||||
@pytest.yield_fixture()
|
||||
def projector(tmp_folder, settings):
|
||||
def projector(temp_folder, settings):
|
||||
"""
|
||||
Set up anything necessary for all tests
|
||||
"""
|
||||
tmpdb_url = 'sqlite:///{db}'.format(db=os.path.join(tmp_folder, TEST_DB))
|
||||
tmpdb_url = 'sqlite:///{db}'.format(db=os.path.join(temp_folder, TEST_DB))
|
||||
with patch('openlp.core.projectors.db.init_url') as mocked_init_url:
|
||||
mocked_init_url.return_value = tmpdb_url
|
||||
proj = ProjectorDB()
|
||||
|
Loading…
Reference in New Issue
Block a user