openlp/openlp/core/ui/themestab.py

212 lines
11 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2012-12-29 15:25:29 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2013-12-24 08:56:50 +00:00
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 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 #
###############################################################################
2013-02-01 21:34:23 +00:00
"""
The Themes configuration tab
"""
2013-08-31 18:17:38 +00:00
2013-04-24 19:05:34 +00:00
from PyQt4 import QtCore, QtGui
2013-12-13 17:44:05 +00:00
from openlp.core.common import Registry, Settings, ThemeLevel, UiStrings, translate
from openlp.core.lib import SettingsTab
from openlp.core.lib.ui import find_and_set_in_combo_box
class ThemesTab(SettingsTab):
"""
ThemesTab is the theme settings tab in the settings dialog.
"""
2013-03-16 21:18:05 +00:00
def __init__(self, parent):
2013-02-01 21:34:23 +00:00
"""
Constructor
"""
2013-08-31 18:17:38 +00:00
self.icon_path = ':/themes/theme_new.png'
2013-03-16 16:59:10 +00:00
theme_translated = translate('OpenLP.ThemesTab', 'Themes')
2013-08-31 18:17:38 +00:00
super(ThemesTab, self).__init__(parent, 'Themes', theme_translated)
def setupUi(self):
2013-02-01 21:34:23 +00:00
"""
Set up the UI
"""
2013-08-31 18:17:38 +00:00
self.setObjectName('ThemesTab')
2013-07-18 19:10:19 +00:00
super(ThemesTab, self).setupUi()
2013-03-16 16:59:10 +00:00
self.global_group_box = QtGui.QGroupBox(self.left_column)
2013-08-31 18:17:38 +00:00
self.global_group_box.setObjectName('global_group_box')
2013-03-16 16:59:10 +00:00
self.global_group_box_layout = QtGui.QVBoxLayout(self.global_group_box)
2013-08-31 18:17:38 +00:00
self.global_group_box_layout.setObjectName('global_group_box_layout')
2013-03-16 16:59:10 +00:00
self.default_combo_box = QtGui.QComboBox(self.global_group_box)
self.default_combo_box.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToMinimumContentsLength)
self.default_combo_box.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
2013-08-31 18:17:38 +00:00
self.default_combo_box.setObjectName('default_combo_box')
2013-03-16 16:59:10 +00:00
self.global_group_box_layout.addWidget(self.default_combo_box)
self.default_list_view = QtGui.QLabel(self.global_group_box)
2013-08-31 18:17:38 +00:00
self.default_list_view.setObjectName('default_list_view')
2013-03-16 16:59:10 +00:00
self.global_group_box_layout.addWidget(self.default_list_view)
self.left_layout.addWidget(self.global_group_box)
self.left_layout.addStretch()
self.level_group_box = QtGui.QGroupBox(self.right_column)
2013-08-31 18:17:38 +00:00
self.level_group_box.setObjectName('level_group_box')
2013-03-16 16:59:10 +00:00
self.level_layout = QtGui.QFormLayout(self.level_group_box)
2013-03-16 21:18:05 +00:00
self.level_layout.setLabelAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
2013-03-16 16:59:10 +00:00
self.level_layout.setFormAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
2013-08-31 18:17:38 +00:00
self.level_layout.setObjectName('level_layout')
2013-03-16 21:18:05 +00:00
self.song_level_radio_button = QtGui.QRadioButton(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.song_level_radio_button.setObjectName('song_level_radio_button')
2013-03-16 16:59:10 +00:00
self.song_level_label = QtGui.QLabel(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.song_level_label.setObjectName('song_level_label')
2013-03-16 16:59:10 +00:00
self.level_layout.addRow(self.song_level_radio_button, self.song_level_label)
2013-03-16 21:18:05 +00:00
self.service_level_radio_button = QtGui.QRadioButton(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.service_level_radio_button.setObjectName('service_level_radio_button')
2013-03-16 16:59:10 +00:00
self.service_level_label = QtGui.QLabel(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.service_level_label.setObjectName('service_level_label')
2013-03-16 16:59:10 +00:00
self.level_layout.addRow(self.service_level_radio_button, self.service_level_label)
2013-03-16 21:18:05 +00:00
self.global_level_radio_button = QtGui.QRadioButton(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.global_level_radio_button.setObjectName('global_level_radio_button')
2013-03-16 16:59:10 +00:00
self.global_level_label = QtGui.QLabel(self.level_group_box)
2013-08-31 18:17:38 +00:00
self.global_level_label.setObjectName('global_level_label')
2013-03-16 16:59:10 +00:00
self.level_layout.addRow(self.global_level_radio_button, self.global_level_label)
label_top_margin = (self.song_level_radio_button.sizeHint().height() -
2013-12-26 17:36:00 +00:00
self.song_level_label.sizeHint().height()) // 2
2013-03-16 16:59:10 +00:00
for label in [self.song_level_label, self.service_level_label, self.global_level_label]:
rect = label.rect()
rect.setTop(rect.top() + label_top_margin)
label.setFrameRect(rect)
label.setWordWrap(True)
2013-03-16 16:59:10 +00:00
self.right_layout.addWidget(self.level_group_box)
self.right_layout.addStretch()
self.song_level_radio_button.clicked.connect(self.on_song_level_button_clicked)
2013-03-16 21:18:05 +00:00
self.service_level_radio_button.clicked.connect(self.on_service_level_button_clicked)
self.global_level_radio_button.clicked.connect(self.on_global_level_button_clicked)
2013-03-16 16:59:10 +00:00
self.default_combo_box.activated.connect(self.on_default_combo_box_changed)
2013-08-31 18:17:38 +00:00
Registry().register_function('theme_update_list', self.update_theme_list)
def retranslateUi(self):
2013-02-01 21:34:23 +00:00
"""
Translate the UI on the fly
"""
2013-03-16 16:59:10 +00:00
self.tab_title_visible = UiStrings().Themes
self.global_group_box.setTitle(translate('OpenLP.ThemesTab', 'Global Theme'))
self.level_group_box.setTitle(translate('OpenLP.ThemesTab', 'Theme Level'))
self.song_level_radio_button.setText(translate('OpenLP.ThemesTab', 'S&ong Level'))
self.song_level_label.setText(translate('OpenLP.ThemesTab', 'Use the theme from each song '
2013-12-26 17:36:00 +00:00
'in the database. If a song doesn\'t have a theme associated with '
'it, then use the service\'s theme. If the service doesn\'t have '
'a theme, then use the global theme.'))
2013-03-16 16:59:10 +00:00
self.service_level_radio_button.setText(translate('OpenLP.ThemesTab', '&Service Level'))
self.service_level_label.setText(translate('OpenLP.ThemesTab', 'Use the theme from the service, '
2013-12-26 17:36:00 +00:00
'overriding any of the individual songs\' themes. If the '
'service doesn\'t have a theme, then use the global theme.'))
2013-03-16 16:59:10 +00:00
self.global_level_radio_button.setText(translate('OpenLP.ThemesTab', '&Global Level'))
self.global_level_label.setText(translate('OpenLP.ThemesTab', 'Use the global theme, overriding '
2013-12-26 17:36:00 +00:00
'any themes associated with either the service or the songs.'))
2009-05-16 16:38:03 +00:00
def load(self):
2013-02-01 21:34:23 +00:00
"""
Load the theme settings into the tab
"""
2012-05-17 15:13:09 +00:00
settings = Settings()
2013-03-16 21:18:05 +00:00
settings.beginGroup(self.settings_section)
2013-08-31 18:17:38 +00:00
self.theme_level = settings.value('theme level')
self.global_theme = settings.value('global theme')
2010-04-28 14:17:42 +00:00
settings.endGroup()
if self.theme_level == ThemeLevel.Global:
2013-03-16 16:59:10 +00:00
self.global_level_radio_button.setChecked(True)
elif self.theme_level == ThemeLevel.Service:
2013-03-16 16:59:10 +00:00
self.service_level_radio_button.setChecked(True)
else:
2013-03-16 16:59:10 +00:00
self.song_level_radio_button.setChecked(True)
def save(self):
2013-02-01 21:34:23 +00:00
"""
Save the settings
"""
2012-05-17 15:13:09 +00:00
settings = Settings()
2013-03-16 21:18:05 +00:00
settings.beginGroup(self.settings_section)
2013-08-31 18:17:38 +00:00
settings.setValue('theme level', self.theme_level)
settings.setValue('global theme', self.global_theme)
2010-04-28 14:17:42 +00:00
settings.endGroup()
2013-02-01 20:09:47 +00:00
self.renderer.set_theme_level(self.theme_level)
2013-03-17 09:21:18 +00:00
if self.tab_visited:
2013-08-31 18:17:38 +00:00
self.settings_form.register_post_process('theme_update_global')
2013-03-17 09:21:18 +00:00
self.tab_visited = False
2009-08-29 07:17:56 +00:00
2013-03-16 21:18:05 +00:00
def on_song_level_button_clicked(self):
2013-02-01 21:34:23 +00:00
"""
Set the theme level
"""
self.theme_level = ThemeLevel.Song
2013-03-16 21:18:05 +00:00
def on_service_level_button_clicked(self):
2013-02-01 21:34:23 +00:00
"""
Set the theme level
"""
self.theme_level = ThemeLevel.Service
2013-03-16 21:18:05 +00:00
def on_global_level_button_clicked(self):
2013-02-01 21:34:23 +00:00
"""
Set the theme level
"""
self.theme_level = ThemeLevel.Global
2013-03-16 16:59:10 +00:00
def on_default_combo_box_changed(self, value):
2013-02-01 21:34:23 +00:00
"""
Set the global default theme
"""
2013-03-16 16:59:10 +00:00
self.global_theme = self.default_combo_box.currentText()
2013-03-14 20:21:04 +00:00
self.renderer.set_global_theme()
2013-03-25 07:27:54 +00:00
self._preview_global_theme()
2013-02-07 11:33:47 +00:00
def update_theme_list(self, theme_list):
2009-05-16 16:38:03 +00:00
"""
Called from ThemeManager when the Themes have changed.
2014-03-17 19:05:55 +00:00
:param theme_list: The list of available themes::
2010-11-13 20:13:24 +00:00
[u'Bible Theme', u'Song Theme']
2009-05-16 16:38:03 +00:00
"""
# Reload as may have been triggered by the ThemeManager.
2013-08-31 18:17:38 +00:00
self.global_theme = Settings().value(self.settings_section + '/global theme')
2013-03-16 16:59:10 +00:00
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)
2013-03-14 20:21:04 +00:00
self.renderer.set_global_theme()
2013-02-01 20:09:47 +00:00
self.renderer.set_theme_level(self.theme_level)
2013-08-31 18:17:38 +00:00
if self.global_theme is not '':
2013-03-16 16:59:10 +00:00
self._preview_global_theme()
2011-02-01 00:33:50 +00:00
2013-03-16 16:59:10 +00:00
def _preview_global_theme(self):
2011-02-01 00:33:50 +00:00
"""
Utility method to update the global theme preview image.
"""
2013-02-02 07:08:28 +00:00
image = self.theme_manager.get_preview_image(self.global_theme)
2013-08-31 18:17:38 +00:00
preview = QtGui.QPixmap(str(image))
2011-02-01 00:33:50 +00:00
if not preview.isNull():
2012-12-29 15:25:29 +00:00
preview = preview.scaled(300, 255, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
2013-03-16 16:59:10 +00:00
self.default_list_view.setPixmap(preview)