openlp/openlp/core/ui/settingsform.py

117 lines
4.9 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2010-12-26 11:04:47 +00:00
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
2011-03-24 19:04:02 +00:00
# Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, Armin Köhler, #
# Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
# --------------------------------------------------------------------------- #
# 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
2011-04-12 17:45:32 +00:00
from PyQt4 import QtGui, QtCore
2011-04-14 18:30:53 +00:00
from openlp.core.lib import Receiver, build_icon, PluginStatus
2011-02-20 20:34:33 +00:00
from openlp.core.ui import AdvancedTab, GeneralTab, ThemesTab
from settingsdialog import Ui_SettingsDialog
2010-03-04 22:09:03 +00:00
log = logging.getLogger(__name__)
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
"""
2010-04-02 18:12:54 +00:00
def __init__(self, screens, mainWindow, parent=None):
2010-06-10 21:30:50 +00:00
"""
Initialise the settings form
"""
2009-10-19 14:56:44 +00:00
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
# General tab
2011-04-14 18:30:53 +00:00
self.generalTab = GeneralTab(self, screens)
# Themes tab
2011-04-14 18:30:53 +00:00
self.themesTab = ThemesTab(self, mainWindow)
2010-07-09 21:32:32 +00:00
# Advanced tab
2011-04-14 18:30:53 +00:00
self.advancedTab = AdvancedTab(self)
2011-04-12 17:45:32 +00:00
def exec_(self):
# load all the settings
2011-04-14 18:30:53 +00:00
self.settingListWidget.clear()
for tabIndex in range(0, self.stackedLayout.count() + 1):
# take at 0 and the rest shuffell up.
self.stackedLayout.takeAt(0)
self.insertTab(self.generalTab, 0, PluginStatus.Active)
self.insertTab(self.themesTab, 1, PluginStatus.Active)
self.insertTab(self.advancedTab, 2, PluginStatus.Active)
count = 3
for plugin in self.plugins:
if plugin.settings_tab:
self.insertTab(plugin.settings_tab, count, plugin.status)
count += 1
2011-04-13 18:40:09 +00:00
self.settingListWidget.setCurrentRow(0)
2011-04-12 17:45:32 +00:00
return QtGui.QDialog.exec_(self)
2011-04-14 18:30:53 +00:00
def insertTab(self, tab, location, is_active):
2010-06-10 21:30:50 +00:00
"""
Add a tab to the form at a specific location
"""
2009-10-28 21:52:13 +00:00
log.debug(u'Inserting %s tab' % tab.tabTitle)
2011-04-14 18:30:53 +00:00
pos = self.stackedLayout.addWidget(tab)
if is_active:
2011-04-12 19:32:17 +00:00
item_name = QtGui.QListWidgetItem(tab.tabTitleVisible)
icon = build_icon(tab.icon_path)
item_name.setIcon(icon)
2011-04-14 18:30:53 +00:00
self.settingListWidget.insertItem(location, item_name)
else:
# add then remove tab to stop th UI displaying it even if
# it is not required.
self.stackedLayout.takeAt(pos)
def accept(self):
2010-06-10 21:30:50 +00:00
"""
Process the form saving the settings
"""
2011-04-12 19:32:17 +00:00
for tabIndex in range(0, self.stackedLayout.count()):
self.stackedLayout.widget(tabIndex).save()
# Must go after all settings are save
Receiver.send_message(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
"""
2011-04-12 19:32:17 +00:00
for tabIndex in range(0, self.stackedLayout.count()):
self.stackedLayout.widget(tabIndex).cancel()
return QtGui.QDialog.reject(self)
2009-08-29 07:17:56 +00:00
def postSetUp(self):
2010-06-10 21:30:50 +00:00
"""
Run any post-setup code for the tabs on the form
"""
2011-04-14 18:55:41 +00:00
self.generalTab.postSetUp()
self.themesTab.postSetUp()
self.advancedTab.postSetUp()
for plugin in self.plugins:
if plugin.settings_tab:
plugin.settings_tab.postSetUp()