2008-11-28 14:05:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-12-29 13:35:16 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
2008-11-28 14:05:41 +00:00
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2015-01-18 13:39:21 +00:00
|
|
|
# Copyright (c) 2008-2015 OpenLP Developers #
|
2009-09-08 19:58:05 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2010-06-10 21:30:50 +00:00
|
|
|
"""
|
|
|
|
The :mod:`settingsform` provides a user interface for the OpenLP settings
|
|
|
|
"""
|
2009-02-28 23:19:45 +00:00
|
|
|
import logging
|
2008-11-28 14:05:41 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
from PyQt5 import QtCore, QtWidgets
|
2008-11-28 14:05:41 +00:00
|
|
|
|
2014-03-16 21:25:23 +00:00
|
|
|
from openlp.core.common import Registry, RegistryProperties
|
2014-10-25 20:26:19 +00:00
|
|
|
from openlp.core.lib import build_icon
|
2011-02-20 20:34:33 +00:00
|
|
|
from openlp.core.ui import AdvancedTab, GeneralTab, ThemesTab
|
2012-09-09 06:27:53 +00:00
|
|
|
from openlp.core.ui.media import PlayerTab
|
2013-08-31 18:17:38 +00:00
|
|
|
from .settingsdialog import Ui_SettingsDialog
|
2014-10-06 19:10:03 +00:00
|
|
|
from openlp.core.ui.projector.tab import ProjectorTab
|
2009-02-28 23:19:45 +00:00
|
|
|
|
2010-03-04 22:09:03 +00:00
|
|
|
log = logging.getLogger(__name__)
|
2009-02-28 23:19:45 +00:00
|
|
|
|
2013-02-01 21:34:23 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
class SettingsForm(QtWidgets.QDialog, Ui_SettingsDialog, RegistryProperties):
|
2010-06-10 21:30:50 +00:00
|
|
|
"""
|
|
|
|
Provide the form to manipulate the settings for OpenLP
|
|
|
|
"""
|
2013-01-23 19:53:40 +00:00
|
|
|
def __init__(self, parent=None):
|
2010-06-10 21:30:50 +00:00
|
|
|
"""
|
|
|
|
Initialise the settings form
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
Registry().register('settings_form', self)
|
2013-12-31 20:29:03 +00:00
|
|
|
Registry().register_function('bootstrap_post_set_up', self.bootstrap_post_set_up)
|
2013-07-18 14:19:01 +00:00
|
|
|
super(SettingsForm, self).__init__(parent)
|
2013-03-10 20:19:42 +00:00
|
|
|
self.processes = []
|
2009-02-28 23:19:45 +00:00
|
|
|
self.setupUi(self)
|
2014-10-25 20:26:19 +00:00
|
|
|
self.setting_list_widget.currentRowChanged.connect(self.list_item_changed)
|
2014-10-30 22:53:06 +00:00
|
|
|
self.general_tab = None
|
|
|
|
self.themes_tab = None
|
|
|
|
self.projector_tab = None
|
|
|
|
self.advanced_tab = None
|
|
|
|
self.player_tab = None
|
2011-04-12 17:45:32 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
def exec(self):
|
2013-02-01 21:34:23 +00:00
|
|
|
"""
|
|
|
|
Execute the form
|
|
|
|
"""
|
2011-04-12 17:45:32 +00:00
|
|
|
# load all the settings
|
2013-03-16 20:52:59 +00:00
|
|
|
self.setting_list_widget.clear()
|
|
|
|
while self.stacked_layout.count():
|
2011-10-11 19:54:18 +00:00
|
|
|
# take at 0 and the rest shuffle up.
|
2013-03-16 20:52:59 +00:00
|
|
|
self.stacked_layout.takeAt(0)
|
2014-10-25 20:26:19 +00:00
|
|
|
self.insert_tab(self.general_tab)
|
|
|
|
self.insert_tab(self.themes_tab)
|
|
|
|
self.insert_tab(self.advanced_tab)
|
|
|
|
self.insert_tab(self.player_tab)
|
2014-10-28 20:45:53 +00:00
|
|
|
self.insert_tab(self.projector_tab)
|
2013-02-18 20:41:08 +00:00
|
|
|
for plugin in self.plugin_manager.plugins:
|
2013-03-19 19:43:22 +00:00
|
|
|
if plugin.settings_tab:
|
2014-10-25 20:26:19 +00:00
|
|
|
self.insert_tab(plugin.settings_tab, plugin.is_active())
|
2013-03-16 20:52:59 +00:00
|
|
|
self.setting_list_widget.setCurrentRow(0)
|
2015-11-07 00:49:40 +00:00
|
|
|
return QtWidgets.QDialog.exec(self)
|
2009-02-28 23:19:45 +00:00
|
|
|
|
2014-10-25 20:26:19 +00:00
|
|
|
def insert_tab(self, tab_widget, is_visible=True):
|
2010-06-10 21:30:50 +00:00
|
|
|
"""
|
|
|
|
Add a tab to the form at a specific location
|
2014-10-25 20:26:19 +00:00
|
|
|
|
|
|
|
:param tab_widget: The widget to add
|
|
|
|
:param is_visible: If this tab should be visible
|
2010-06-10 21:30:50 +00:00
|
|
|
"""
|
2014-10-25 20:26:19 +00:00
|
|
|
log.debug('Inserting %s tab' % tab_widget.tab_title)
|
2011-04-18 15:31:20 +00:00
|
|
|
# add the tab to get it to display in the correct part of the screen
|
2014-10-25 20:26:19 +00:00
|
|
|
self.stacked_layout.addWidget(tab_widget)
|
|
|
|
if is_visible:
|
2015-11-07 00:49:40 +00:00
|
|
|
list_item = QtWidgets.QListWidgetItem(build_icon(tab_widget.icon_path), tab_widget.tab_title_visible)
|
2014-10-25 20:26:19 +00:00
|
|
|
list_item.setData(QtCore.Qt.UserRole, tab_widget.tab_title)
|
|
|
|
self.setting_list_widget.addItem(list_item)
|
2008-11-28 14:05:41 +00:00
|
|
|
|
2009-03-01 20:21:57 +00:00
|
|
|
def accept(self):
|
2010-06-10 21:30:50 +00:00
|
|
|
"""
|
|
|
|
Process the form saving the settings
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
log.debug('Processing settings exit')
|
2014-10-28 19:40:01 +00:00
|
|
|
# We add all the forms into the stacked layout, even if the plugin is inactive,
|
|
|
|
# but we don't add the item to the list on the side if the plugin is inactive,
|
|
|
|
# so loop through the list items, and then find the tab for that item.
|
|
|
|
for item_index in range(self.setting_list_widget.count()):
|
|
|
|
# Get the list item
|
|
|
|
list_item = self.setting_list_widget.item(item_index)
|
|
|
|
if not list_item:
|
|
|
|
continue
|
|
|
|
# Now figure out if there's a tab for it, and save the tab.
|
|
|
|
plugin_name = list_item.data(QtCore.Qt.UserRole)
|
|
|
|
for tab_index in range(self.stacked_layout.count()):
|
|
|
|
tab_widget = self.stacked_layout.widget(tab_index)
|
|
|
|
if tab_widget.tab_title == plugin_name:
|
|
|
|
tab_widget.save()
|
|
|
|
# if the image background has been changed we need to regenerate the image cache
|
2013-08-31 18:17:38 +00:00
|
|
|
if 'images_config_updated' in self.processes or 'config_screen_changed' in self.processes:
|
|
|
|
self.register_post_process('images_regenerate')
|
2013-03-17 09:21:18 +00:00
|
|
|
# Now lets process all the post save handlers
|
2013-03-10 20:19:42 +00:00
|
|
|
while self.processes:
|
|
|
|
Registry().execute(self.processes.pop(0))
|
2015-11-07 00:49:40 +00:00
|
|
|
return QtWidgets.QDialog.accept(self)
|
2009-08-29 07:17:56 +00:00
|
|
|
|
2010-12-23 17:42:28 +00:00
|
|
|
def reject(self):
|
|
|
|
"""
|
|
|
|
Process the form saving the settings
|
|
|
|
"""
|
2013-03-10 20:19:42 +00:00
|
|
|
self.processes = []
|
2014-10-30 22:53:06 +00:00
|
|
|
# Same as accept(), we need to loop over the visible tabs, and skip the inactive ones
|
|
|
|
for item_index in range(self.setting_list_widget.count()):
|
|
|
|
# Get the list item
|
|
|
|
list_item = self.setting_list_widget.item(item_index)
|
|
|
|
if not list_item:
|
|
|
|
continue
|
|
|
|
# Now figure out if there's a tab for it, and save the tab.
|
|
|
|
plugin_name = list_item.data(QtCore.Qt.UserRole)
|
|
|
|
for tab_index in range(self.stacked_layout.count()):
|
|
|
|
tab_widget = self.stacked_layout.widget(tab_index)
|
|
|
|
if tab_widget.tab_title == plugin_name:
|
|
|
|
tab_widget.cancel()
|
2015-11-07 00:49:40 +00:00
|
|
|
return QtWidgets.QDialog.reject(self)
|
2010-12-23 17:42:28 +00:00
|
|
|
|
2013-12-31 20:29:03 +00:00
|
|
|
def bootstrap_post_set_up(self):
|
2010-06-10 21:30:50 +00:00
|
|
|
"""
|
|
|
|
Run any post-setup code for the tabs on the form
|
|
|
|
"""
|
2013-03-10 20:19:42 +00:00
|
|
|
# General tab
|
2013-03-16 20:52:59 +00:00
|
|
|
self.general_tab = GeneralTab(self)
|
2013-03-10 20:19:42 +00:00
|
|
|
# Themes tab
|
2013-03-16 20:52:59 +00:00
|
|
|
self.themes_tab = ThemesTab(self)
|
2014-10-06 19:10:03 +00:00
|
|
|
# Projector Tab
|
|
|
|
self.projector_tab = ProjectorTab(self)
|
2013-03-10 20:19:42 +00:00
|
|
|
# Advanced tab
|
2013-03-16 20:52:59 +00:00
|
|
|
self.advanced_tab = AdvancedTab(self)
|
2013-03-10 20:19:42 +00:00
|
|
|
# Advanced tab
|
2013-03-16 20:52:59 +00:00
|
|
|
self.player_tab = PlayerTab(self)
|
|
|
|
self.general_tab.post_set_up()
|
|
|
|
self.themes_tab.post_set_up()
|
|
|
|
self.advanced_tab.post_set_up()
|
|
|
|
self.player_tab.post_set_up()
|
2013-02-18 20:41:08 +00:00
|
|
|
for plugin in self.plugin_manager.plugins:
|
2013-03-19 19:43:22 +00:00
|
|
|
if plugin.settings_tab:
|
|
|
|
plugin.settings_tab.post_set_up()
|
2011-12-11 21:59:10 +00:00
|
|
|
|
2014-10-25 20:26:19 +00:00
|
|
|
def list_item_changed(self, item_index):
|
2011-12-11 21:59:10 +00:00
|
|
|
"""
|
|
|
|
A different settings tab is selected
|
2014-10-25 20:26:19 +00:00
|
|
|
|
|
|
|
:param item_index: The index of the item that was selected
|
|
|
|
"""
|
|
|
|
# Get the item we clicked on
|
|
|
|
list_item = self.setting_list_widget.item(item_index)
|
2014-10-28 19:02:06 +00:00
|
|
|
# Quick exit to the left if the item doesn't exist (maybe -1?)
|
|
|
|
if not list_item:
|
|
|
|
return
|
2014-10-25 20:26:19 +00:00
|
|
|
# Loop through the list of tabs in the stacked layout
|
|
|
|
for tab_index in range(self.stacked_layout.count()):
|
|
|
|
# Get the widget
|
|
|
|
tab_widget = self.stacked_layout.itemAt(tab_index).widget()
|
|
|
|
# Check that the title of the tab (i.e. plugin name) is the same as the data in the list item
|
|
|
|
if tab_widget.tab_title == list_item.data(QtCore.Qt.UserRole):
|
|
|
|
# Make the matching tab visible
|
|
|
|
self.stacked_layout.setCurrentIndex(tab_index)
|
|
|
|
self.stacked_layout.currentWidget().tab_visible()
|
2012-10-07 07:25:55 +00:00
|
|
|
|
2013-03-10 20:19:42 +00:00
|
|
|
def register_post_process(self, function):
|
2012-10-07 07:25:55 +00:00
|
|
|
"""
|
2013-03-10 20:19:42 +00:00
|
|
|
Register for updates to be done on save removing duplicate functions
|
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param function: The function to be called
|
2012-10-07 07:25:55 +00:00
|
|
|
"""
|
2014-04-12 20:19:22 +00:00
|
|
|
if function not in self.processes:
|
2014-03-20 19:10:31 +00:00
|
|
|
self.processes.append(function)
|