openlp/openlp/core/ui/pluginform.py

140 lines
6.3 KiB
Python
Raw Normal View History

2009-10-06 21:07:12 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2009-12-31 12:52:01 +00:00
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
2010-07-24 22:10:47 +00:00
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard, Frode Woldsund #
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
2010-06-09 23:08:12 +00:00
from openlp.core.lib import PluginStatus, 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):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.parent = 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!
QtCore.QObject.connect(
2010-07-27 11:57:25 +00:00
self.pluginListWidget,
QtCore.SIGNAL(u'itemSelectionChanged()'),
self.onPluginListWidgetSelectionChanged)
QtCore.QObject.connect(
2010-07-27 11:57:25 +00:00
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()
2009-10-06 21:07:12 +00:00
for plugin in self.parent.plugin_manager.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.
status_text = unicode(
translate('OpenLP.PluginForm', '%s (Inactive)'))
if plugin.status == PluginStatus.Active:
status_text = unicode(
translate('OpenLP.PluginForm', '%s (Active)'))
elif plugin.status == PluginStatus.Inactive:
2010-06-17 21:07:01 +00:00
status_text = unicode(
translate('OpenLP.PluginForm', '%s (Inactive)'))
elif plugin.status == PluginStatus.Disabled:
2010-06-17 21:07:01 +00:00
status_text = unicode(
translate('OpenLP.PluginForm', '%s (Disabled)'))
item.setText(status_text % plugin.name)
# 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)
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('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
status = 1
if self.activePlugin.status == PluginStatus.Active:
status = 0
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-07-27 11:57:25 +00:00
plugin_name = self.pluginListWidget.currentItem().text().split(u' ')[0]
2009-10-06 21:07:12 +00:00
self.activePlugin = None
for plugin in self.parent.plugin_manager.plugins:
if plugin.name == plugin_name:
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):
2009-11-07 14:58:24 +00:00
if self.programaticChange:
return
if status == 0:
2010-07-05 16:00:48 +00:00
self.activePlugin.toggleStatus(PluginStatus.Active)
2009-10-06 21:07:12 +00:00
self.activePlugin.initialise()
else:
2010-07-05 16:00:48 +00:00
self.activePlugin.toggleStatus(PluginStatus.Inactive)
2009-10-06 21:07:12 +00:00
self.activePlugin.finalise()
status_text = unicode(
translate('OpenLP.PluginForm', '%s (Inactive)'))
if self.activePlugin.status == PluginStatus.Active:
status_text = unicode(
translate('OpenLP.PluginForm', '%s (Active)'))
elif self.activePlugin.status == PluginStatus.Inactive:
status_text = unicode(
translate('OpenLP.PluginForm', '%s (Inactive)'))
elif self.activePlugin.status == PluginStatus.Disabled:
status_text = unicode(
translate('OpenLP.PluginForm', '%s (Disabled)'))
if self.pluginListWidget.currentItem():
self.pluginListWidget.currentItem().setText(
status_text % self.activePlugin.name)