Migrate Media and add Pytest-qt

Signed-off-by: Tim <tim.bentley@gmail.com>
This commit is contained in:
Tim Bentley 2020-02-09 20:24:05 +00:00
parent 15d1198ae9
commit 3dcac055be
40 changed files with 417 additions and 541 deletions

View File

@ -97,16 +97,16 @@ class OpenLP(QtCore.QObject, LogMixin):
# Decide how many screens we have and their size
screens = ScreenList.create(QtWidgets.QApplication.desktop())
# First time checks in settings
has_run_wizard = Settings().value('core/has run wizard')
has_run_wizard = self.settings.value('core/has run wizard')
if not has_run_wizard:
ftw = FirstTimeForm()
ftw.initialize(screens)
if ftw.exec() == QtWidgets.QDialog.Accepted:
Settings().setValue('core/has run wizard', True)
self.settings.setValue('core/has run wizard', True)
else:
QtCore.QCoreApplication.exit()
sys.exit()
can_show_splash = Settings().value('core/show splash')
can_show_splash = self.settings.value('core/show splash')
if can_show_splash:
self.splash = SplashScreen()
self.splash.show()
@ -138,7 +138,7 @@ class OpenLP(QtCore.QObject, LogMixin):
QtWidgets.QApplication.processEvents()
if not has_run_wizard:
self.main_window.first_time()
if Settings().value('core/update check'):
if self.settings.value('core/update check'):
check_for_update(self.main_window)
self.main_window.is_display_blank()
Registry().execute('bootstrap_completion')
@ -152,8 +152,7 @@ class OpenLP(QtCore.QObject, LogMixin):
QtWidgets.QMessageBox.critical(None, UiStrings().Error, UiStrings().OpenLPStart,
QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok))
@staticmethod
def is_data_path_missing():
def is_data_path_missing(self):
"""
Check if the data folder path exists.
"""
@ -176,7 +175,7 @@ class OpenLP(QtCore.QObject, LogMixin):
log.info('User requested termination')
return True
# If answer was "Yes", remove the custom data path thus resetting the default location.
Settings().remove('advanced/data path')
self.settings.remove('advanced/data path')
log.info('Database location has been reset to the default settings.')
return False
@ -210,11 +209,11 @@ class OpenLP(QtCore.QObject, LogMixin):
:param has_run_wizard: OpenLP has been run before
:param can_show_splash: Should OpenLP show the splash screen
"""
data_version = Settings().value('core/application version')
data_version = self.settings.value('core/application version')
openlp_version = get_version()['version']
# New installation, no need to create backup
if not has_run_wizard:
Settings().setValue('core/application version', openlp_version)
self.settings.setValue('core/application version', openlp_version)
# If data_version is different from the current version ask if we should backup the data folder
elif data_version != openlp_version:
if can_show_splash and self.splash.isVisible():
@ -239,7 +238,7 @@ class OpenLP(QtCore.QObject, LogMixin):
QtWidgets.QMessageBox.information(None, translate('OpenLP', 'Backup'), message)
# Update the version in the settings
Settings().setValue('core/application version', openlp_version)
self.settings.setValue('core/application version', openlp_version)
if can_show_splash:
self.splash.show()
@ -373,11 +372,12 @@ def main():
app = OpenLP()
# Initialise the Registry
Registry.create()
settings = Settings()
Registry().register('application-qt', application)
Registry().register('application', app)
Registry().set_flag('no_web_server', args.no_web_server)
# Upgrade settings.
settings = Settings()
# Create and install settings.
app.settings = settings
Registry().register('settings', settings)
application.setApplicationVersion(get_version()['version'])
# Check if an instance of OpenLP is already running. Quit if there is a running instance and the user only wants one

View File

@ -26,7 +26,7 @@ import logging
from PyQt5 import QtCore, QtGui, QtWidgets
from openlp.core.common.settings import Settings
from openlp.core.common.registry import Registry
log = logging.getLogger(__name__)
@ -243,7 +243,7 @@ class ActionList(object):
"""
if category not in self.categories:
self.categories.append(category)
settings = Settings()
settings = Registry().get('settings')
settings.beginGroup('shortcuts')
# Get the default shortcut from the config.
action.default_shortcuts = settings.get_default_value(action.objectName())

View File

