openlp/openlp/core/ui/pluginform.py

153 lines
7.0 KiB
Python
Raw Normal View History

2009-10-06 21:07:12 +00:00
# -*- coding: utf-8 -*-
2012-12-29 13:35:16 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
2009-10-06 21:07:12 +00:00
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2019 OpenLP Developers #
# ---------------------------------------------------------------------- #
# 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 20:52:42 +00:00
"""
The actual plugin view form
"""
2009-10-06 21:07:12 +00:00
import logging
from PyQt5 import QtCore, QtWidgets
2009-10-06 21:07:12 +00:00
from openlp.core.state import State
2017-10-07 07:05:07 +00:00
from openlp.core.common.i18n import translate
2017-10-23 22:09:57 +00:00
from openlp.core.common.mixins import RegistryProperties
from openlp.core.lib.plugin import PluginStatus
2017-10-07 07:05:07 +00:00
from openlp.core.ui.plugindialog import Ui_PluginViewDialog
2009-10-06 21:07:12 +00:00
2018-10-02 04:39:42 +00:00
2010-02-27 15:31:23 +00:00
log = logging.getLogger(__name__)
2013-02-01 20:52:42 +00:00
2015-11-07 00:49:40 +00:00
class PluginForm(QtWidgets.QDialog, Ui_PluginViewDialog, RegistryProperties):
2011-02-07 15:55:02 +00:00
"""
The plugin form provides user control over the plugins OpenLP uses.
"""
2009-10-06 21:07:12 +00:00
def __init__(self, parent=None):
2013-02-01 20:52:42 +00:00
"""
Constructor
"""
super(PluginForm, self).__init__(parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint |
QtCore.Qt.WindowCloseButtonHint)
2013-12-24 15:55:01 +00:00
self.active_plugin = None
2019-01-01 16:04:37 +00:00
self.programmatic_change = False
self.setup_ui(self)
2009-10-06 21:07:12 +00:00
self.load()
2013-12-24 15:55:01 +00:00
self._clear_details()
2009-10-06 21:07:12 +00:00
# Right, now let's put some signals and slots together!
2013-12-24 20:45:29 +00:00
self.plugin_list_widget.itemSelectionChanged.connect(self.on_plugin_list_widget_selection_changed)
self.status_checkbox.stateChanged.connect(self.on_status_checkbox_changed)
2009-10-06 21:07:12 +00:00
def load(self):
"""
Load the plugin details into the screen
"""
2013-12-24 20:45:29 +00:00
self.plugin_list_widget.clear()
2019-01-01 16:04:37 +00:00
self.programmatic_change = True
2013-12-24 15:55:01 +00:00
self._clear_details()
2019-01-01 16:04:37 +00:00
self.programmatic_change = True
2013-12-24 15:55:01 +00:00
plugin_list_width = 0
for plugin in State().list_plugins():
2019-01-01 16:04:37 +00:00
if plugin:
item = QtWidgets.QListWidgetItem(self.plugin_list_widget)
# We do this just to make 100% sure the status is an integer as
# sometimes when it's loaded from the config, it isn't cast to int.
plugin.status = int(plugin.status)
# Set the little status text in brackets next to the plugin name.
if plugin.status == PluginStatus.Disabled:
status_text = translate('OpenLP.PluginForm', '{name} (Disabled)')
elif plugin.status == PluginStatus.Active:
status_text = translate('OpenLP.PluginForm', '{name} (Active)')
else:
# PluginStatus.Inactive
status_text = translate('OpenLP.PluginForm', '{name} (Inactive)')
item.setText(status_text.format(name=plugin.name_strings['singular']))
# If the plugin has an icon, set it!
if plugin.icon:
item.setIcon(plugin.icon)
self.plugin_list_widget.addItem(item)
plugin_list_width = max(plugin_list_width, self.fontMetrics().width(
translate('OpenLP.PluginForm', '{name} (Inactive)').format(name=plugin.name_strings['singular'])))
2013-12-24 20:45:29 +00:00
self.plugin_list_widget.setFixedWidth(plugin_list_width + self.plugin_list_widget.iconSize().width() + 48)
2009-10-06 21:07:12 +00:00
2013-12-24 15:55:01 +00:00
def _clear_details(self):
2013-02-01 20:52:42 +00:00
"""
Clear the plugin details widgets
"""
self.status_checkbox.setChecked(False)
2013-12-24 20:45:29 +00:00
self.about_text_browser.setHtml('')
self.status_checkbox.setEnabled(False)
2009-10-06 21:07:12 +00:00
2013-12-24 15:55:01 +00:00
def _set_details(self):
2013-02-01 20:52:42 +00:00
"""
Set the details of the currently selected plugin
"""
2016-05-20 16:22:06 +00:00
log.debug('PluginStatus: {status}'.format(status=str(self.active_plugin.status)))
2013-12-24 20:45:29 +00:00
self.about_text_browser.setHtml(self.active_plugin.about())
2019-01-01 16:04:37 +00:00
self.programmatic_change = True
if self.active_plugin.status != PluginStatus.Disabled:
self.status_checkbox.setChecked(self.active_plugin.status == PluginStatus.Active)
self.status_checkbox.setEnabled(True)
else:
self.status_checkbox.setChecked(False)
self.status_checkbox.setEnabled(False)
2019-01-01 16:04:37 +00:00
self.programmatic_change = False
2009-10-06 21:07:12 +00:00
2013-12-24 15:55:01 +00:00
def on_plugin_list_widget_selection_changed(self):
2013-02-01 20:52:42 +00:00
"""
If the selected plugin changes, update the form
"""
2013-12-24 20:45:29 +00:00
if self.plugin_list_widget.currentItem() is None:
2013-12-24 15:55:01 +00:00
self._clear_details()
2009-10-06 21:07:12 +00:00
return
2013-12-24 20:45:29 +00:00
plugin_name_singular = self.plugin_list_widget.currentItem().text().split('(')[0][:-1]
2013-12-24 15:55:01 +00:00
self.active_plugin = None
for plugin in State().list_plugins():
if plugin.name_strings['singular'] == plugin_name_singular:
self.active_plugin = plugin
break
2013-12-24 15:55:01 +00:00
if self.active_plugin:
self._set_details()
2009-10-06 21:07:12 +00:00
else:
2013-12-24 15:55:01 +00:00
self._clear_details()
2009-10-06 21:07:12 +00:00
def on_status_checkbox_changed(self, status):
2013-02-01 20:52:42 +00:00
"""
If the status of a plugin is altered, apply the change
"""
2019-01-01 16:04:37 +00:00
if self.programmatic_change or self.active_plugin is None:
2009-11-07 14:58:24 +00:00
return
if status:
2013-02-03 19:23:12 +00:00
self.application.set_busy_cursor()
2013-12-24 15:55:01 +00:00
self.active_plugin.toggle_status(PluginStatus.Active)
2013-02-03 19:23:12 +00:00
self.application.set_normal_cursor()
2013-12-24 15:55:01 +00:00
self.active_plugin.app_startup()
2009-10-06 21:07:12 +00:00
else:
2013-12-24 15:55:01 +00:00
self.active_plugin.toggle_status(PluginStatus.Inactive)
status_text = translate('OpenLP.PluginForm', '{name} (Inactive)')
2013-12-24 15:55:01 +00:00
if self.active_plugin.status == PluginStatus.Active:
status_text = translate('OpenLP.PluginForm', '{name} (Active)')
2013-12-24 15:55:01 +00:00
elif self.active_plugin.status == PluginStatus.Inactive:
status_text = translate('OpenLP.PluginForm', '{name} (Inactive)')
2013-12-24 15:55:01 +00:00
elif self.active_plugin.status == PluginStatus.Disabled:
status_text = translate('OpenLP.PluginForm', '{name} (Disabled)')
2013-12-24 20:45:29 +00:00
self.plugin_list_widget.currentItem().setText(
status_text.format(name=self.active_plugin.name_strings['singular']))