openlp/openlp/core/ui/pluginform.py

141 lines
6.9 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
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2012-12-29 20:56:56 +00:00
# Copyright (c) 2008-2013 Raoul Snyman #
# Portions copyright (c) 2008-2013 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 #
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 #
###############################################################################
import logging
from PyQt4 import QtCore, QtGui
2011-02-14 16:08:17 +00:00
from openlp.core.lib import PluginStatus, Receiver, translate
2009-10-06 21:07:12 +00:00
from plugindialog import Ui_PluginViewDialog
2010-02-27 15:31:23 +00:00
log = logging.getLogger(__name__)
2009-10-06 21:07:12 +00:00
class PluginForm(QtGui.QDialog, Ui_PluginViewDialog):
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):
QtGui.QDialog.__init__(self, parent)
self.activePlugin = None
2009-10-30 20:34:11 +00:00
self.programaticChange = False
2009-10-06 21:07:12 +00:00
self.setupUi(self)
self.load()
self._clearDetails()
# Right, now let's put some signals and slots together!
2012-12-29 13:35:16 +00:00
QtCore.QObject.connect(self.pluginListWidget, QtCore.SIGNAL(u'itemSelectionChanged()'),
self.onPluginListWidgetSelectionChanged)
2012-12-29 13:35:16 +00:00
QtCore.QObject.connect(self.statusComboBox, QtCore.SIGNAL(u'currentIndexChanged(int)'),
self.onStatusComboBoxChanged)
2009-10-06 21:07:12 +00:00
def load(self):
"""
Load the plugin details into the screen
"""
2010-07-27 11:57:25 +00:00
self.pluginListWidget.clear()
2010-09-08 19:36:39 +00:00
self.programaticChange = True
self._clearDetails()
self.programaticChange = True
pluginListWidth = 0
for plugin in self.parent().pluginManager.plugins:
2010-07-27 11:57:25 +00:00
item = QtGui.QListWidgetItem(self.pluginListWidget)
# 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:
2012-05-17 18:57:01 +00:00
status_text = translate('OpenLP.PluginForm', '%s (Disabled)')
elif plugin.status == PluginStatus.Active:
2012-05-17 18:57:01 +00:00
status_text = translate('OpenLP.PluginForm', '%s (Active)')
else:
# PluginStatus.Inactive
2012-05-17 18:57:01 +00:00
status_text = translate('OpenLP.PluginForm', '%s (Inactive)')
2011-02-14 16:08:17 +00:00
item.setText(status_text % plugin.nameStrings[u'singular'])
# 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)
2010-07-27 11:57:25 +00:00
self.pluginListWidget.addItem(item)
pluginListWidth = max(pluginListWidth, self.fontMetrics().width(
2012-12-29 13:35:16 +00:00
translate('OpenLP.PluginForm', '%s (Inactive)') % plugin.nameStrings[u'singular']))
self.pluginListWidget.setFixedWidth(pluginListWidth + self.pluginListWidget.iconSize().width() + 48)
2009-10-06 21:07:12 +00:00
def _clearDetails(self):
2010-07-27 11:57:25 +00:00
self.statusComboBox.setCurrentIndex(-1)
self.versionNumberLabel.setText(u'')
self.aboutTextBrowser.setHtml(u'')
self.statusComboBox.setEnabled(False)
2009-10-06 21:07:12 +00:00
def _setDetails(self):
log.debug(u'PluginStatus: %s', str(self.activePlugin.status))
2010-07-27 11:57:25 +00:00
self.versionNumberLabel.setText(self.activePlugin.version)
self.aboutTextBrowser.setHtml(self.activePlugin.about())
self.programaticChange = True
2012-06-09 15:46:01 +00:00
status = PluginStatus.Active
if self.activePlugin.status == PluginStatus.Active:
2012-06-09 15:46:01 +00:00
status = PluginStatus.Inactive
2010-07-27 11:57:25 +00:00
self.statusComboBox.setCurrentIndex(status)
self.statusComboBox.setEnabled(True)
self.programaticChange = False
2009-10-06 21:07:12 +00:00
def onPluginListWidgetSelectionChanged(self):
2010-07-27 11:57:25 +00:00
if self.pluginListWidget.currentItem() is None:
2009-10-06 21:07:12 +00:00
self._clearDetails()
return
2010-12-24 12:36:40 +00:00
plugin_name_singular = \
2011-06-11 21:43:08 +00:00
self.pluginListWidget.currentItem().text().split(u'(')[0][:-1]
2009-10-06 21:07:12 +00:00
self.activePlugin = None
for plugin in self.parent().pluginManager.plugins:
2011-12-03 12:51:40 +00:00
if plugin.status != PluginStatus.Disabled:
if plugin.nameStrings[u'singular'] == plugin_name_singular:
self.activePlugin = plugin
break
2009-11-03 18:14:25 +00:00
if self.activePlugin:
2009-10-06 21:07:12 +00:00
self._setDetails()
else:
self._clearDetails()
def onStatusComboBoxChanged(self, status):
2011-12-03 12:51:40 +00:00
if self.programaticChange or status == PluginStatus.Disabled:
2009-11-07 14:58:24 +00:00
return
2012-06-09 15:46:01 +00:00
if status == PluginStatus.Inactive:
2011-02-05 23:56:34 +00:00
Receiver.send_message(u'cursor_busy')
2010-07-05 16:00:48 +00:00
self.activePlugin.toggleStatus(PluginStatus.Active)
2011-02-05 23:56:34 +00:00
Receiver.send_message(u'cursor_normal')
self.activePlugin.appStartup()
2009-10-06 21:07:12 +00:00
else:
2010-07-05 16:00:48 +00:00
self.activePlugin.toggleStatus(PluginStatus.Inactive)
2012-05-17 18:57:01 +00:00
status_text = translate('OpenLP.PluginForm', '%s (Inactive)')
if self.activePlugin.status == PluginStatus.Active:
2012-05-17 18:57:01 +00:00
status_text = translate('OpenLP.PluginForm', '%s (Active)')
elif self.activePlugin.status == PluginStatus.Inactive:
2012-05-17 18:57:01 +00:00
status_text = translate('OpenLP.PluginForm', '%s (Inactive)')
elif self.activePlugin.status == PluginStatus.Disabled:
2012-05-17 18:57:01 +00:00
status_text = translate('OpenLP.PluginForm', '%s (Disabled)')
2010-09-08 19:36:39 +00:00
self.pluginListWidget.currentItem().setText(
2011-02-14 16:08:17 +00:00
status_text % self.activePlugin.nameStrings[u'singular'])