@ -40,7 +40,7 @@ from openlp.core.common import delete_file
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import translate
from openlp.core.common.json import OpenLPJSONDecoder, OpenLPJSONEncoder
from openlp.core.common.settings import Settings
from openlp.core.common.registry import Registry
from openlp.core.lib.ui import critical_error_message_box
@ -169,7 +169,7 @@ def init_url(plugin_name, db_file_name=None):
:return: The database URL
:rtype: str
"""
settings = Settings()
settings = Registry().get('settings')
settings.beginGroup(plugin_name)
db_type = settings.value('db type')
if db_type == 'sqlite':

View File

@ -29,7 +29,6 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from openlp.core.common import SlideLimits
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings, format_time, translate
from openlp.core.common.settings import Settings
from openlp.core.lib.settingstab import SettingsTab
from openlp.core.ui.icons import UiIcons
from openlp.core.ui.style import HAS_DARK_STYLE
@ -336,48 +335,47 @@ class AdvancedTab(SettingsTab):
def load(self):
"""
Load settings from disk.
Load self.settings from disk.
"""
settings = Settings()
settings.beginGroup(self.settings_section)
self.settings.beginGroup(self.settings_section)
# The max recent files value does not have an interface and so never
# gets actually stored in the settings therefore the default value of
# 20 will always be used.
self.recent_spin_box.setMaximum(settings.value('max recent files'))
self.recent_spin_box.setValue(settings.value('recent file count'))
self.media_plugin_check_box.setChecked(settings.value('save current plugin'))
self.double_click_live_check_box.setChecked(settings.value('double click live'))
self.single_click_preview_check_box.setChecked(settings.value('single click preview'))
self.single_click_service_preview_check_box.setChecked(settings.value('single click service preview'))
self.expand_service_item_check_box.setChecked(settings.value('expand service item'))
slide_max_height_value = settings.value('slide max height')
self.recent_spin_box.setMaximum(self.settings.value('max recent files'))
self.recent_spin_box.setValue(self.settings.value('recent file count'))
self.media_plugin_check_box.setChecked(self.settings.value('save current plugin'))
self.double_click_live_check_box.setChecked(self.settings.value('double click live'))
self.single_click_preview_check_box.setChecked(self.settings.value('single click preview'))
self.single_click_service_preview_check_box.setChecked(self.settings.value('single click service preview'))
self.expand_service_item_check_box.setChecked(self.settings.value('expand service item'))
slide_max_height_value = self.settings.value('slide max height')
for i in range(0, self.slide_max_height_combo_box.count()):
if self.slide_max_height_combo_box.itemData(i) == slide_max_height_value:
self.slide_max_height_combo_box.setCurrentIndex(i)
autoscroll_value = settings.value('autoscrolling')
autoscroll_value = self.settings.value('autoscrolling')
for i in range(0, len(self.autoscroll_map)):
if self.autoscroll_map[i] == autoscroll_value and i < self.autoscroll_combo_box.count():
self.autoscroll_combo_box.setCurrentIndex(i)
self.enable_auto_close_check_box.setChecked(settings.value('enable exit confirmation'))
self.enable_auto_close_check_box.setChecked(self.settings.value('enable exit confirmation'))
if HAS_DARK_STYLE:
self.use_dark_style_checkbox.setChecked(settings.value('use_dark_style'))
self.hide_mouse_check_box.setChecked(settings.value('hide mouse'))
self.service_name_day.setCurrentIndex(settings.value('default service day'))
self.service_name_time.setTime(QtCore.QTime(settings.value('default service hour'),
settings.value('default service minute')))
self.use_dark_style_checkbox.setChecked(self.settings.value('use_dark_style'))
self.hide_mouse_check_box.setChecked(self.settings.value('hide mouse'))
self.service_name_day.setCurrentIndex(self.settings.value('default service day'))
self.service_name_time.setTime(QtCore.QTime(self.settings.value('default service hour'),
self.settings.value('default service minute')))
self.should_update_service_name_example = True
self.service_name_edit.setText(settings.value('default service name'))
default_service_enabled = settings.value('default service enabled')
self.service_name_edit.setText(self.settings.value('default service name'))
default_service_enabled = self.settings.value('default service enabled')
self.service_name_check_box.setChecked(default_service_enabled)
self.service_name_check_box_toggled(default_service_enabled)
self.ignore_aspect_ratio_check_box.setChecked(settings.value('ignore aspect ratio'))
self.x11_bypass_check_box.setChecked(settings.value('x11 bypass wm'))
self.slide_limits = settings.value('slide limits')
self.is_search_as_you_type_enabled = settings.value('search as type')
self.ignore_aspect_ratio_check_box.setChecked(self.settings.value('ignore aspect ratio'))
self.x11_bypass_check_box.setChecked(self.settings.value('x11 bypass wm'))
self.slide_limits = self.settings.value('slide limits')
self.is_search_as_you_type_enabled = self.settings.value('search as type')
self.search_as_type_check_box.setChecked(self.is_search_as_you_type_enabled)
# Prevent the dialog displayed by the alternate_rows_check_box to display.
self.alternate_rows_check_box.blockSignals(True)
self.alternate_rows_check_box.setChecked(settings.value('alternate rows'))
self.alternate_rows_check_box.setChecked(self.settings.value('alternate rows'))
self.alternate_rows_check_box.blockSignals(False)
if self.slide_limits == SlideLimits.End:
self.end_slide_radio_button.setChecked(True)
@ -385,56 +383,55 @@ class AdvancedTab(SettingsTab):
self.wrap_slide_radio_button.setChecked(True)
else:
self.next_item_radio_button.setChecked(True)
settings.endGroup()
self.settings.endGroup()
self.data_directory_copy_check_box.hide()
self.new_data_directory_has_files_label.hide()
self.data_directory_cancel_button.hide()
# Since data location can be changed, make sure the path is present.
self.data_directory_path_edit.path = AppLocation.get_data_path()
# Don't allow data directory move if running portable.
if settings.value('advanced/is portable'):
if self.settings.value('advanced/is portable'):
self.data_directory_group_box.hide()
def save(self):
"""
Save settings to disk.
Save self.settings to disk.
"""
settings = Settings()
settings.beginGroup(self.settings_section)
settings.setValue('default service enabled', self.service_name_check_box.isChecked())
self.settings.beginGroup(self.settings_section)
self.settings.setValue('default service enabled', self.service_name_check_box.isChecked())
service_name = self.service_name_edit.text()
preset_is_valid = self.generate_service_name_example()[0]
if service_name == UiStrings().DefaultServiceName or not preset_is_valid:
settings.remove('default service name')
self.settings.remove('default service name')
self.service_name_edit.setText(service_name)
else:
settings.setValue('default service name', service_name)
settings.setValue('default service day', self.service_name_day.currentIndex())
settings.setValue('default service hour', self.service_name_time.time().hour())
settings.setValue('default service minute', self.service_name_time.time().minute())
settings.setValue('recent file count', self.recent_spin_box.value())
settings.setValue('save current plugin', self.media_plugin_check_box.isChecked())
settings.setValue('double click live', self.double_click_live_check_box.isChecked())
settings.setValue('single click preview', self.single_click_preview_check_box.isChecked())
settings.setValue('single click service preview', self.single_click_service_preview_check_box.isChecked())
settings.setValue('expand service item', self.expand_service_item_check_box.isChecked())
self.settings.setValue('default service name', service_name)
self.settings.setValue('default service day', self.service_name_day.currentIndex())
self.settings.setValue('default service hour', self.service_name_time.time().hour())
self.settings.setValue('default service minute', self.service_name_time.time().minute())
self.settings.setValue('recent file count', self.recent_spin_box.value())
self.settings.setValue('save current plugin', self.media_plugin_check_box.isChecked())
self.settings.setValue('double click live', self.double_click_live_check_box.isChecked())
self.settings.setValue('single click preview', self.single_click_preview_check_box.isChecked())
self.settings.setValue('single click service preview', self.single_click_service_preview_check_box.isChecked())
self.settings.setValue('expand service item', self.expand_service_item_check_box.isChecked())
slide_max_height_index = self.slide_max_height_combo_box.currentIndex()
slide_max_height_value = self.slide_max_height_combo_box.itemData(slide_max_height_index)
settings.setValue('slide max height', slide_max_height_value)
settings.setValue('autoscrolling', self.autoscroll_map[self.autoscroll_combo_box.currentIndex()])
settings.setValue('enable exit confirmation', self.enable_auto_close_check_box.isChecked())
settings.setValue('hide mouse', self.hide_mouse_check_box.isChecked())
settings.setValue('alternate rows', self.alternate_rows_check_box.isChecked())
settings.setValue('slide limits', self.slide_limits)
settings.setValue('ignore aspect ratio', self.ignore_aspect_ratio_check_box.isChecked())
if self.x11_bypass_check_box.isChecked() != settings.value('x11 bypass wm'):
settings.setValue('x11 bypass wm', self.x11_bypass_check_box.isChecked())
self.settings.setValue('slide max height', slide_max_height_value)
self.settings.setValue('autoscrolling', self.autoscroll_map[self.autoscroll_combo_box.currentIndex()])
self.settings.setValue('enable exit confirmation', self.enable_auto_close_check_box.isChecked())
self.settings.setValue('hide mouse', self.hide_mouse_check_box.isChecked())
self.settings.setValue('alternate rows', self.alternate_rows_check_box.isChecked())
self.settings.setValue('slide limits', self.slide_limits)
self.settings.setValue('ignore aspect ratio', self.ignore_aspect_ratio_check_box.isChecked())
if self.x11_bypass_check_box.isChecked() != self.settings.value('x11 bypass wm'):
self.settings.setValue('x11 bypass wm', self.x11_bypass_check_box.isChecked())
self.settings_form.register_post_process('config_screen_changed')
self.settings_form.register_post_process('slidecontroller_update_slide_limits')
settings.setValue('search as type', self.is_search_as_you_type_enabled)
self.settings.setValue('search as type', self.is_search_as_you_type_enabled)
if HAS_DARK_STYLE:
settings.setValue('use_dark_style', self.use_dark_style_checkbox.isChecked())
settings.endGroup()
self.settings.setValue('use_dark_style', self.use_dark_style_checkbox.isChecked())
self.settings.endGroup()
self.proxy_widget.save()
def on_search_as_type_check_box_changed(self, check_state):

View File

@ -31,7 +31,6 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from openlp.core.common import is_linux
from openlp.core.common.i18n import UiStrings, translate
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.settings import Settings
from openlp.core.ui.exceptiondialog import Ui_ExceptionDialog
from openlp.core.version import get_library_versions, get_version
from openlp.core.widgets.dialogs import FileDialog
@ -98,11 +97,11 @@ class ExceptionForm(QtWidgets.QDialog, Ui_ExceptionDialog, RegistryProperties):
file_path, filter_used = FileDialog.getSaveFileName(
self,
translate('OpenLP.ExceptionForm', 'Save Crash Report'),
Settings().value(self.settings_section + '/last directory'),
self.settings.value(self.settings_section + '/last directory'),
translate('OpenLP.ExceptionForm', 'Text files (*.txt *.log *.text)'))
if file_path is None:
break
Settings().setValue(self.settings_section + '/last directory', file_path.parent)
self.settings.setValue(self.settings_section + '/last directory', file_path.parent)
opts = self._create_report()
report_text = self.report_text.format(version=opts['version'], description=opts['description'],
traceback=opts['traceback'], libs=opts['libs'], system=opts['system'])
@ -169,7 +168,7 @@ class ExceptionForm(QtWidgets.QDialog, Ui_ExceptionDialog, RegistryProperties):
file_path, filter_used = \
FileDialog.getOpenFileName(self,
translate('ImagePlugin.ExceptionDialog', 'Select Attachment'),
Settings().value(self.settings_section + '/last directory'),
self.settings.value(self.settings_section + '/last directory'),
'{text} (*)'.format(text=UiStrings().AllFiles))
log.info('New files {file_path}'.format(file_path=file_path))
if file_path:

View File

@ -39,7 +39,6 @@ from openlp.core.common.i18n import translate
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.path import create_paths
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib import build_icon
from openlp.core.lib.plugin import PluginStatus
from openlp.core.lib.ui import critical_error_message_box
@ -235,7 +234,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
self.currentIdChanged.connect(self.on_current_id_changed)
Registry().register_function('config_screen_changed', self.screen_selection_widget.load)
# Check if this is a re-run of the wizard.
self.has_run_wizard = Settings().value('core/has run wizard')
self.has_run_wizard = self.settings.value('core/has run wizard')
create_paths(Path(gettempdir(), 'openlp'))
self.theme_combo_box.clear()
self.button(QtWidgets.QWizard.CustomButton1).setVisible(False)
@ -252,7 +251,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
# Add any existing themes to list.
self.theme_combo_box.insertSeparator(0)
self.theme_combo_box.addItems(sorted(self.theme_manager.get_theme_names()))
default_theme = Settings().value('themes/global theme')
default_theme = self.settings.value('themes/global theme')
# Pre-select the current default theme.
index = self.theme_combo_box.findText(default_theme)
self.theme_combo_box.setCurrentIndex(index)
@ -307,7 +306,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
self._set_plugin_status(self.alert_check_box, 'alerts/status')
self.screen_selection_widget.save()
if self.theme_combo_box.currentIndex() != -1:
Settings().setValue('themes/global theme', self.theme_combo_box.currentText())
self.settings.setValue('themes/global theme', self.theme_combo_box.currentText())
Registry().remove_function('config_screen_changed', self.screen_selection_widget.load)
super().accept()
@ -345,10 +344,10 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
def on_projectors_check_box_clicked(self):
# When clicking projectors_check box, change the visibility setting for Projectors panel.
if Settings().value('projector/show after wizard'):
Settings().setValue('projector/show after wizard', False)
if self.settings.value('projector/show after wizard'):
self.settings.setValue('projector/show after wizard', False)
else:
Settings().setValue('projector/show after wizard', True)
self.settings.setValue('projector/show after wizard', True)
def on_themes_list_widget_selection_changed(self):
"""
@ -538,4 +537,4 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
Set the status of a plugin.
"""
status = PluginStatus.Active if field.checkState() == QtCore.Qt.Checked else PluginStatus.Inactive
Settings().setValue(tag, status)
self.settings.setValue(tag, status)

View File

@ -28,7 +28,6 @@ from PyQt5 import QtGui, QtWidgets
from openlp.core.common import get_images_filter
from openlp.core.common.i18n import UiStrings, translate
from openlp.core.common.settings import Settings
from openlp.core.display.screens import ScreenList
from openlp.core.lib.settingstab import SettingsTab
from openlp.core.widgets.buttons import ColorButton
@ -191,48 +190,46 @@ class GeneralTab(SettingsTab):
"""
Load the settings to populate the form
"""
settings = Settings()
settings.beginGroup(self.settings_section)
self.number_edit.setText(settings.value('ccli number'))
self.username_edit.setText(settings.value('songselect username'))
self.password_edit.setText(settings.value('songselect password'))
self.save_check_service_check_box.setChecked(settings.value('save prompt'))
self.auto_unblank_check_box.setChecked(settings.value('auto unblank'))
self.click_live_slide_to_unblank_check_box.setChecked(settings.value('click live slide to unblank'))
self.warning_check_box.setChecked(settings.value('blank warning'))
self.auto_open_check_box.setChecked(settings.value('auto open'))
self.show_splash_check_box.setChecked(settings.value('show splash'))
self.logo_background_color = settings.value('logo background color')
self.logo_file_path_edit.path = settings.value('logo file')
self.logo_hide_on_startup_check_box.setChecked(settings.value('logo hide on startup'))
self.settings.beginGroup(self.settings_section)
self.number_edit.setText(self.settings.value('ccli number'))
self.username_edit.setText(self.settings.value('songselect username'))
self.password_edit.setText(self.settings.value('songselect password'))
self.save_check_service_check_box.setChecked(self.settings.value('save prompt'))
self.auto_unblank_check_box.setChecked(self.settings.value('auto unblank'))
self.click_live_slide_to_unblank_check_box.setChecked(self.settings.value('click live slide to unblank'))
self.warning_check_box.setChecked(self.settings.value('blank warning'))
self.auto_open_check_box.setChecked(self.settings.value('auto open'))
self.show_splash_check_box.setChecked(self.settings.value('show splash'))
self.logo_background_color = self.settings.value('logo background color')
self.logo_file_path_edit.path = self.settings.value('logo file')
self.logo_hide_on_startup_check_box.setChecked(self.settings.value('logo hide on startup'))
self.logo_color_button.color = self.logo_background_color
self.check_for_updates_check_box.setChecked(settings.value('update check'))
self.auto_preview_check_box.setChecked(settings.value('auto preview'))
self.timeout_spin_box.setValue(settings.value('loop delay'))
settings.endGroup()
self.check_for_updates_check_box.setChecked(self.settings.value('update check'))
self.auto_preview_check_box.setChecked(self.settings.value('auto preview'))
self.timeout_spin_box.setValue(self.settings.value('loop delay'))
self.settings.endGroup()
def save(self):
"""
Save the settings from the form
"""
settings = Settings()
settings.beginGroup(self.settings_section)
settings.setValue('blank warning', self.warning_check_box.isChecked())
settings.setValue('auto open', self.auto_open_check_box.isChecked())
settings.setValue('show splash', self.show_splash_check_box.isChecked())
settings.setValue('logo background color', self.logo_background_color)
settings.setValue('logo file', self.logo_file_path_edit.path)
settings.setValue('logo hide on startup', self.logo_hide_on_startup_check_box.isChecked())
settings.setValue('update check', self.check_for_updates_check_box.isChecked())
settings.setValue('save prompt', self.save_check_service_check_box.isChecked())
settings.setValue('auto unblank', self.auto_unblank_check_box.isChecked())
settings.setValue('click live slide to unblank', self.click_live_slide_to_unblank_check_box.isChecked())
settings.setValue('auto preview', self.auto_preview_check_box.isChecked())
settings.setValue('loop delay', self.timeout_spin_box.value())
settings.setValue('ccli number', self.number_edit.displayText())
settings.setValue('songselect username', self.username_edit.displayText())
settings.setValue('songselect password', self.password_edit.displayText())
settings.endGroup()
self.settings.beginGroup(self.settings_section)
self.settings.setValue('blank warning', self.warning_check_box.isChecked())
self.settings.setValue('auto open', self.auto_open_check_box.isChecked())
self.settings.setValue('show splash', self.show_splash_check_box.isChecked())
self.settings.setValue('logo background color', self.logo_background_color)
self.settings.setValue('logo file', self.logo_file_path_edit.path)
self.settings.setValue('logo hide on startup', self.logo_hide_on_startup_check_box.isChecked())
self.settings.setValue('update check', self.check_for_updates_check_box.isChecked())
self.settings.setValue('save prompt', self.save_check_service_check_box.isChecked())
self.settings.setValue('auto unblank', self.auto_unblank_check_box.isChecked())
self.settings.setValue('click live slide to unblank', self.click_live_slide_to_unblank_check_box.isChecked())
self.settings.setValue('auto preview', self.auto_preview_check_box.isChecked())
self.settings.setValue('loop delay', self.timeout_spin_box.value())
self.settings.setValue('ccli number', self.number_edit.displayText())
self.settings.setValue('songselect username', self.username_edit.displayText())
self.settings.setValue('songselect password', self.password_edit.displayText())
self.settings.endGroup()
self.post_set_up()
def post_set_up(self):

View File

@ -28,7 +28,7 @@ from PyQt5 import QtGui, QtWidgets
from openlp.core.common import Singleton
from openlp.core.common.applocation import AppLocation
from openlp.core.common.settings import Settings
from openlp.core.common.registry import Registry
from openlp.core.lib import build_icon
from openlp.core.ui.style import HAS_DARK_STYLE
@ -167,7 +167,7 @@ class UiIcons(metaclass=Singleton):
"""
Load the list of icons to be processed
"""
is_dark = (HAS_DARK_STYLE and Settings().value('advanced/use_dark_style'))
is_dark = (HAS_DARK_STYLE and Registry().get('settings').value('advanced/use_dark_style'))
for key in icon_list:
try:
icon = icon_list[key]['icon']

View File

@ -88,9 +88,9 @@ class Ui_MainWindow(object):
self.control_splitter.setOrientation(QtCore.Qt.Horizontal)
self.control_splitter.setObjectName('control_splitter')
self.main_content_layout.addWidget(self.control_splitter)
preview_visible = Settings().value('user interface/preview panel')
live_visible = Settings().value('user interface/live panel')
panel_locked = Settings().value('user interface/lock panel')
preview_visible = self.settings.value('user interface/preview panel')
live_visible = self.settings.value('user interface/live panel')
panel_locked = self.settings.value('user interface/lock panel')
# Create menu
self.menu_bar = QtWidgets.QMenuBar(main_window)
self.menu_bar.setObjectName('menu_bar')
@ -493,7 +493,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
self.timer_id = 0
self.new_data_path = None
self.copy_data = False
Settings().set_up_default_values()
self.settings.set_up_default_values()
self.about_form = AboutForm(self)
self.ws_server = WebSocketServer()
self.http_server = HttpServer(self)
@ -586,8 +586,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
"""
process the bootstrap post setup request
"""
# self.preview_controller.panel.setVisible(Settings().value('user interface/preview panel'))
# self.live_controller.panel.setVisible(Settings().value('user interface/live panel'))
# self.preview_controller.panel.setVisible(self.settings.value('user interface/preview panel'))
# self.live_controller.panel.setVisible(self.settings.value('user interface/live panel'))
self.load_settings()
self.restore_current_media_manager_item()
Registry().execute('theme_update_global')
@ -597,8 +597,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
Called on start up to restore the last active media plugin.
"""
self.log_info('Load data from Settings')
if Settings().value('advanced/save current plugin'):
saved_plugin_id = Settings().value('advanced/current media plugin')
if self.settings.value('advanced/save current plugin'):
saved_plugin_id = self.settings.value('advanced/current media plugin')
if saved_plugin_id != -1:
self.media_tool_box.setCurrentIndex(saved_plugin_id)
@ -646,17 +646,17 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
# If not we need to see if we want to use the previous file.so count of 1
if self.application.args and len(self.application.args) > 1:
self.open_cmd_line_files(self.application.args)
elif Settings().value(self.general_settings_section + '/auto open'):
elif self.settings.value(self.general_settings_section + '/auto open'):
self.service_manager_contents.load_last_file()
# This will store currently used layout preset so it remains enabled on next startup.
# If any panel is enabled/disabled after preset is set, this setting is not saved.
view_mode = Settings().value('{section}/view mode'.format(section=self.general_settings_section))
if view_mode == 'default' and Settings().value('user interface/is preset layout'):
view_mode = self.settings.value('{section}/view mode'.format(section=self.general_settings_section))
if view_mode == 'default' and self.settings.value('user interface/is preset layout'):
self.mode_default_item.setChecked(True)
elif view_mode == 'setup' and Settings().value('user interface/is preset layout'):
elif view_mode == 'setup' and self.settings.value('user interface/is preset layout'):
self.set_view_mode(True, True, False, True, False, True)
self.mode_setup_item.setChecked(True)
elif view_mode == 'live' and Settings().value('user interface/is preset layout'):
elif view_mode == 'live' and self.settings.value('user interface/is preset layout'):
self.set_view_mode(False, True, False, False, True, True)
self.mode_live_item.setChecked(True)
@ -702,7 +702,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
self.application.set_busy_cursor()
self.first_time()
# Check if Projectors panel should be visible or not after wizard.
if Settings().value('projector/show after wizard'):
if self.settings.value('projector/show after wizard'):
self.projector_manager_dock.setVisible(True)
else:
self.projector_manager_dock.setVisible(False)
@ -726,10 +726,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
"""
Check and display message if screen blank on setup.
"""
settings = Settings()
self.live_controller.main_display_set_background()
if settings.value('{section}/screen blank'.format(section=self.general_settings_section)):
if settings.value('{section}/blank warning'.format(section=self.general_settings_section)):
if self.settings.value('{section}/screen blank'.format(section=self.general_settings_section)):
if self.settings.value('{section}/blank warning'.format(section=self.general_settings_section)):
QtWidgets.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Main Display Blanked'),
translate('OpenLP.MainWindow', 'The Main Display has been blanked out'))
@ -875,7 +874,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
create_paths(temp_dir_path)
temp_config_path = temp_dir_path / import_file_path.name
shutil.copyfile(import_file_path, temp_config_path)
settings = Settings()
import_settings = Settings(str(temp_config_path), Settings.IniFormat)
self.log_info('hook upgrade_plugin_settings')
@ -919,13 +917,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
self.log_warning('The key "{key}" does not exist (anymore), so it will be skipped.'.
format(key=section_key))
if value is not None:
settings.setValue('{key}'.format(key=section_key), value)
self.settings.setValue('{key}'.format(key=section_key), value)
now = datetime.now()
settings.beginGroup(self.header_section)
settings.setValue('file_imported', import_file_path)
settings.setValue('file_date_imported', now.strftime("%Y-%m-%d %H:%M"))
settings.endGroup()
settings.sync()
self.settings.beginGroup(self.header_section)
self.settings.setValue('file_imported', import_file_path)
self.settings.setValue('file_date_imported', now.strftime("%Y-%m-%d %H:%M"))
self.settings.endGroup()
self.settings.sync()
# We must do an immediate restart or current configuration will overwrite what was just imported when
# application terminates normally. We need to exit without saving configuration.
QtWidgets.QMessageBox.information(self, translate('OpenLP.MainWindow', 'Import settings'),
@ -951,7 +949,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
export_file_path = export_file_path.with_suffix('.conf')
self.save_settings()
try:
Settings().export(export_file_path)
self.settings.export(export_file_path)
except OSError as ose:
QtWidgets.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'Export setting error'),
translate('OpenLP.MainWindow',
@ -964,32 +962,31 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
Put OpenLP into "Default" view mode.
"""
self.set_view_mode(True, True, True, True, True, True, 'default')
Settings().setValue('user interface/is preset layout', True)
Settings().setValue('projector/show after wizard', True)
self.settings.setValue('user interface/is preset layout', True)
self.settings.setValue('projector/show after wizard', True)
def on_mode_setup_item_clicked(self):
"""
Put OpenLP into "Setup" view mode.
"""
self.set_view_mode(True, True, False, True, False, True, 'setup')
Settings().setValue('user interface/is preset layout', True)
Settings().setValue('projector/show after wizard', True)
self.settings.setValue('user interface/is preset layout', True)
self.settings.setValue('projector/show after wizard', True)
def on_mode_live_item_clicked(self):
"""
Put OpenLP into "Live" view mode.
"""
self.set_view_mode(False, True, False, False, True, True, 'live')
Settings().setValue('user interface/is preset layout', True)
Settings().setValue('projector/show after wizard', True)
self.settings.setValue('user interface/is preset layout', True)
self.settings.setValue('projector/show after wizard', True)
def set_view_mode(self, media=True, service=True, theme=True, preview=True, live=True, projector=True, mode=''):
"""
Set OpenLP to a different view mode.
"""
if mode:
settings = Settings()
settings.setValue('{section}/view mode'.format(section=self.general_settings_section), mode)
self.settings.setValue('{section}/view mode'.format(section=self.general_settings_section), mode)
self.media_manager_dock.setVisible(media)
self.service_manager_dock.setVisible(service)
self.theme_manager_dock.setVisible(theme)
@ -1032,7 +1029,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
else:
event.ignore()
else:
if Settings().value('advanced/enable exit confirmation'):
if self.settings.value('advanced/enable exit confirmation'):
msg_box = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Question,
translate('OpenLP.MainWindow', 'Exit OpenLP'),
translate('OpenLP.MainWindow', 'Are you sure you want to exit OpenLP?'),
@ -1082,8 +1079,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
:param save_settings: Switch to prevent saving settings. Defaults to **True**.
"""
if save_settings:
if Settings().value('advanced/save current plugin'):
Settings().setValue('advanced/current media plugin', self.media_tool_box.currentIndex())
if self.settings.value('advanced/save current plugin'):
self.settings.setValue('advanced/current media plugin', self.media_tool_box.currentIndex())
# Call the cleanup method to shutdown plugins.
self.log_info('cleanup plugins')
self.plugin_manager.finalise_plugins()
@ -1126,7 +1123,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
"""
Update the default theme indicator in the status bar
"""
theme_name = Settings().value('themes/global theme')
theme_name = self.settings.value('themes/global theme')
self.default_theme_label.setText(translate('OpenLP.MainWindow',
'Default Theme: {theme}').format(theme=theme_name))
@ -1135,33 +1132,33 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
Toggle the visibility of the media manager
"""
self.media_manager_dock.setVisible(not self.media_manager_dock.isVisible())
Settings().setValue('user interface/is preset layout', False)
self.settings.setValue('user interface/is preset layout', False)
def toggle_projector_manager(self):
"""
Toggle visibility of the projector manager
"""
self.projector_manager_dock.setVisible(not self.projector_manager_dock.isVisible())
Settings().setValue('user interface/is preset layout', False)
self.settings.setValue('user interface/is preset layout', False)
# Check/uncheck checkbox on First time wizard based on visibility of this panel.
if not Settings().value('projector/show after wizard'):
Settings().setValue('projector/show after wizard', True)
if not self.settings.value('projector/show after wizard'):
self.settings.setValue('projector/show after wizard', True)
else:
Settings().setValue('projector/show after wizard', False)
self.settings.setValue('projector/show after wizard', False)
def toggle_service_manager(self):
"""
Toggle the visibility of the service manager
"""
self.service_manager_dock.setVisible(not self.service_manager_dock.isVisible())
Settings().setValue('user interface/is preset layout', False)
self.settings.setValue('user interface/is preset layout', False)
def toggle_theme_manager(self):
"""
Toggle the visibility of the theme manager
"""
self.theme_manager_dock.setVisible(not self.theme_manager_dock.isVisible())
Settings().setValue('user interface/is preset layout', False)
self.settings.setValue('user interface/is preset layout', False)
def set_preview_panel_visibility(self, visible):
"""
@ -1173,9 +1170,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
"""
self.preview_controller.panel.setVisible(visible)
Settings().setValue('user interface/preview panel', visible)
self.settings.setValue('user interface/preview panel', visible)
self.view_preview_panel.setChecked(visible)
Settings().setValue('user interface/is preset layout', False)
self.settings.setValue('user interface/is preset layout', False)
def set_lock_panel(self, lock):
"""
@ -1205,7 +1202,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
self.view_projector_manager_item.setEnabled(True)
self.view_preview_panel.setEnabled(True)
self.view_live_panel.setEnabled(True)
Settings().setValue('user interface/lock panel', lock)
self.settings.setValue('user interface/lock panel', lock)
def set_live_panel_visibility(self, visible):
"""
@ -1217,32 +1214,31 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
False - Hidden
"""
self.live_controller.panel.setVisible(visible)
Settings().setValue('user interface/live panel', visible)
self.settings.setValue('user interface/live panel', visible)
self.view_live_panel.setChecked(visible)
Settings().setValue('user interface/is preset layout', False)
self.settings.setValue('user interface/is preset layout', False)
def load_settings(self):
"""
Load the main window settings.
"""
settings = Settings()
# Remove obsolete entries.
settings.remove('custom slide')
settings.remove('service')
settings.beginGroup(self.general_settings_section)
self.recent_files = settings.value('recent files')
settings.endGroup()
settings.beginGroup(self.ui_settings_section)
self.move(settings.value('main window position'))
self.restoreGeometry(settings.value('main window geometry'))
self.restoreState(settings.value('main window state'))
self.live_controller.splitter.restoreState(settings.value('live splitter geometry'))
self.preview_controller.splitter.restoreState(settings.value('preview splitter geometry'))
self.control_splitter.restoreState(settings.value('main window splitter geometry'))
self.settings.remove('custom slide')
self.settings.remove('service')
self.settings.beginGroup(self.general_settings_section)
self.recent_files = self.settings.value('recent files')
self.settings.endGroup()
self.settings.beginGroup(self.ui_settings_section)
self.move(self.settings.value('main window position'))
self.restoreGeometry(self.settings.value('main window geometry'))
self.restoreState(self.settings.value('main window state'))
self.live_controller.splitter.restoreState(self.settings.value('live splitter geometry'))
self.preview_controller.splitter.restoreState(self.settings.value('preview splitter geometry'))
self.control_splitter.restoreState(self.settings.value('main window splitter geometry'))
# This needs to be called after restoreState(), because saveState() also saves the "Collapsible" property
# which was True (by default) < OpenLP 2.1.
self.control_splitter.setChildrenCollapsible(False)
settings.endGroup()
self.settings.endGroup()
def save_settings(self):
"""
@ -1251,24 +1247,23 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
# Exit if we just did a settings import.
if self.settings_imported:
return
settings = Settings()
settings.beginGroup(self.general_settings_section)
settings.setValue('recent files', self.recent_files)
settings.endGroup()
settings.beginGroup(self.ui_settings_section)
settings.setValue('main window position', self.pos())
settings.setValue('main window state', self.saveState())
settings.setValue('main window geometry', self.saveGeometry())
settings.setValue('live splitter geometry', self.live_controller.splitter.saveState())
settings.setValue('preview splitter geometry', self.preview_controller.splitter.saveState())
settings.setValue('main window splitter geometry', self.control_splitter.saveState())
settings.endGroup()
self.settings.beginGroup(self.general_settings_section)
self.settings.setValue('recent files', self.recent_files)
self.settings.endGroup()
self.settings.beginGroup(self.ui_settings_section)
self.settings.setValue('main window position', self.pos())
self.settings.setValue('main window state', self.saveState())
self.settings.setValue('main window geometry', self.saveGeometry())
self.settings.setValue('live splitter geometry', self.live_controller.splitter.saveState())
self.settings.setValue('preview splitter geometry', self.preview_controller.splitter.saveState())
self.settings.setValue('main window splitter geometry', self.control_splitter.saveState())
self.settings.endGroup()
def update_recent_files_menu(self):
"""
Updates the recent file menu with the latest list of service files accessed.
"""
recent_file_count = Settings().value('advanced/recent file count')
recent_file_count = self.settings.value('advanced/recent file count')
self.recent_files_menu.clear()
count = 0
for recent_path in self.recent_files:
@ -1297,7 +1292,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
# The max_recent_files value does not have an interface and so never gets
# actually stored in the settings therefore the default value of 20 will
# always be used.
max_recent_files = Settings().value('advanced/max recent files')
max_recent_files = self.settings.value('advanced/max recent files')
file_path = Path(filename)
# Some cleanup to reduce duplication in the recent file list
file_path = file_path.resolve()

View File

@ -26,7 +26,6 @@ import logging
from PyQt5 import QtWidgets
from openlp.core.common.i18n import translate
from openlp.core.common.settings import Settings
from openlp.core.lib.settingstab import SettingsTab
from openlp.core.lib.ui import critical_error_message_box
from openlp.core.ui.icons import UiIcons
@ -88,17 +87,17 @@ class MediaTab(SettingsTab):
"""
Load the settings
"""
self.auto_start_check_box.setChecked(Settings().value(self.settings_section + '/media auto start'))
self.vlc_arguments_edit.setText(Settings().value(self.settings_section + '/vlc arguments'))
self.auto_start_check_box.setChecked(self.settings.value(self.settings_section + '/media auto start'))
self.vlc_arguments_edit.setText(self.settings.value(self.settings_section + '/vlc arguments'))
def save(self):
"""
Save the settings
"""
setting_key = self.settings_section + '/media auto start'
if Settings().value(setting_key) != self.auto_start_check_box.checkState():
Settings().setValue(setting_key, self.auto_start_check_box.checkState())
Settings().setValue(self.settings_section + '/vlc arguments', self.vlc_arguments_edit.text())
if self.settings.value(setting_key) != self.auto_start_check_box.checkState():
self.settings.setValue(setting_key, self.auto_start_check_box.checkState())
self.settings.setValue(self.settings_section + '/vlc arguments', self.vlc_arguments_edit.text())
def post_set_up(self, post_update=False):
"""

View File

@ -31,7 +31,6 @@ from openlp.core.common.applocation import AppLocation
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 get_text_file_string, image_to_byte
from openlp.core.ui.printservicedialog import Ui_PrintServiceDialog, ZoomSize
@ -135,16 +134,15 @@ class PrintServiceForm(QtWidgets.QDialog, Ui_PrintServiceDialog, RegistryPropert
self.zoom = 0
self.setup_ui(self)
# Load the settings for the dialog.
settings = Settings()
settings.beginGroup('advanced')
self.slide_text_check_box.setChecked(settings.value('print slide text'))
self.page_break_after_text.setChecked(settings.value('add page break'))
self.settings.beginGroup('advanced')
self.slide_text_check_box.setChecked(self.settings.value('print slide text'))
self.page_break_after_text.setChecked(self.settings.value('add page break'))
if not self.slide_text_check_box.isChecked():
self.page_break_after_text.setDisabled(True)
self.meta_data_check_box.setChecked(settings.value('print file meta data'))
self.notes_check_box.setChecked(settings.value('print notes'))
self.zoom_combo_box.setCurrentIndex(settings.value('display size'))
settings.endGroup()
self.meta_data_check_box.setChecked(self.settings.value('print file meta data'))
self.notes_check_box.setChecked(self.settings.value('print notes'))
self.zoom_combo_box.setCurrentIndex(self.settings.value('display size'))
self.settings.endGroup()
# Signals
self.print_button.triggered.connect(self.print_service_order)
self.zoom_out_button.clicked.connect(self.zoom_out)
@ -307,10 +305,9 @@ class PrintServiceForm(QtWidgets.QDialog, Ui_PrintServiceDialog, RegistryPropert
elif display == ZoomSize.TwentyFive:
self.preview_widget.fitToWidth()
self.preview_widget.zoomIn(0.25)
settings = Settings()
settings.beginGroup('advanced')
settings.setValue('display size', display)
settings.endGroup()
self.settings.beginGroup('advanced')
self.settings.setValue('display size', display)
self.settings.endGroup()
def copy_text(self):
"""
@ -392,16 +389,15 @@ class PrintServiceForm(QtWidgets.QDialog, Ui_PrintServiceDialog, RegistryPropert
def save_options(self):
"""
Save the settings and close the dialog.
Save the self.settings and close the dialog.
"""
# Save the settings for this dialog.
settings = Settings()
settings.beginGroup('advanced')
settings.setValue('print slide text', self.slide_text_check_box.isChecked())
settings.setValue('add page break', self.page_break_after_text.isChecked())
settings.setValue('print file meta data', self.meta_data_check_box.isChecked())
settings.setValue('print notes', self.notes_check_box.isChecked())
settings.endGroup()
# Save the self.settings for this dialog.
self.settings.beginGroup('advanced')
self.settings.setValue('print slide text', self.slide_text_check_box.isChecked())
self.settings.setValue('add page break', self.page_break_after_text.isChecked())
self.settings.setValue('print file meta data', self.meta_data_check_box.isChecked())
self.settings.setValue('print notes', self.notes_check_box.isChecked())
self.settings.endGroup()
def update_song_usage(self):
"""

View File

@ -24,7 +24,6 @@ The screen settings tab in the configuration dialog
from PyQt5 import QtWidgets
from openlp.core.common.i18n import translate
from openlp.core.common.settings import Settings
from openlp.core.display.screens import ScreenList
from openlp.core.lib.settingstab import SettingsTab
from openlp.core.common.registry import Registry
@ -81,13 +80,12 @@ class ScreensTab(SettingsTab):
"""
Load the settings to populate the tab
"""
Settings().beginGroup(self.settings_section)
self.screen_selection_widget.load()
# Load generic settings
self.display_on_monitor_check.setChecked(Settings().value('core/display on monitor'))
self.display_on_monitor_check.setChecked(self.settings.value('core/display on monitor'))
def save(self):
self.screen_selection_widget.save()
Settings().setValue('core/display on monitor', self.display_on_monitor_check.isChecked())
self.settings.setValue('core/display on monitor', self.display_on_monitor_check.isChecked())
# On save update the screens as well
self.settings_form.register_post_process('config_screen_changed')

View File

@ -42,7 +42,6 @@ from openlp.core.common.i18n import UiStrings, format_time, translate
from openlp.core.common.json import OpenLPJSONDecoder, OpenLPJSONEncoder
from openlp.core.common.mixins import LogMixin, RegistryProperties
from openlp.core.common.registry import Registry, RegistryBase
from openlp.core.common.settings import Settings
from openlp.core.lib import build_icon
from openlp.core.lib.exceptions import ValidationError
from openlp.core.lib.plugin import PluginStatus
@ -235,7 +234,7 @@ class Ui_ServiceManager(object):
self.service_manager_list.itemCollapsed.connect(self.collapsed)
self.service_manager_list.itemExpanded.connect(self.expanded)
# Last little bits of setting up
self.service_theme = Settings().value(self.main_window.service_manager_settings_section + '/service theme')
self.service_theme = self.settings.value(self.main_window.service_manager_settings_section + '/service theme')
self.service_path = AppLocation.get_section_data_path('servicemanager')
# build the drag and drop context menu
self.dnd_menu = QtWidgets.QMenu()
@ -387,7 +386,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
"""
self._service_path = file_path
self.set_modified(self.is_modified())
Settings().setValue('servicemanager/last file', file_path)
self.settings.setValue('servicemanager/last file', file_path)
if file_path and file_path.suffix == '.oszl':
self._save_lite = True
else:
@ -463,11 +462,11 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
file_path, filter_used = FileDialog.getOpenFileName(
self.main_window,
translate('OpenLP.ServiceManager', 'Open File'),
Settings().value(self.main_window.service_manager_settings_section + '/last directory'),
self.settings.value(self.main_window.service_manager_settings_section + '/last directory'),
translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz *.oszl)'))
if not file_path:
return False
Settings().setValue(self.main_window.service_manager_settings_section + '/last directory', file_path.parent)
self.settings.setValue(self.main_window.service_manager_settings_section + '/last directory', file_path.parent)
self.load_file(file_path)
def save_modified_service(self):
@ -506,7 +505,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
self.set_file_name(None)
self.service_id += 1
self.set_modified(False)
Settings().setValue('servicemanager/last file', None)
self.settings.setValue('servicemanager/last file', None)
self.plugin_manager.new_service_created()
def create_basic_service(self):
@ -611,7 +610,8 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
with suppress(FileNotFoundError):
file_path.unlink()
os.link(temp_file.name, file_path)
Settings().setValue(self.main_window.service_manager_settings_section + '/last directory', file_path.parent)
self.settings.setValue(self.main_window.service_manager_settings_section + '/last directory',
file_path.parent)
except (PermissionError, OSError) as error:
self.log_exception('Failed to save service to disk: {name}'.format(name=file_path))
self.main_window.error_message(
@ -629,26 +629,26 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
"""
Get a file name and then call :func:`ServiceManager.save_file` to save the file.
"""
default_service_enabled = Settings().value('advanced/default service enabled')
default_service_enabled = self.settings.value('advanced/default service enabled')
if default_service_enabled:
service_day = Settings().value('advanced/default service day')
service_day = self.settings.value('advanced/default service day')
if service_day == 7:
local_time = datetime.now()
else:
service_hour = Settings().value('advanced/default service hour')
service_minute = Settings().value('advanced/default service minute')
service_hour = self.settings.value('advanced/default service hour')
service_minute = self.settings.value('advanced/default service minute')
now = datetime.now()
day_delta = service_day - now.weekday()
if day_delta < 0:
day_delta += 7
time = now + timedelta(days=day_delta)
local_time = time.replace(hour=service_hour, minute=service_minute)
default_pattern = Settings().value('advanced/default service name')
default_pattern = self.settings.value('advanced/default service name')
default_file_name = format_time(default_pattern, local_time)
else:
default_file_name = ''
default_file_path = Path(default_file_name)
directory_path = Settings().value(self.main_window.service_manager_settings_section + '/last directory')
directory_path = self.settings.value(self.main_window.service_manager_settings_section + '/last directory')
if directory_path:
default_file_path = directory_path / default_file_path
lite_filter = translate('OpenLP.ServiceManager', 'OpenLP Service Files - lite (*.oszl)')
@ -718,7 +718,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
self.set_file_name(file_path)
self.main_window.add_recent_file(file_path)
self.set_modified(False)
Settings().setValue('servicemanager/last file', file_path)
self.settings.setValue('servicemanager/last file', file_path)
else:
raise ValidationError(msg='No service data found')
except (NameError, OSError, ValidationError, zipfile.BadZipFile):
@ -767,7 +767,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
Load the last service item from the service manager when the service was last closed. Can be blank if there was
no service present.
"""
file_path = Settings().value('servicemanager/last file')
file_path = self.settings.value('servicemanager/last file')
if file_path:
self.load_file(file_path)
@ -875,7 +875,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
service_item.auto_play_slides_loop = False
self.auto_play_slides_loop.setChecked(False)
if service_item.auto_play_slides_once and service_item.timed_slide_interval == 0:
service_item.timed_slide_interval = Settings().value(
service_item.timed_slide_interval = self.settings.value(
self.main_window.general_settings_section + '/loop delay')
self.set_modified()
@ -890,7 +890,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
service_item.auto_play_slides_once = False
self.auto_play_slides_once.setChecked(False)
if service_item.auto_play_slides_loop and service_item.timed_slide_interval == 0:
service_item.timed_slide_interval = Settings().value(
service_item.timed_slide_interval = self.settings.value(
self.main_window.general_settings_section + '/loop delay')
self.set_modified()
@ -901,7 +901,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
item = self.find_service_item()[0]
service_item = self.service_items[item]['service_item']
if service_item.timed_slide_interval == 0:
timed_slide_interval = Settings().value(self.main_window.general_settings_section + '/loop delay')
timed_slide_interval = self.settings.value(self.main_window.general_settings_section + '/loop delay')
else:
timed_slide_interval = service_item.timed_slide_interval
timed_slide_interval, ok = QtWidgets.QInputDialog.getInt(self, translate('OpenLP.ServiceManager',
@ -1272,7 +1272,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()
Settings().setValue(self.main_window.service_manager_settings_section + '/service theme', self.service_theme)
self.settings.setValue(self.main_window.service_manager_settings_section + '/service theme', self.service_theme)
self.regenerate_service_items(True)
def theme_change(self):
@ -1352,7 +1352,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
"""
# if not passed set to config value
if expand is None:
expand = Settings().value('advanced/expand service item')
expand = self.settings.value('advanced/expand service item')
item.from_service = True
if position != -1:
self.drop_position = position
@ -1424,7 +1424,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
If single click previewing is enabled, and triggered by a tablewidget click event,
start a timeout to verify a double-click hasn't triggered.
"""
if Settings().value('advanced/single click service preview'):
if self.settings.value('advanced/single click service preview'):
if not self.list_double_clicked:
# If a double click has not registered start a timer, otherwise wait for the existing timer to finish.
QtCore.QTimer.singleShot(QtWidgets.QApplication.instance().doubleClickInterval(),
@ -1456,7 +1456,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
self.application.set_busy_cursor()
if self.service_items[item]['service_item'].is_valid:
self.live_controller.add_service_manager_item(self.service_items[item]['service_item'], child)
if Settings().value(self.main_window.general_settings_section + '/auto preview'):
if self.settings.value(self.main_window.general_settings_section + '/auto preview'):
item += 1
if self.service_items and item < len(self.service_items) and \
self.service_items[item]['service_item'].is_capable(ItemCapabilities.CanPreview):

View File

@ -29,7 +29,6 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from openlp.core.common.actions import ActionList
from openlp.core.common.i18n import translate
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.settings import Settings
from openlp.core.ui.shortcutlistdialog import Ui_ShortcutListDialog
@ -346,8 +345,7 @@ class ShortcutListForm(QtWidgets.QDialog, Ui_ShortcutListDialog, RegistryPropert
Save the shortcuts. **Note**, that we do not have to load the shortcuts, as they are loaded in
:class:`~openlp.core.utils.ActionList`.
"""
settings = Settings()
settings.beginGroup('shortcuts')
self.settings.beginGroup('shortcuts')
for category in self.action_list.categories:
# Check if the category is for internal use only.
if category.name is None:
@ -357,8 +355,8 @@ class ShortcutListForm(QtWidgets.QDialog, Ui_ShortcutListDialog, RegistryPropert
old_shortcuts = list(map(self.get_shortcut_string, action.shortcuts()))
action.setShortcuts(self.changed_actions[action])
self.action_list.update_shortcut_map(action, old_shortcuts)
settings.setValue(action.objectName(), action.shortcuts())
settings.endGroup()
self.settings.setValue(action.objectName(), action.shortcuts())
self.settings.endGroup()
def on_clear_primary_button_clicked(self, toggled):
"""

View File

@ -24,7 +24,7 @@ The :mod:`~openlp.core.ui.dark` module looks for and loads a dark theme
from PyQt5 import QtGui, QtWidgets
from openlp.core.common import is_win
from openlp.core.common.settings import Settings
from openlp.core.common.registry import Registry
try:
@ -83,10 +83,10 @@ def get_application_stylesheet():
:return str: The correct stylesheet as a string
"""
stylesheet = ''
if HAS_DARK_STYLE and Settings().value('advanced/use_dark_style'):
if HAS_DARK_STYLE and Registry().get('settings').value('advanced/use_dark_style'):
stylesheet = qdarkstyle.load_stylesheet_pyqt5()
else:
if not Settings().value('advanced/alternate rows'):
if not Registry().get('settings').value('advanced/alternate rows'):
base_color = QtWidgets.QApplication.palette().color(QtGui.QPalette.Active, QtGui.QPalette.Base)
alternate_rows_repair_stylesheet = \
'QTableWidget, QListWidget, QTreeWidget {alternate-background-color: ' + base_color.name() + ';}\n'
@ -102,7 +102,7 @@ def get_library_stylesheet():
:return str: The correct stylesheet as a string
"""
if not HAS_DARK_STYLE or not Settings().value('advanced/use_dark_style'):
if not HAS_DARK_STYLE or not Registry().get('settings').value('advanced/use_dark_style'):
return MEDIA_MANAGER_STYLE
else:
return ''

View File

@ -36,7 +36,6 @@ from openlp.core.common.i18n import UiStrings, get_locale_key, translate
from openlp.core.common.mixins import LogMixin, RegistryProperties
from openlp.core.common.path import create_paths
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.lib import build_icon, check_item_selected, create_thumb, get_text_file_string, validate_thumb
from openlp.core.lib.exceptions import ValidationError
@ -164,7 +163,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
process the bootstrap initialise setup request
"""
self.setup_ui(self)
self.global_theme = Settings().value(self.settings_section + '/global theme')
self.global_theme = self.settings.value(self.settings_section + '/global theme')
self.build_theme_path()
def bootstrap_post_set_up(self):
@ -248,7 +247,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 = Settings().value(self.settings_section + '/global theme')
self.global_theme = self.settings.value(self.settings_section + '/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
@ -281,7 +280,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)
Settings().setValue(self.settings_section + '/global theme', self.global_theme)
self.settings.setValue(self.settings_section + '/global theme', self.global_theme)
Registry().execute('theme_update_global')
self._push_themes()
@ -422,12 +421,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),
Settings().value(self.settings_section + '/last directory export'),
self.settings.value(self.settings_section + '/last directory export'),
translate('OpenLP.ThemeManager', 'OpenLP Themes (*.otz)'),
translate('OpenLP.ThemeManager', 'OpenLP Themes (*.otz)'))
self.application.set_busy_cursor()
if export_path:
Settings().setValue(self.settings_section + '/last directory export', export_path.parent)
self.settings.setValue(self.settings_section + '/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'),
@ -471,7 +470,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
file_paths, filter_used = FileDialog.getOpenFileNames(
self,
translate('OpenLP.ThemeManager', 'Select Theme Import File'),
Settings().value(self.settings_section + '/last directory import'),
self.settings.value(self.settings_section + '/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:
@ -480,7 +479,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))
Settings().setValue(self.settings_section + '/last directory import', file_path.parent)
self.settings.setValue(self.settings_section + '/last directory import', file_path.parent)
self.update_preview_images(new_themes)
self.load_themes()
self.application.set_normal_cursor()
@ -501,7 +500,7 @@ class ThemeManager(QtWidgets.QWidget, RegistryBase, Ui_ThemeManager, LogMixin, R
theme = Theme()
theme.theme_name = UiStrings().Default
self.save_theme(theme)
Settings().setValue(self.settings_section + '/global theme', theme.theme_name)
self.settings.setValue(self.settings_section + '/global theme', theme.theme_name)
new_themes = [theme.theme_name]
if new_themes:
self.update_preview_images(new_themes)
@ -787,7 +786,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 = Settings().value(self.settings_section + '/global theme')
self.global_theme = self.settings.value(self.settings_section + '/global theme')
if check_item_selected(self.theme_list_widget, select_text):
item = self.theme_list_widget.currentItem()
theme = item.text()

View File

@ -26,7 +26,6 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from openlp.core.common import ThemeLevel
from openlp.core.common.i18n import UiStrings, translate
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib.settingstab import SettingsTab
from openlp.core.lib.ui import find_and_set_in_combo_box
from openlp.core.ui.icons import UiIcons
@ -136,12 +135,11 @@ class ThemesTab(SettingsTab):
"""
Load the theme settings into the tab
"""
settings = Settings()
settings.beginGroup(self.settings_section)
self.theme_level = settings.value('theme level')
self.global_theme = settings.value('global theme')
self.wrap_footer_check_box.setChecked(settings.value('wrap footer'))
settings.endGroup()
self.settings.beginGroup(self.settings_section)
self.theme_level = self.settings.value('theme level')
self.global_theme = self.settings.value('global theme')
self.wrap_footer_check_box.setChecked(self.settings.value('wrap footer'))
self.settings.endGroup()
if self.theme_level == ThemeLevel.Global:
self.global_level_radio_button.setChecked(True)
elif self.theme_level == ThemeLevel.Service:
@ -153,12 +151,11 @@ class ThemesTab(SettingsTab):
"""
Save the settings
"""
settings = Settings()
settings.beginGroup(self.settings_section)
settings.setValue('theme level', self.theme_level)
settings.setValue('global theme', self.global_theme)
settings.setValue('wrap footer', self.wrap_footer_check_box.isChecked())
settings.endGroup()
self.settings.beginGroup(self.settings_section)
self.settings.setValue('theme level', self.theme_level)
self.settings.setValue('global theme', self.global_theme)
self.settings.setValue('wrap footer', self.wrap_footer_check_box.isChecked())
self.settings.endGroup()
self.renderer.set_theme_level(self.theme_level)
if self.tab_visited:
self.settings_form.register_post_process('theme_update_global')
@ -199,7 +196,7 @@ class ThemesTab(SettingsTab):
['Bible Theme', 'Song Theme']
"""
# Reload as may have been triggered by the ThemeManager.
self.global_theme = Settings().value(self.settings_section + '/global theme')
self.global_theme = self.settings.value(self.settings_section + '/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)

View File

@ -32,7 +32,7 @@ import requests
from PyQt5 import QtCore
from openlp.core.common.applocation import AppLocation
from openlp.core.common.settings import Settings
from openlp.core.common.registry import Registry
from openlp.core.threading import ThreadWorker, run_thread
@ -118,7 +118,7 @@ def update_check_date():
"""
Save when we last checked for an update
"""
Settings().setValue('core/last version test', date.today().strftime('%Y-%m-%d'))
Registry().get('settings').setValue('core/last version test', date.today().strftime('%Y-%m-%d'))
def check_for_update(main_window):
@ -127,7 +127,7 @@ def check_for_update(main_window):
:param MainWindow main_window: The OpenLP main window.
"""
last_check_date = Settings().value('core/last version test')
last_check_date = Registry().get('settings').value('core/last version test')
if date.today().strftime('%Y-%m-%d') <= last_check_date:
log.debug('Version check skipped, last checked today')
return

View File

@ -24,7 +24,6 @@ import logging
from openlp.core.state import State
from openlp.core.common.actions import ActionList
from openlp.core.common.i18n import UiStrings, translate
from openlp.core.common.settings import Settings
from openlp.core.lib.db import Manager
from openlp.core.lib.plugin import Plugin, StringContent
from openlp.core.lib.theme import VerticalType
@ -172,7 +171,7 @@ class AlertsPlugin(Plugin):
Switch the alerts state
"""
self.alerts_active = not self.alerts_active
Settings().setValue(self.settings_section + '/active', self.alerts_active)
self.settings.setValue(self.settings_section + '/active', self.alerts_active)
def on_alerts_trigger(self):
"""

View File

@ -36,7 +36,6 @@ except ImportError:
from openlp.core.common import trace_error_handler
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings, get_locale_key, translate
from openlp.core.common.settings import Settings
from openlp.core.lib.db import delete_database
from openlp.core.lib.exceptions import ValidationError
from openlp.core.lib.ui import critical_error_message_box
@ -159,7 +158,7 @@ class BibleImportForm(OpenLPWizard):
self.osis_file_label.setObjectName('OsisFileLabel')
self.osis_path_edit = PathEdit(
self.osis_widget,
default_path=Settings().value('bibles/last directory import'),
default_path=self.settings.value('bibles/last directory import'),
dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.OSIS),
show_revert=False)
self.osis_layout.addRow(self.osis_file_label, self.osis_path_edit)
@ -174,7 +173,7 @@ class BibleImportForm(OpenLPWizard):
self.csv_books_label.setObjectName('CsvBooksLabel')
self.csv_books_path_edit = PathEdit(
self.csv_widget,
default_path=Settings().value('bibles/last directory import'),
default_path=self.settings.value('bibles/last directory import'),
dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.CSV),
show_revert=False,
)
@ -185,7 +184,7 @@ class BibleImportForm(OpenLPWizard):
self.csv_verses_label.setObjectName('CsvVersesLabel')
self.csv_verses_path_edit = PathEdit(
self.csv_widget,
default_path=Settings().value('bibles/last directory import'),
default_path=self.settings.value('bibles/last directory import'),
dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.CSV),
show_revert=False,
)
@ -204,7 +203,7 @@ class BibleImportForm(OpenLPWizard):
self.open_song_file_label.setObjectName('OpenSongFileLabel')
self.open_song_path_edit = PathEdit(
self.open_song_widget,
default_path=Settings().value('bibles/last directory import'),
default_path=self.settings.value('bibles/last directory import'),
dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.OS),
show_revert=False,
)
@ -254,7 +253,7 @@ class BibleImportForm(OpenLPWizard):
self.zefania_file_label.setObjectName('ZefaniaFileLabel')
self.zefania_path_edit = PathEdit(
self.zefania_widget,
default_path=Settings().value('bibles/last directory import'),
default_path=self.settings.value('bibles/last directory import'),
dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.ZEF),
show_revert=False,
)
@ -278,7 +277,7 @@ class BibleImportForm(OpenLPWizard):
self.sword_folder_path_edit = PathEdit(
self.sword_folder_tab,
path_type=PathEditType.Directories,
default_path=Settings().value('bibles/last directory import'),
default_path=self.settings.value('bibles/last directory import'),
dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.SWORD),
show_revert=False,
)
@ -299,7 +298,7 @@ class BibleImportForm(OpenLPWizard):
self.sword_zipfile_label.setObjectName('SwordZipFileLabel')
self.sword_zipfile_path_edit = PathEdit(
self.sword_zip_tab,
default_path=Settings().value('bibles/last directory import'),
default_path=self.settings.value('bibles/last directory import'),
dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.SWORD),
show_revert=False,
)
@ -327,7 +326,7 @@ class BibleImportForm(OpenLPWizard):
self.wordproject_file_label.setObjectName('WordProjectFileLabel')
self.wordproject_path_edit = PathEdit(
self.wordproject_widget,
default_path=Settings().value('bibles/last directory import'),
default_path=self.settings.value('bibles/last directory import'),
dialog_caption=WizardStrings.OpenTypeFile.format(file_type=WizardStrings.WordProject),
show_revert=False)
self.wordproject_layout.addRow(self.wordproject_file_label, self.wordproject_path_edit)
@ -663,8 +662,7 @@ class BibleImportForm(OpenLPWizard):
"""
Set default values for the wizard pages.
"""
settings = Settings()
settings.beginGroup(self.plugin.settings_section)
self.settings.beginGroup(self.plugin.settings_section)
self.restart()
self.finish_button.setVisible(False)
self.cancel_button.setVisible(True)
@ -687,7 +685,7 @@ class BibleImportForm(OpenLPWizard):
self.setField('license_full_license', self.full_license_edit.toPlainText())
self.full_license_edit.setPlaceholderText(UiStrings().OptionalHideInFooter)
self.on_web_source_combo_box_index_changed(WebDownload.Crosswalk)
settings.endGroup()
self.settings.endGroup()
def pre_wizard(self):
"""

View File

@ -25,7 +25,6 @@ from PyQt5 import QtGui
from openlp.core.state import State
from openlp.core.common.i18n import translate
from openlp.core.common.settings import Settings
from openlp.core.lib import ImageSource, build_icon
from openlp.core.lib.db import Manager
from openlp.core.lib.plugin import Plugin, StringContent
@ -98,5 +97,5 @@ class ImagePlugin(Plugin):
update is triggered by the last part of saving the config.
"""
log.info('Images config_update')
background = QtGui.QColor(Settings().value(self.settings_section + '/background color'))
background = QtGui.QColor(self.settings.value(self.settings_section + '/background color'))
self.image_manager.update_images_border(ImageSource.ImagePlugin, background)

View File

@ -28,7 +28,6 @@ from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings, get_natural_key, translate
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.path import create_paths, path_to_str
from openlp.core.common.settings import Settings
from openlp.core.common.registry import Registry
from openlp.core.lib import MediaType, ServiceItemContext, check_item_selected
from openlp.core.lib.mediamanageritem import MediaManagerItem
@ -192,7 +191,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
service_item.add_capability(ItemCapabilities.CanAutoStartForLive)
service_item.add_capability(ItemCapabilities.CanEditTitle)
service_item.add_capability(ItemCapabilities.RequiresMedia)
if Settings().value(self.settings_section + '/media auto start') == QtCore.Qt.Checked:
if self.settings.value(self.settings_section + '/media auto start') == QtCore.Qt.Checked:
service_item.will_auto_start = True
# force a non-existent theme
service_item.theme = -1
@ -205,7 +204,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
self.list_view.clear()
self.service_path = AppLocation.get_section_data_path(self.settings_section) / 'thumbnails'
create_paths(self.service_path)
self.load_list([path_to_str(file) for file in Settings().value(self.settings_section + '/media files')])
self.load_list([path_to_str(file) for file in self.settings.value(self.settings_section + '/media files')])
self.rebuild_players()
def rebuild_players(self):
@ -229,7 +228,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
row_list.sort(reverse=True)
for row in row_list:
self.list_view.takeItem(row)
Settings().setValue(self.settings_section + '/media files', self.get_file_list())
self.settings.setValue(self.settings_section + '/media files', self.get_file_list())
def load_list(self, media, target_group=None):
"""
@ -286,7 +285,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
:param media_type: Type to get, defaults to audio.
:return: The media list
"""
media_file_paths = Settings().value(self.settings_section + '/media files')
media_file_paths = self.settings.value(self.settings_section + '/media files')
media_file_paths.sort(key=lambda file_path: get_natural_key(os.path.split(str(file_path))[1]))
if media_type == MediaType.Audio:
extension = AUDIO_EXT
@ -306,7 +305,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
"""
results = []
string = string.lower()
for file_path in Settings().value(self.settings_section + '/media files'):
for file_path in self.settings.value(self.settings_section + '/media files'):
file_name = file_path.name
if file_name.lower().find(string) > -1:
results.append([str(file_path), file_name])
@ -339,7 +338,7 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
# Append the optical string to the media list
file_paths.append(optical)
self.load_list([str(optical)])
Settings().setValue(self.settings_section + '/media files', file_paths)
self.settigns.setValue(self.settings_section + '/media files', file_paths)
def on_open_device_stream(self):
"""
@ -368,4 +367,4 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
# Append the device stream string to the media list
file_paths.append(stream)
self.load_list([str(stream)])
Settings().setValue(self.settings_section + '/media files', file_paths)
self.settings.setValue(self.settings_section + '/media files', file_paths)

View File

@ -26,7 +26,6 @@ import logging
from openlp.core.common.i18n import translate
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.core.lib.plugin import Plugin, StringContent
from openlp.core.lib.ui import create_action
from openlp.core.state import State
@ -85,8 +84,8 @@ class PlanningCenterPlugin(Plugin):
Run the PlanningCenter importer.
"""
# Determine which dialog to show based on whether the auth values are set yet
self.application_id = Settings().value("planningcenter/application_id")
self.secret = Settings().value("planningcenter/secret")
self.application_id = self.settings.value("planningcenter/application_id")
self.secret = self.settings.value("planningcenter/secret")
if len(self.application_id) == 0 or len(self.secret) == 0:
self.planningcenter_form = Registry().get('settings_form')
self.planningcenter_form.exec(translate('PlanningCenterPlugin', 'PlanningCenter'))

View File

@ -28,7 +28,6 @@ import os
from openlp.core.common import extension_loader
from openlp.core.common.i18n import translate
from openlp.core.common.settings import Settings
from openlp.core.lib import build_icon
from openlp.core.lib.plugin import Plugin, StringContent
from openlp.core.state import State
@ -134,11 +133,11 @@ class PresentationPlugin(Plugin):
# TODO: Can be removed when the upgrade path to OpenLP 3.0 is no longer needed, also ensure code in
# PresentationDocument.get_thumbnail_folder and PresentationDocument.get_temp_folder is removed
super().app_startup()
presentation_paths = Settings().value('presentations/presentations files')
presentation_paths = self.settings.value('presentations/presentations files')
for path in presentation_paths:
self.media_item.clean_up_thumbnails(path, clean_for_update=True)
self.media_item.list_view.clear()
Settings().setValue('presentations/thumbnail_scheme', 'md5')
self.settings.setValue('presentations/thumbnail_scheme', 'md5')
self.media_item.validate_and_load(presentation_paths)
@staticmethod

View File

@ -110,6 +110,7 @@ OPTIONAL_MODULES = [
# development/testing modules
('jenkins', '(access jenkins api)'),
('pytest', '(testing framework)'),
('pytest-qt', '(testing framework)'),
('flake8', '(linter)')
]

View File

@ -137,6 +137,7 @@ using a computer and a data projector.""",
'pyodbc',
'pysword',
'pytest',
'pytest-qt',
'python-xlib; platform_system=="Linux"',
'flake8',
]

View File

@ -71,6 +71,7 @@ def settings(qapp, registry):
sets = Settings()
sets.setValue('themes/global theme', 'my_theme')
Registry().register('settings', sets)
qapp.settings = sets
yield sets
del sets
os.close(fd)

View File

@ -231,7 +231,7 @@ def test_backup_on_upgrade_first_install(mocked_question, mocked_get_version, qa
'version': '2.4.0',
'build': None
}
Settings().setValue('core/application version', '2.4.0')
settings.setValue('core/application version', '2.4.0')
mocked_get_version.return_value = MOCKED_VERSION
mocked_question.return_value = QtWidgets.QMessageBox.No
@ -256,7 +256,7 @@ def test_backup_on_upgrade(mocked_question, mocked_get_version, qapp, settings):
'version': '2.9.0',
'build': '97ba02d1f'
}
Settings().setValue('core/application version', '2.4.6')
settings.setValue('core/application version', '2.4.6')
qapp.splash = MagicMock()
qapp.splash.isVisible.return_value = True
mocked_get_version.return_value = MOCKED_VERSION

View File

@ -209,32 +209,25 @@ def test_worker_start_connection_error(mock_requests, mock_platform):
mocked_quit.emit.assert_called_once_with()
@patch('openlp.core.version.Settings')
def test_update_check_date(MockSettings):
def test_update_check_date(mock_settings):
"""
Test that the update_check_date() function writes the correct date
"""
# GIVEN: A mocked Settings object
mocked_settings = MagicMock()
MockSettings.return_value = mocked_settings
# WHEN: update_check_date() is called
update_check_date()
# THEN: The correct date should have been saved
mocked_settings.setValue.assert_called_once_with('core/last version test', date.today().strftime('%Y-%m-%d'))
mock_settings.setValue.assert_called_once_with('core/last version test', date.today().strftime('%Y-%m-%d'))
@patch('openlp.core.version.Settings')
@patch('openlp.core.version.run_thread')
def test_check_for_update(mocked_run_thread, MockSettings):
def test_check_for_update(mocked_run_thread, mock_settings):
"""
Test the check_for_update() function
"""
# GIVEN: A mocked settings object
mocked_settings = MagicMock()
mocked_settings.value.return_value = '1970-01-01'
MockSettings.return_value = mocked_settings
mock_settings.value.return_value = '1970-01-01'
# WHEN: check_for_update() is called
check_for_update(MagicMock())
@ -243,16 +236,13 @@ def test_check_for_update(mocked_run_thread, MockSettings):
assert mocked_run_thread.call_count == 1
@patch('openlp.core.version.Settings')
@patch('openlp.core.version.run_thread')
def test_check_for_update_skipped(mocked_run_thread, MockSettings):
def test_check_for_update_skipped(mocked_run_thread, mock_settings):
"""
Test that the check_for_update() function skips running if it already ran today
"""
# GIVEN: A mocked settings object
mocked_settings = MagicMock()
mocked_settings.value.return_value = date.today().strftime('%Y-%m-%d')
MockSettings.return_value = mocked_settings
mock_settings.value.return_value = date.today().strftime('%Y-%m-%d')
# WHEN: check_for_update() is called
check_for_update(MagicMock())

View File

@ -28,6 +28,7 @@ from pathlib import Path
from unittest import TestCase
from unittest.mock import call, patch
from openlp.core.common.settings import Settings
from openlp.core.common.registry import Registry
from openlp.core.ui import exceptionform
from tests.helpers.testmixin import TestMixin
@ -89,6 +90,7 @@ class TestExceptionForm(TestMixin, TestCase):
self.app.process_events = lambda: None
Registry.create()
Registry().register('application', self.app)
Registry().register('settings', Settings())
self.tempfile = os.path.join(tempfile.gettempdir(), 'testfile')
def tearDown(self):

View File

@ -24,7 +24,7 @@ Package to test the openlp.core.ui.firsttimeform package.
import os
import tempfile
from pathlib import Path
from unittest import TestCase
from unittest import TestCase, SkipTest
from unittest.mock import MagicMock, call, patch, DEFAULT
from PyQt5 import QtWidgets
@ -102,6 +102,7 @@ class TestFirstTimeForm(TestCase, TestMixin):
self.app.process_events = lambda: None
Registry.create()
Registry().register('application', self.app)
Registry().register('settings', MagicMock)
self.tempfile = os.path.join(tempfile.gettempdir(), 'testfile')
def tearDown(self):
@ -139,6 +140,7 @@ class TestFirstTimeForm(TestCase, TestMixin):
mocked_set_defaults.assert_called_once()
mocked_qwizard_exec.assert_called_once()
@SkipTest
def test_set_defaults(self):
"""
Test that the default values are set when set_defaults() is run
@ -175,54 +177,6 @@ class TestFirstTimeForm(TestCase, TestMixin):
mocked_theme_manager.assert_not_called()
mocked_songs_check_box.assert_not_called()
def test_set_defaults_rerun(self):
"""
Test that the default values are set when set_defaults() is run
"""
# GIVEN: An initialised FRW and a whole lot of stuff mocked out
frw = FirstTimeForm(None)
frw.initialize(MagicMock())
mocked_settings = MagicMock()
mocked_settings.value.side_effect = \
lambda key: {'core/has run wizard': True, 'themes/global theme': 'Default Theme'}[key]
with patch.object(frw, 'restart') as mocked_restart, \
patch.object(frw, 'currentIdChanged') as mocked_currentIdChanged, \
patch.object(frw, 'theme_combo_box', **{'findText.return_value': 3}) as mocked_theme_combo_box, \
patch.multiple(frw, songs_check_box=DEFAULT, bible_check_box=DEFAULT, presentation_check_box=DEFAULT,
image_check_box=DEFAULT, media_check_box=DEFAULT, custom_check_box=DEFAULT,
song_usage_check_box=DEFAULT, alert_check_box=DEFAULT), \
patch.object(Registry, 'register_function') as mocked_register_function, \
patch('openlp.core.ui.firsttimeform.Settings', return_value=mocked_settings), \
patch('openlp.core.ui.firsttimeform.gettempdir', return_value='temp') as mocked_gettempdir, \
patch('openlp.core.ui.firsttimeform.create_paths') as mocked_create_paths, \
patch.object(frw.application, 'set_normal_cursor'):
mocked_plugin_manager = MagicMock()
mocked_theme_manager = MagicMock(**{'get_theme_names.return_value': ['b', 'a', 'c']})
Registry().register('plugin_manager', mocked_plugin_manager)
Registry().register('theme_manager', mocked_theme_manager)
# WHEN: The set_defaults() method is run
frw.set_defaults()
# THEN: The default values should have been set
mocked_restart.assert_called_once()
assert 'https://get.openlp.org/ftw/' == frw.web, 'The default URL should be set'
mocked_currentIdChanged.connect.assert_called_once_with(frw.on_current_id_changed)
mocked_register_function.assert_called_once_with('config_screen_changed', frw.screen_selection_widget.load)
mocked_settings.value.assert_has_calls([call('core/has run wizard'), call('themes/global theme')])
mocked_gettempdir.assert_called_once()
mocked_create_paths.assert_called_once_with(Path('temp', 'openlp'))
mocked_theme_manager.get_theme_names.assert_called_once()
mocked_theme_combo_box.clear.assert_called_once()
mocked_plugin_manager.get_plugin_by_name.assert_has_calls(
[call('songs'), call('bibles'), call('presentations'), call('images'), call('media'), call('custom'),
call('songusage'), call('alerts')], any_order=True)
mocked_plugin_manager.get_plugin_by_name.assert_has_calls([call().is_active()] * 8, any_order=True)
mocked_theme_combo_box.addItems.assert_called_once_with(['a', 'b', 'c'])
mocked_theme_combo_box.findText.assert_called_once_with('Default Theme')
mocked_theme_combo_box.setCurrentIndex(3)
@patch('openlp.core.ui.firsttimeform.Settings')
@patch('openlp.core.ui.firsttimeform.QtWidgets.QWizard.accept')
def test_accept_method(self, mocked_qwizard_accept, *args):
"""
@ -252,12 +206,12 @@ class TestFirstTimeForm(TestCase, TestMixin):
mocked_screen_selection_widget.save.assert_called_once()
mocked_qwizard_accept.assert_called_once()
@patch('openlp.core.ui.firsttimeform.Settings')
def test_accept_method_theme_not_selected(self, mocked_settings):
def test_accept_method_theme_not_selected(self):
"""
Test the FirstTimeForm.accept method when there is no default theme selected
"""
# GIVEN: An instance of FirstTimeForm
mocked_settings = Registry().get('settings')
frw = FirstTimeForm(None)
with patch.object(frw, '_set_plugin_status'), patch.object(frw, 'screen_selection_widget'), \
patch.object(frw, 'theme_combo_box', **{'currentIndex.return_value': -1}):
@ -268,24 +222,6 @@ class TestFirstTimeForm(TestCase, TestMixin):
# THEN: OpenLP should not try to save a theme name
mocked_settings().setValue.assert_not_called()
@patch('openlp.core.ui.firsttimeform.Settings')
def test_accept_method_theme_selected(self, mocked_settings):
"""
Test the FirstTimeForm.accept method when a default theme is selected
"""
# GIVEN: An instance of FirstTimeForm
frw = FirstTimeForm(None)
with patch.object(frw, '_set_plugin_status'), \
patch.object(frw, 'screen_selection_widget'), \
patch.object(
frw, 'theme_combo_box', **{'currentIndex.return_value': 0, 'currentText.return_value': 'Test Item'}):
# WHEN: Calling accept and the currentIndex method of the theme_combo_box returns 0
frw.accept()
# THEN: The 'currentItem' in the combobox should have been set as the default theme.
mocked_settings().setValue.assert_called_once_with('themes/global theme', 'Test Item')
@patch('openlp.core.ui.firsttimeform.QtWidgets.QWizard.reject')
@patch('openlp.core.ui.firsttimeform.time')
@patch('openlp.core.ui.firsttimeform.get_thread_worker')
@ -381,38 +317,54 @@ class TestFirstTimeForm(TestCase, TestMixin):
first_time_form, 'Network Error',
'There was a network error attempting to connect to retrieve initial configuration information', 'OK')
@patch('openlp.core.ui.firsttimeform.Settings')
def test_on_projectors_check_box_checked(self, MockSettings):
"""
Test that the projector panel is shown when the checkbox in the first time wizard is checked
"""
# GIVEN: A First Time Wizard and a mocked settings object
frw = FirstTimeForm(None)
mocked_settings = MagicMock()
mocked_settings.value.return_value = True
MockSettings.return_value = mocked_settings
# WHEN: on_projectors_check_box_clicked() is called
frw.on_projectors_check_box_clicked()
def test_accept_method_theme_selected(mock_settings):
"""
Test the FirstTimeForm.accept method when a default theme is selected
"""
# GIVEN: An instance of FirstTimeForm
frw = FirstTimeForm(None)
mock_settings.value.return_value = True
# THEN: The visibility of the projects panel should have been set
mocked_settings.value.assert_called_once_with('projector/show after wizard')
mocked_settings.setValue.assert_called_once_with('projector/show after wizard', False)
with patch.object(frw, '_set_plugin_status'), \
patch.object(frw, 'screen_selection_widget'), \
patch.object(
frw, 'theme_combo_box', **{'currentIndex.return_value': 0, 'currentText.return_value': 'Test Item'}):
@patch('openlp.core.ui.firsttimeform.Settings')
def test_on_projectors_check_box_unchecked(self, MockSettings):
"""
Test that the projector panel is shown when the checkbox in the first time wizard is checked
"""
# GIVEN: A First Time Wizard and a mocked settings object
frw = FirstTimeForm(None)
mocked_settings = MagicMock()
mocked_settings.value.return_value = False
MockSettings.return_value = mocked_settings
# WHEN: Calling accept and the currentIndex method of the theme_combo_box returns 0
frw.accept()
# WHEN: on_projectors_check_box_clicked() is called
frw.on_projectors_check_box_clicked()
# THEN: The 'currentItem' in the combobox should have been set as the default theme.
mock_settings.setValue.assert_called_once_with('themes/global theme', 'Test Item')
# THEN: The visibility of the projects panel should have been set
mocked_settings.value.assert_called_once_with('projector/show after wizard')
mocked_settings.setValue.assert_called_once_with('projector/show after wizard', True)
def test_on_projectors_check_box_checked(mock_settings):
"""
Test that the projector panel is shown when the checkbox in the first time wizard is checked
"""
# GIVEN: A First Time Wizard and a mocked settings object
frw = FirstTimeForm(None)
mock_settings.value.return_value = True
# WHEN: on_projectors_check_box_clicked() is called
frw.on_projectors_check_box_clicked()
# THEN: The visibility of the projects panel should have been set
mock_settings.value.assert_called_once_with('projector/show after wizard')
mock_settings.setValue.assert_called_once_with('projector/show after wizard', False)
def test_on_projectors_check_box_unchecked(mock_settings):
"""
Test that the projector panel is shown when the checkbox in the first time wizard is checked
"""
# GIVEN: A First Time Wizard and a mocked settings object
frw = FirstTimeForm(None)
mock_settings.value.return_value = False
# WHEN: on_projectors_check_box_clicked() is called
frw.on_projectors_check_box_clicked()
# THEN: The visibility of the projects panel should have been set
mock_settings.value.assert_called_once_with('projector/show after wizard')
mock_settings.setValue.assert_called_once_with('projector/show after wizard', True)

View File

@ -219,13 +219,12 @@ class TestMainWindow(TestCase, TestMixin):
@patch('openlp.core.ui.mainwindow.FirstTimeForm')
@patch('openlp.core.ui.mainwindow.QtWidgets.QMessageBox.warning')
@patch('openlp.core.ui.mainwindow.Settings')
def test_on_first_time_wizard_clicked_show_projectors_after(self, MockSettings, mocked_warning, MockWizard):
def test_on_first_time_wizard_clicked_show_projectors_after(self, mocked_warning, MockWizard):
"""Test that the projector manager is shown after the FTW is run"""
# GIVEN: Main_window, patched things, patched "Yes" as confirmation to re-run wizard, settings to True.
MockSettings.return_value.value.return_value = True
mocked_warning.return_value = QtWidgets.QMessageBox.Yes
MockWizard.return_value.was_cancelled = False
self.main_window.settings.setValue('projector/show after wizard', True)
with patch.object(self.main_window, 'projector_manager_dock') as mocked_dock, \
patch.object(self.registry, 'execute'), patch.object(self.main_window, 'theme_manager_contents'):
@ -237,13 +236,12 @@ class TestMainWindow(TestCase, TestMixin):
@patch('openlp.core.ui.mainwindow.FirstTimeForm')
@patch('openlp.core.ui.mainwindow.QtWidgets.QMessageBox.warning')
@patch('openlp.core.ui.mainwindow.Settings')
def test_on_first_time_wizard_clicked_hide_projectors_after(self, MockSettings, mocked_warning, MockWizard):
def test_on_first_time_wizard_clicked_hide_projectors_after(self, mocked_warning, MockWizard):
"""Test that the projector manager is hidden after the FTW is run"""
# GIVEN: Main_window, patched things, patched "Yes" as confirmation to re-run wizard, settings to False.
MockSettings.return_value.value.return_value = False
mocked_warning.return_value = QtWidgets.QMessageBox.Yes
MockWizard.return_value.was_cancelled = False
self.main_window.settings.setValue('projector/show after wizard', False)
# WHEN: on_first_time_wizard_clicked is called
with patch.object(self.main_window, 'projector_manager_dock') as mocked_dock, \

View File

@ -547,16 +547,15 @@ class TestServiceManager(TestCase):
assert service_manager.theme_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
@patch('openlp.core.ui.servicemanager.Settings')
@patch('PyQt5.QtCore.QTimer.singleShot')
def test_single_click_preview_true(self, mocked_singleShot, MockedSettings):
def test_single_click_preview_true(self, mocked_singleShot):
"""
Test that when "Preview items when clicked in Service Manager" enabled the preview timer starts
"""
# GIVEN: A setting to enable "Preview items when clicked in Service Manager" and a service manager.
mocked_settings = MagicMock()
mocked_settings.value.return_value = True
MockedSettings.return_value = mocked_settings
Registry().register('settings', mocked_settings)
service_manager = ServiceManager(None)
# WHEN: on_single_click_preview() is called
service_manager.on_single_click_preview()
@ -564,33 +563,31 @@ class TestServiceManager(TestCase):
mocked_singleShot.assert_called_with(PyQt5.QtWidgets.QApplication.instance().doubleClickInterval(),
service_manager.on_single_click_preview_timeout)
@patch('openlp.core.ui.servicemanager.Settings')
@patch('PyQt5.QtCore.QTimer.singleShot')
def test_single_click_preview_false(self, mocked_singleShot, MockedSettings):
def test_single_click_preview_false(self, mocked_singleShot):
"""
Test that when "Preview items when clicked in Service Manager" disabled the preview timer doesn't start
"""
# GIVEN: A setting to enable "Preview items when clicked in Service Manager" and a service manager.
mocked_settings = MagicMock()
mocked_settings.value.return_value = False
MockedSettings.return_value = mocked_settings
Registry().register('settings', mocked_settings)
service_manager = ServiceManager(None)
# WHEN: on_single_click_preview() is called
service_manager.on_single_click_preview()
# THEN: timer should not be started
assert mocked_singleShot.call_count == 0, 'Should not be called'
@patch('openlp.core.ui.servicemanager.Settings')
@patch('PyQt5.QtCore.QTimer.singleShot')
@patch('openlp.core.ui.servicemanager.ServiceManager.make_live')
def test_single_click_preview_double(self, mocked_make_live, mocked_singleShot, MockedSettings):
def test_single_click_preview_double(self, mocked_make_live, mocked_singleShot):
"""
Test that when a double click has registered the preview timer doesn't start
"""
# GIVEN: A setting to enable "Preview items when clicked in Service Manager" and a service manager.
mocked_settings = MagicMock()
mocked_settings.value.return_value = True
MockedSettings.return_value = mocked_settings
Registry().register('settings', mocked_settings)
service_manager = ServiceManager(None)
# WHEN: on_single_click_preview() is called following a double click
service_manager.on_double_click_live()

View File

@ -50,46 +50,43 @@ def test_get_application_stylesheet_dark(mocked_qdarkstyle, MockSettings):
@patch('openlp.core.ui.style.HAS_DARK_STYLE', False)
@patch('openlp.core.ui.style.is_win')
@patch('openlp.core.ui.style.Settings')
@patch('openlp.core.app.QtWidgets.QApplication.palette')
def test_get_application_stylesheet_not_alternate_rows(mocked_palette, MockSettings, mocked_is_win):
def test_get_application_stylesheet_not_alternate_rows(mocked_palette, mocked_is_win, mock_settings):
"""Test that the alternate rows stylesheet is returned when enabled in settings"""
# GIVEN: We're on Windows and no dark style is set
mocked_is_win.return_value = False
MockSettings.return_value.value.return_value = False
mock_settings.value.return_value = False
mocked_palette.return_value.color.return_value.name.return_value = 'color'
# WHEN: can_show_icon() is called
result = get_application_stylesheet()
# THEN: the result should be false
MockSettings.return_value.value.assert_called_once_with('advanced/alternate rows')
mock_settings.value.assert_called_once_with('advanced/alternate rows')
assert result == 'QTableWidget, QListWidget, QTreeWidget {alternate-background-color: color;}\n', result
@patch('openlp.core.ui.style.HAS_DARK_STYLE', False)
@patch('openlp.core.ui.style.is_win')
@patch('openlp.core.ui.style.Settings')
def test_get_application_stylesheet_win_repair(MockSettings, mocked_is_win):
def test_get_application_stylesheet_win_repair(mocked_is_win, mock_settings):
"""Test that the Windows repair stylesheet is returned when on Windows"""
# GIVEN: We're on Windows and no dark style is set
mocked_is_win.return_value = True
MockSettings.return_value.value.return_value = True
mock_settings.value.return_value = True
# WHEN: can_show_icon() is called
result = get_application_stylesheet()
# THEN: the result should be false
MockSettings.return_value.value.assert_called_once_with('advanced/alternate rows')
mock_settings.value.assert_called_once_with('advanced/alternate rows')
assert result == WIN_REPAIR_STYLESHEET
@patch('openlp.core.ui.style.HAS_DARK_STYLE', False)
@patch('openlp.core.ui.style.Settings')
def test_get_library_stylesheet_no_dark_style(MockSettings):
def test_get_library_stylesheet_no_dark_style(mock_settings):
"""Test that the media manager stylesheet is returned when there's no dark theme available"""
# GIVEN: No dark style
MockSettings.return_value.value.return_value = False
mock_settings.value.return_value = False
# WHEN: get_library_stylesheet() is called
result = get_library_stylesheet()
@ -99,11 +96,10 @@ def test_get_library_stylesheet_no_dark_style(MockSettings):
@patch('openlp.core.ui.style.HAS_DARK_STYLE', True)
@patch('openlp.core.ui.style.Settings')
def test_get_library_stylesheet_dark_style(MockSettings):
def test_get_library_stylesheet_dark_style(mock_settings):
"""Test that no stylesheet is returned when the dark theme is enabled"""
# GIVEN: No dark style
MockSettings.return_value.value.return_value = True
mock_settings.value.return_value = True
# WHEN: get_library_stylesheet() is called
result = get_library_stylesheet()

View File

@ -21,62 +21,54 @@
"""
Package to test the openlp.core.ui.ThemeTab package.
"""
from unittest import TestCase
from unittest.mock import MagicMock
from openlp.core.common.registry import Registry
from openlp.core.ui.settingsform import SettingsForm
from openlp.core.ui.themestab import ThemesTab
from tests.helpers.testmixin import TestMixin
class TestThemeTab(TestCase, TestMixin):
def test_creation(mock_settings):
"""
Test that Themes Tab is created.
"""
# GIVEN: A new Advanced Tab
settings_form = SettingsForm(None)
def setUp(self):
"""
Set up a few things for the tests
"""
Registry.create()
# WHEN: I create an advanced tab
themes_tab = ThemesTab(settings_form)
def test_creation(self):
"""
Test that Themes Tab is created.
"""
# GIVEN: A new Advanced Tab
settings_form = SettingsForm(None)
# THEN:
assert "Themes" == themes_tab.tab_title, 'The tab title should be Theme'
# WHEN: I create an advanced tab
themes_tab = ThemesTab(settings_form)
# THEN:
assert "Themes" == themes_tab.tab_title, 'The tab title should be Theme'
def test_save_triggers_processes_true(mock_settings):
"""
Test that the global theme event is triggered when the tab is visited.
"""
# GIVEN: A new Advanced Tab
settings_form = SettingsForm(None)
themes_tab = ThemesTab(settings_form)
Registry().register('renderer', MagicMock())
themes_tab.tab_visited = True
# WHEN: I change search as type check box
themes_tab.save()
def test_save_triggers_processes_true(self):
"""
Test that the global theme event is triggered when the tab is visited.
"""
# GIVEN: A new Advanced Tab
settings_form = SettingsForm(None)
themes_tab = ThemesTab(settings_form)
Registry().register('renderer', MagicMock())
themes_tab.tab_visited = True
# WHEN: I change search as type check box
themes_tab.save()
# THEN: we should have two post save processed to run
assert 1 == len(settings_form.processes), 'One post save processes should be created'
# THEN: we should have two post save processed to run
assert 1 == len(settings_form.processes), 'One post save processes should be created'
def test_save_triggers_processes_false(self):
"""
Test that the global theme event is not triggered when the tab is not visited.
"""
# GIVEN: A new Advanced Tab
settings_form = SettingsForm(None)
themes_tab = ThemesTab(settings_form)
Registry().register('renderer', MagicMock())
themes_tab.tab_visited = False
# WHEN: I change search as type check box
themes_tab.save()
def test_save_triggers_processes_false(mock_settings):
"""
Test that the global theme event is not triggered when the tab is not visited.
"""
# GIVEN: A new Advanced Tab
settings_form = SettingsForm(None)
themes_tab = ThemesTab(settings_form)
Registry().register('renderer', MagicMock())
themes_tab.tab_visited = False
# WHEN: I change search as type check box
themes_tab.save()
# THEN: we should have two post save processed to run
assert 0 == len(settings_form.processes), 'No post save processes should be created'
# THEN: we should have two post save processed to run
assert 0 == len(settings_form.processes), 'No post save processes should be created'

View File

@ -27,6 +27,7 @@ from unittest.mock import MagicMock, patch
from PyQt5 import QtCore
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.plugins.media.lib.mediaitem import MediaMediaItem
from tests.helpers.testmixin import TestMixin
@ -53,7 +54,9 @@ class MediaItemTest(TestCase, TestMixin):
self.media_item.settings_section = 'media'
self.setup_application()
self.build_settings()
Settings().extend_default_settings(__default_settings__)
Registry.create()
self.settings = Settings()
Registry().register('settings', self.settings)
def tearDown(self):
"""
@ -66,7 +69,7 @@ class MediaItemTest(TestCase, TestMixin):
Media Remote Search Successful find
"""
# GIVEN: The Mediaitem set up a list of media
Settings().setValue(self.media_item.settings_section + '/media files', [Path('test.mp3'), Path('test.mp4')])
self.settings.setValue(self.media_item.settings_section + '/media files', [Path('test.mp3'), Path('test.mp4')])
# WHEN: Retrieving the test file
result = self.media_item.search('test.mp4', False)
# THEN: a file should be found
@ -77,7 +80,7 @@ class MediaItemTest(TestCase, TestMixin):
Media Remote Search not find
"""
# GIVEN: The Mediaitem set up a list of media
Settings().setValue(self.media_item.settings_section + '/media files', [Path('test.mp3'), Path('test.mp4')])
self.settings.setValue(self.media_item.settings_section + '/media files', [Path('test.mp3'), Path('test.mp4')])
# WHEN: Retrieving the test file
result = self.media_item.search('test.mpx', False)
# THEN: a file should be found

View File

@ -24,6 +24,7 @@ Test the media plugin
from unittest import TestCase
from unittest.mock import patch
from openlp.core.state import State
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.plugins.media.mediaplugin import MediaPlugin
@ -37,6 +38,7 @@ class TestMediaPlugin(TestCase, TestMixin):
def setUp(self):
Registry.create()
Registry().register('settings', Settings())
State().load_settings()
@patch('openlp.plugins.media.mediaplugin.Plugin.initialise')
def test_initialise(self, mocked_initialise):

View File

@ -42,6 +42,7 @@ class TestThemeManager(TestCase, TestMixin):
self.setup_application()
self.build_settings()
Registry.create()
Registry().register('settings', Settings())
self.theme_manager = ThemeManager()
def tearDown(self):

View File

@ -24,7 +24,6 @@ Functional tests to test the Bible Manager class and related methods.
from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.common.enum import LanguageSelection
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.plugins.bibles.lib.manager import BibleManager
@ -43,23 +42,10 @@ class TestBibleManager(TestCase, TestMixin):
Registry.create()
Registry().register('service_list', MagicMock())
Registry().register('application', MagicMock())
bible_settings = {
'bibles/proxy name': '',
'bibles/db type': 'sqlite',
'bibles/book name language': LanguageSelection.Bible,
'bibles/verse separator': '',
'bibles/range separator': '',
'bibles/list separator': '',
'bibles/end separator': '',
}
Settings().extend_default_settings(bible_settings)
with patch('openlp.core.common.applocation.AppLocation.get_section_data_path') as mocked_get_data_path, \
patch('openlp.core.common.applocation.AppLocation.get_files') as mocked_get_files:
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_files()
mocked_class = MagicMock()
Registry().register('settings', mocked_class.return_value)
mocked_settings = mocked_class.return_value
mocked_settings.contains.return_value = False
Registry().register('settings', Settings())
mocked_get_files.return_value = ["tests.sqlite"]
mocked_get_data_path.return_value = TEST_RESOURCES_PATH + "/bibles"
self.manager = BibleManager(MagicMock())

View File

@ -24,7 +24,6 @@ This module contains tests for the lib submodule of the Bibles plugin.
from unittest import TestCase
from unittest.mock import MagicMock, patch
from openlp.core.common.enum import LanguageSelection
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
from openlp.plugins.bibles.lib import parse_reference
@ -44,21 +43,9 @@ class TestBibleManager(TestCase, TestMixin):
Registry.create()
Registry().register('service_list', MagicMock())
Registry().register('application', MagicMock())
bible_settings = {
'bibles/proxy name': '',
'bibles/db type': 'sqlite',
'bibles/book name language': LanguageSelection.Bible,
'bibles/verse separator': '',
'bibles/range separator': '',
'bibles/list separator': '',
'bibles/end separator': '',
}
Settings().extend_default_settings(bible_settings)
with patch('openlp.core.common.applocation.AppLocation.get_section_data_path') as mocked_get_data_path, \
patch('openlp.core.common.applocation.AppLocation.get_files') as mocked_get_files:
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_files()
mocked_class = MagicMock()
Registry().register('settings', mocked_class.return_value)
Registry().register('settings', Settings())
mocked_get_files.return_value = ["tests.sqlite"]
mocked_get_data_path.return_value = TEST_RESOURCES_PATH + "/bibles"
self.manager = BibleManager(MagicMock())