openlp/openlp/core/ui/settingsform.py

183 lines
7.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2012-12-29 13:35:16 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2012-12-29 20:56:56 +00:00
# Copyright (c) 2008-2013 Raoul Snyman #
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
2012-11-11 21:16:14 +00:00
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
2012-10-21 13:16:22 +00:00
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2010-06-10 21:30:50 +00:00
"""
The :mod:`settingsform` provides a user interface for the OpenLP settings
"""
import logging
2013-01-18 23:31:02 +00:00
from PyQt4 import QtGui
2013-02-07 08:42:17 +00:00
from openlp.core.lib import PluginStatus, Registry, build_icon
2011-02-20 20:34:33 +00:00
from openlp.core.ui import AdvancedTab, GeneralTab, ThemesTab
from openlp.core.ui.media import PlayerTab
from settingsdialog import Ui_SettingsDialog
2010-03-04 22:09:03 +00:00
log = logging.getLogger(__name__)
2013-02-01 21:34:23 +00:00
2009-05-01 11:50:09 +00:00
class SettingsForm(QtGui.QDialog, Ui_SettingsDialog):
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-01-23 19:53:40 +00:00
Registry().register(u'settings_form', self)
2013-02-21 21:18:26 +00:00
Registry().register_function(u'bootstrap_post_set_up', self.post_set_up)
2009-10-19 14:56:44 +00:00
QtGui.QDialog.__init__(self, parent)
2013-03-10 20:19:42 +00:00
self.processes = []
self.setupUi(self)
2011-04-12 17:45:32 +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)
self.insert_tab(self.general_tab, 0, PluginStatus.Active)
self.insert_tab(self.themes_tab, 1, PluginStatus.Active)
self.insert_tab(self.advanced_tab, 2, PluginStatus.Active)
self.insert_tab(self.player_tab, 3, PluginStatus.Active)
count = 4
2013-02-18 20:41:08 +00:00
for plugin in self.plugin_manager.plugins:
if plugin.settingsTab:
2013-03-16 20:52:59 +00:00
self.insert_tab(plugin.settingsTab, count, plugin.status)
2011-04-14 18:30:53 +00:00
count += 1
2013-03-16 20:52:59 +00:00
self.setting_list_widget.setCurrentRow(0)
2011-04-12 17:45:32 +00:00
return QtGui.QDialog.exec_(self)
2013-03-16 20:52:59 +00:00
def insert_tab(self, tab, location, is_active):
2010-06-10 21:30:50 +00:00
"""
Add a tab to the form at a specific location
"""
2013-03-16 20:52:59 +00:00
log.debug(u'Inserting %s tab' % tab.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
2013-03-16 20:52:59 +00:00
pos = self.stacked_layout.addWidget(tab)
2011-04-14 18:30:53 +00:00
if is_active:
2013-03-16 20:52:59 +00:00
item_name = QtGui.QListWidgetItem(tab.tab_title_visible)
icon = build_icon(tab.icon_path)
2011-04-12 19:32:17 +00:00
item_name.setIcon(icon)
2013-03-16 20:52:59 +00:00
self.setting_list_widget.insertItem(location, item_name)
2011-04-14 18:30:53 +00:00
else:
2011-04-18 15:31:20 +00:00
# then remove tab to stop the UI displaying it even if
# it is not required.
2013-03-16 20:52:59 +00:00
self.stacked_layout.takeAt(pos)
def accept(self):
2010-06-10 21:30:50 +00:00
"""
Process the form saving the settings
"""
2013-03-16 20:52:59 +00:00
for tabIndex in range(self.stacked_layout.count()):
self.stacked_layout.widget(tabIndex).save()
# Must go after all settings are save
2013-03-10 20:19:42 +00:00
while self.processes:
Registry().execute(self.processes.pop(0))
2013-02-06 21:52:15 +00:00
Registry().execute(u'config_updated')
2009-08-06 13:17:36 +00:00
return QtGui.QDialog.accept(self)
2009-08-29 07:17:56 +00:00
def reject(self):
"""
Process the form saving the settings
"""
2013-03-10 20:19:42 +00:00
self.processes = []
2013-03-16 20:52:59 +00:00
for tabIndex in range(self.stacked_layout.count()):
self.stacked_layout.widget(tabIndex).cancel()
return QtGui.QDialog.reject(self)
2013-02-19 19:50:14 +00:00
def 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)
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:
if plugin.settingsTab:
2013-02-19 19:50:14 +00:00
plugin.settingsTab.post_set_up()
2013-03-16 20:52:59 +00:00
def tab_changed(self, tabIndex):
"""
A different settings tab is selected
"""
2013-03-16 20:52:59 +00:00
self.stacked_layout.setCurrentIndex(tabIndex)
2013-03-16 21:18:05 +00:00
self.stacked_layout.currentWidget().tab_visible()
2013-03-10 20:19:42 +00:00
def register_post_process(self, function):
"""
2013-03-10 20:19:42 +00:00
Register for updates to be done on save removing duplicate functions
``function``
The function to be called
"""
2013-03-10 20:19:42 +00:00
if not function in self.processes:
self.processes.append(function)
2013-01-23 19:53:40 +00:00
def _get_main_window(self):
"""
Adds the main window to the class dynamically
"""
if not hasattr(self, u'_main_window'):
self._main_window = Registry().get(u'main_window')
return self._main_window
main_window = property(_get_main_window)
def _get_service_manager(self):
"""
Adds the plugin manager to the class dynamically
"""
if not hasattr(self, u'_service_manager'):
self._service_manager = Registry().get(u'service_manager')
return self._service_manager
2013-02-05 08:05:28 +00:00
service_manager = property(_get_service_manager)
2013-02-18 20:41:08 +00:00
def _get_plugin_manager(self):
"""
Adds the plugin manager to the class dynamically
"""
if not hasattr(self, u'_plugin_manager'):
self._plugin_manager = Registry().get(u'plugin_manager')
return self._plugin_manager
plugin_manager = property(_get_plugin_manager)