2008-11-23 21:24:58 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-12-28 22:06:43 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
2009-07-14 13:51:27 +00:00
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2015-12-31 22:46:06 +00:00
|
|
|
# Copyright (c) 2008-2016 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 #
|
|
|
|
###############################################################################
|
2013-02-01 19:58:18 +00:00
|
|
|
"""
|
|
|
|
The :mod:`~openlp.core.lib.settingstab` module contains the base SettingsTab class which plugins use for adding their
|
|
|
|
own tab to the settings dialog.
|
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
|
2008-11-23 21:24:58 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
from PyQt5 import QtWidgets
|
2009-07-14 13:51:27 +00:00
|
|
|
|
2013-02-01 19:58:18 +00:00
|
|
|
|
2014-03-16 21:25:23 +00:00
|
|
|
from openlp.core.common import RegistryProperties
|
2013-02-01 20:09:47 +00:00
|
|
|
|
2013-03-16 16:59:10 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
class SettingsTab(QtWidgets.QWidget, RegistryProperties):
|
2009-02-28 07:23:48 +00:00
|
|
|
"""
|
2013-03-16 20:52:59 +00:00
|
|
|
SettingsTab is a helper widget for plugins to define Tabs for the settings dialog.
|
2009-02-28 07:23:48 +00:00
|
|
|
"""
|
2011-04-13 19:12:47 +00:00
|
|
|
def __init__(self, parent, title, visible_title=None, icon_path=None):
|
2009-02-28 07:23:48 +00:00
|
|
|
"""
|
2009-07-10 13:16:15 +00:00
|
|
|
Constructor to create the Settings tab item.
|
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param parent:
|
|
|
|
:param title: The title of the tab, which is used internally for the tab handling.
|
|
|
|
:param visible_title: The title of the tab, which is usually displayed on the tab.
|
|
|
|
:param icon_path:
|
2009-02-28 07:23:48 +00:00
|
|
|
"""
|
2013-07-18 11:23:59 +00:00
|
|
|
super(SettingsTab, self).__init__(parent)
|
2013-03-16 16:59:10 +00:00
|
|
|
self.tab_title = title
|
|
|
|
self.tab_title_visible = visible_title
|
|
|
|
self.settings_section = self.tab_title.lower()
|
2013-03-17 09:21:18 +00:00
|
|
|
self.tab_visited = False
|
2011-04-12 17:45:32 +00:00
|
|
|
if icon_path:
|
2013-03-16 16:59:10 +00:00
|
|
|
self.icon_path = icon_path
|
2015-02-14 09:12:35 +00:00
|
|
|
self._setup()
|
|
|
|
|
|
|
|
def _setup(self):
|
|
|
|
"""
|
|
|
|
Run some initial setup. This method is separate from __init__ in order to mock it out in tests.
|
|
|
|
"""
|
2009-02-28 23:19:45 +00:00
|
|
|
self.setupUi()
|
|
|
|
self.retranslateUi()
|
2009-05-01 11:50:09 +00:00
|
|
|
self.initialise()
|
2009-03-05 18:16:10 +00:00
|
|
|
self.load()
|
2009-04-15 04:58:51 +00:00
|
|
|
|
2009-02-28 23:19:45 +00:00
|
|
|
def setupUi(self):
|
2009-05-01 11:50:09 +00:00
|
|
|
"""
|
|
|
|
Setup the tab's interface.
|
|
|
|
"""
|
2015-11-07 00:49:40 +00:00
|
|
|
self.tab_layout = QtWidgets.QHBoxLayout(self)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.tab_layout.setObjectName('tab_layout')
|
2015-11-07 00:49:40 +00:00
|
|
|
self.left_column = QtWidgets.QWidget(self)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.left_column.setObjectName('left_column')
|
2015-11-07 00:49:40 +00:00
|
|
|
self.left_layout = QtWidgets.QVBoxLayout(self.left_column)
|
|
|
|
self.left_layout.setContentsMargins(0, 0, 0, 0)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.left_layout.setObjectName('left_layout')
|
2013-03-16 16:59:10 +00:00
|
|
|
self.tab_layout.addWidget(self.left_column)
|
2015-11-07 00:49:40 +00:00
|
|
|
self.right_column = QtWidgets.QWidget(self)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.right_column.setObjectName('right_column')
|
2015-11-07 00:49:40 +00:00
|
|
|
self.right_layout = QtWidgets.QVBoxLayout(self.right_column)
|
|
|
|
self.right_layout.setContentsMargins(0, 0, 0, 0)
|
2013-08-31 18:17:38 +00:00
|
|
|
self.right_layout.setObjectName('right_layout')
|
2013-03-16 16:59:10 +00:00
|
|
|
self.tab_layout.addWidget(self.right_column)
|
2011-01-03 11:25:30 +00:00
|
|
|
|
|
|
|
def resizeEvent(self, event=None):
|
|
|
|
"""
|
|
|
|
Resize the sides in two equal halves if the layout allows this.
|
|
|
|
"""
|
|
|
|
if event:
|
2015-11-07 00:49:40 +00:00
|
|
|
QtWidgets.QWidget.resizeEvent(self, event)
|
2013-03-16 16:59:10 +00:00
|
|
|
width = self.width() - self.tab_layout.spacing() - \
|
|
|
|
self.tab_layout.contentsMargins().left() - self.tab_layout.contentsMargins().right()
|
2013-04-24 20:47:30 +00:00
|
|
|
left_width = min(width - self.right_column.minimumSizeHint().width(), width // 2)
|
2013-03-16 16:59:10 +00:00
|
|
|
left_width = max(left_width, self.left_column.minimumSizeHint().width())
|
|
|
|
self.left_column.setFixedWidth(left_width)
|
2009-02-28 23:19:45 +00:00
|
|
|
|
|
|
|
def retranslateUi(self):
|
2009-05-01 11:50:09 +00:00
|
|
|
"""
|
|
|
|
Setup the interface translation strings.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def initialise(self):
|
|
|
|
"""
|
|
|
|
Do any extra initialisation here.
|
|
|
|
"""
|
2009-02-28 23:19:45 +00:00
|
|
|
pass
|
2009-04-15 04:58:51 +00:00
|
|
|
|
2009-03-01 20:21:57 +00:00
|
|
|
def load(self):
|
2009-05-01 11:50:09 +00:00
|
|
|
"""
|
|
|
|
Load settings from disk.
|
|
|
|
"""
|
2009-03-01 20:21:57 +00:00
|
|
|
pass
|
2009-04-15 04:58:51 +00:00
|
|
|
|
2009-03-01 20:21:57 +00:00
|
|
|
def save(self):
|
2009-05-01 11:50:09 +00:00
|
|
|
"""
|
|
|
|
Save settings to disk.
|
|
|
|
"""
|
2009-03-01 20:21:57 +00:00
|
|
|
pass
|
2009-08-29 07:17:56 +00:00
|
|
|
|
2010-12-23 17:42:28 +00:00
|
|
|
def cancel(self):
|
|
|
|
"""
|
2012-04-02 00:19:16 +00:00
|
|
|
Reset any settings if cancel triggered
|
2010-12-23 17:42:28 +00:00
|
|
|
"""
|
2011-05-15 15:52:20 +00:00
|
|
|
self.load()
|
2010-12-23 17:42:28 +00:00
|
|
|
|
2013-12-24 08:56:50 +00:00
|
|
|
def post_set_up(self, post_update=False):
|
2009-08-29 07:17:56 +00:00
|
|
|
"""
|
|
|
|
Changes which need to be made after setup of application
|
2010-12-02 14:37:38 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param post_update: Indicates if called before or after updates.
|
2009-08-29 07:17:56 +00:00
|
|
|
"""
|
2010-12-27 22:57:35 +00:00
|
|
|
pass
|
2011-12-11 21:59:10 +00:00
|
|
|
|
2013-03-16 16:59:10 +00:00
|
|
|
def tab_visible(self):
|
2011-12-11 21:59:10 +00:00
|
|
|
"""
|
|
|
|
Tab has just been made visible to the user
|
|
|
|
"""
|
2013-03-17 09:21:18 +00:00
|
|
|
self.tab_visited = True
|