openlp/openlp/core/lib/settingstab.py

134 lines
4.9 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-02-01 10:10:57 +00:00
# Copyright (c) 2008-2022 OpenLP Developers #
2019-04-13 13:00:22 +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, either version 3 of the License, or #
# (at your option) any later version. #
# #
# 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, see <https://www.gnu.org/licenses/>. #
##########################################################################
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.
"""
2015-11-07 00:49:40 +00:00
from PyQt5 import QtWidgets
2017-10-23 22:09:57 +00:00
from openlp.core.common.mixins 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):
"""
2013-03-16 20:52:59 +00:00
SettingsTab is a helper widget for plugins to define Tabs for the settings dialog.
"""
2011-04-13 19:12:47 +00:00
def __init__(self, parent, title, visible_title=None, icon_path=None):
"""
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:
"""
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
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.
"""
self.setup_ui()
self.retranslate_ui()
2009-05-01 11:50:09 +00:00
self.initialise()
self.load()
def setup_ui(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)
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)
def retranslate_ui(self):
2009-05-01 11:50:09 +00:00
"""
Setup the interface translation strings.
"""
pass
def initialise(self):
"""
Do any extra initialisation here.
"""
pass
def load(self):
2009-05-01 11:50:09 +00:00
"""
Load settings from disk.
"""
pass
def save(self):
2009-05-01 11:50:09 +00:00
"""
Save settings to disk.
"""
pass
2009-08-29 07:17:56 +00:00
def cancel(self):
"""
Reset any settings if cancel triggered
"""
self.load()
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
"""
pass
2013-03-16 16:59:10 +00:00
def tab_visible(self):
"""
Tab has just been made visible to the user
"""
pass