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
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2015-12-31 22:46:06 +00:00
|
|
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
2009-10-06 21:07:12 +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 20:52:42 +00:00
|
|
|
"""
|
|
|
|
The actual plugin view form
|
|
|
|
"""
|
2009-10-06 21:07:12 +00:00
|
|
|
import logging
|
|
|
|
|
2015-12-30 15:03:35 +00:00
|
|
|
from PyQt5 import QtCore, QtWidgets
|
2009-10-06 21:07:12 +00:00
|
|
|
|
2014-03-16 21:25:23 +00:00
|
|
|
from openlp.core.common import RegistryProperties, translate
|
2013-12-13 17:44:05 +00:00
|
|
|
from openlp.core.lib import PluginStatus
|
2013-08-31 18:17:38 +00:00
|
|
|
from .plugindialog import Ui_PluginViewDialog
|
2009-10-06 21:07:12 +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
|
|
|
|
"""
|
2016-01-09 16:26:14 +00:00
|
|
|
super(PluginForm, self).__init__(parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
|
2013-12-24 15:55:01 +00:00
|
|
|
self.active_plugin = None
|
|
|
|
self.programatic_change = False
|
2009-10-06 21:07:12 +00:00
|
|
|
self.setupUi(self)
|
|
|
|
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)
|
2016-01-03 13:03:29 +00:00
|
|
|
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()
|
2013-12-24 15:55:01 +00:00
|
|
|
self.programatic_change = True
|
|
|
|
self._clear_details()
|
|
|
|
self.programatic_change = True
|
|
|
|
plugin_list_width = 0
|
2013-02-03 09:07:31 +00:00
|
|
|
for plugin in self.plugin_manager.plugins:
|
2015-11-07 00:49:40 +00:00
|
|
|
item = QtWidgets.QListWidgetItem(self.plugin_list_widget)
|
2009-10-08 19:58:49 +00:00
|
|
|
# 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.
|
2011-01-01 13:22:12 +00:00
|
|
|
if plugin.status == PluginStatus.Disabled:
|
2012-05-17 18:57:01 +00:00
|
|
|
status_text = translate('OpenLP.PluginForm', '%s (Disabled)')
|
2011-01-01 13:22:12 +00:00
|
|
|
elif plugin.status == PluginStatus.Active:
|
2012-05-17 18:57:01 +00:00
|
|
|
status_text = translate('OpenLP.PluginForm', '%s (Active)')
|
2011-01-01 13:22:12 +00:00
|
|
|
else:
|
|
|
|
# PluginStatus.Inactive
|
2012-05-17 18:57:01 +00:00
|
|
|
status_text = translate('OpenLP.PluginForm', '%s (Inactive)')
|
2013-08-31 18:17:38 +00:00
|
|
|
item.setText(status_text % plugin.name_strings['singular'])
|
2009-10-08 19:58:49 +00:00
|
|
|
# If the plugin has an icon, set it!
|
2009-11-03 18:14:25 +00:00
|
|
|
if plugin.icon:
|
2009-10-06 21:07:12 +00:00
|
|
|
item.setIcon(plugin.icon)
|
2013-12-24 20:45:29 +00:00
|
|
|
self.plugin_list_widget.addItem(item)
|
2013-12-24 15:55:01 +00:00
|
|
|
plugin_list_width = max(plugin_list_width, self.fontMetrics().width(
|
2013-08-31 18:17:38 +00:00
|
|
|
translate('OpenLP.PluginForm', '%s (Inactive)') % 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
|
|
|
|
"""
|
2016-01-03 13:03:29 +00:00
|
|
|
self.status_checkbox.setChecked(False)
|
2013-12-24 20:45:29 +00:00
|
|
|
self.about_text_browser.setHtml('')
|
2016-01-03 13:03:29 +00:00
|
|
|
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
|
|
|
|
"""
|
2013-12-24 15:55:01 +00:00
|
|
|
log.debug('PluginStatus: %s', str(self.active_plugin.status))
|
2013-12-24 20:45:29 +00:00
|
|
|
self.about_text_browser.setHtml(self.active_plugin.about())
|
2013-12-24 15:55:01 +00:00
|
|
|
self.programatic_change = True
|
2016-02-22 14:51:11 +00:00
|
|
|
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)
|
2013-12-24 15:55:01 +00:00
|
|
|
self.programatic_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
|
2013-02-03 09:07:31 +00:00
|
|
|
for plugin in self.plugin_manager.plugins:
|
2016-02-22 14:51:11 +00:00
|
|
|
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
|
|
|
|
2016-01-03 13:03:29 +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
|
|
|
|
"""
|
2016-02-22 14:34:00 +00:00
|
|
|
if self.programatic_change or self.active_plugin is None:
|
2009-11-07 14:58:24 +00:00
|
|
|
return
|
2016-01-03 13:03:29 +00:00
|
|
|
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)
|
2012-05-17 18:57:01 +00:00
|
|
|
status_text = translate('OpenLP.PluginForm', '%s (Inactive)')
|
2013-12-24 15:55:01 +00:00
|
|
|
if self.active_plugin.status == PluginStatus.Active:
|
2012-05-17 18:57:01 +00:00
|
|
|
status_text = translate('OpenLP.PluginForm', '%s (Active)')
|
2013-12-24 15:55:01 +00:00
|
|
|
elif self.active_plugin.status == PluginStatus.Inactive:
|
2012-05-17 18:57:01 +00:00
|
|
|
status_text = translate('OpenLP.PluginForm', '%s (Inactive)')
|
2013-12-24 15:55:01 +00:00
|
|
|
elif self.active_plugin.status == PluginStatus.Disabled:
|
2012-05-17 18:57:01 +00:00
|
|
|
status_text = translate('OpenLP.PluginForm', '%s (Disabled)')
|
2013-12-24 20:45:29 +00:00
|
|
|
self.plugin_list_widget.currentItem().setText(
|
2014-03-20 19:10:31 +00:00
|
|
|
status_text % self.active_plugin.name_strings['singular'])
|