forked from openlp/openlp
Plugin cleanup
bzr-revno: 552
This commit is contained in:
commit
109d09ec89
@ -111,6 +111,7 @@ def contextMenuSeparator(base):
|
||||
from eventreceiver import Receiver
|
||||
from settingsmanager import SettingsManager
|
||||
from pluginconfig import PluginConfig
|
||||
from plugin import PluginStatus
|
||||
from plugin import Plugin
|
||||
from pluginmanager import PluginManager
|
||||
from settingstab import SettingsTab
|
||||
|
@ -27,6 +27,13 @@ from PyQt4 import QtCore
|
||||
|
||||
from openlp.core.lib import PluginConfig, Receiver
|
||||
|
||||
class PluginStatus(object):
|
||||
"""
|
||||
Defines the status of the plugin
|
||||
"""
|
||||
Active = 1
|
||||
Inactive = 2
|
||||
|
||||
class Plugin(object):
|
||||
"""
|
||||
Base class for openlp plugins to inherit from.
|
||||
@ -122,6 +129,7 @@ class Plugin(object):
|
||||
self.icon = None
|
||||
self.config = PluginConfig(self.name)
|
||||
self.weight = 0
|
||||
self.status = PluginStatus.Inactive
|
||||
# Set up logging
|
||||
self.log = logging.getLogger(self.name)
|
||||
self.preview_controller = plugin_helpers[u'preview']
|
||||
|
@ -26,7 +26,7 @@ import os
|
||||
import sys
|
||||
import logging
|
||||
|
||||
from openlp.core.lib import Plugin
|
||||
from openlp.core.lib import Plugin, PluginStatus
|
||||
|
||||
class PluginManager(object):
|
||||
"""
|
||||
@ -92,23 +92,20 @@ class PluginManager(object):
|
||||
log.error(u'Failed to import module %s on path %s for reason %s', modulename, path, e.args[0])
|
||||
plugin_classes = Plugin.__subclasses__()
|
||||
self.plugins = []
|
||||
self.plugin_list=[]
|
||||
plugin_objects = []
|
||||
for p in plugin_classes:
|
||||
try:
|
||||
plugin = p(self.plugin_helpers)
|
||||
log.debug(u'Loaded plugin %s with helpers', unicode(p))
|
||||
|
||||
plugin_objects.append(plugin)
|
||||
except TypeError:
|
||||
log.error(u'loaded plugin %s has no helpers', unicode(p))
|
||||
plugins_list = sorted(plugin_objects, self.order_by_weight)
|
||||
for plugin in plugins_list:
|
||||
pList = {u'plugin': plugin, u'status': u'Inactive'}
|
||||
if plugin.check_pre_conditions():
|
||||
log.debug(u'Plugin %s active', unicode(plugin.name))
|
||||
pList[u'status'] = u'Active'
|
||||
self.plugins.append(pList)
|
||||
plugin.status = PluginStatus.Active
|
||||
self.plugins.append(plugin)
|
||||
|
||||
def order_by_weight(self, x, y):
|
||||
"""
|
||||
@ -131,11 +128,11 @@ class PluginManager(object):
|
||||
The Media Manager itself.
|
||||
"""
|
||||
for plugin in self.plugins:
|
||||
if plugin[u'status'] == u'Active':
|
||||
media_manager_item = plugin[u'plugin'].get_media_manager_item()
|
||||
if plugin.status == PluginStatus.Active:
|
||||
media_manager_item = plugin.get_media_manager_item()
|
||||
if media_manager_item is not None:
|
||||
log.debug(u'Inserting media manager item from %s' % plugin[u'plugin'].name)
|
||||
mediatoolbox.addItem(media_manager_item, plugin[u'plugin'].icon, media_manager_item.title)
|
||||
log.debug(u'Inserting media manager item from %s' % plugin.name)
|
||||
mediatoolbox.addItem(media_manager_item, plugin.icon, media_manager_item.title)
|
||||
|
||||
def hook_settings_tabs(self, settingsform=None):
|
||||
"""
|
||||
@ -147,12 +144,12 @@ class PluginManager(object):
|
||||
Defaults to *None*. The settings form to add tabs to.
|
||||
"""
|
||||
for plugin in self.plugins:
|
||||
settings_tab = plugin[u'plugin'].get_settings_tab()
|
||||
settings_tab = plugin.get_settings_tab()
|
||||
if settings_tab is not None:
|
||||
log.debug(u'Inserting settings tab item from %s' % plugin[u'plugin'].name)
|
||||
log.debug(u'Inserting settings tab item from %s' % plugin.name)
|
||||
settingsform.addTab(settings_tab)
|
||||
else:
|
||||
log.debug(u'No settings in %s' % plugin[u'plugin'].name)
|
||||
log.debug(u'No settings in %s' % plugin.name)
|
||||
|
||||
def hook_import_menu(self, import_menu):
|
||||
"""
|
||||
@ -163,8 +160,8 @@ class PluginManager(object):
|
||||
The Import menu.
|
||||
"""
|
||||
for plugin in self.plugins:
|
||||
if plugin[u'status'] == u'Active':
|
||||
plugin[u'plugin'].add_import_menu_item(import_menu)
|
||||
if plugin.status == PluginStatus.Active:
|
||||
plugin.add_import_menu_item(import_menu)
|
||||
|
||||
def hook_export_menu(self, export_menu):
|
||||
"""
|
||||
@ -175,8 +172,8 @@ class PluginManager(object):
|
||||
The Export menu.
|
||||
"""
|
||||
for plugin in self.plugins:
|
||||
if plugin[u'status'] == u'Active':
|
||||
plugin[u'plugin'].add_export_menu_item(export_menu)
|
||||
if plugin.status == PluginStatus.Active:
|
||||
plugin.add_export_menu_item(export_menu)
|
||||
|
||||
def hook_tools_menu(self, tools_menu):
|
||||
"""
|
||||
@ -187,8 +184,8 @@ class PluginManager(object):
|
||||
The Tools menu.
|
||||
"""
|
||||
for plugin in self.plugins:
|
||||
if plugin[u'status'] == u'Active':
|
||||
plugin[u'plugin'].add_tools_menu_item(tools_menu)
|
||||
if plugin.status == PluginStatus.Active:
|
||||
plugin.add_tools_menu_item(tools_menu)
|
||||
|
||||
def initialise_plugins(self):
|
||||
"""
|
||||
@ -196,8 +193,8 @@ class PluginManager(object):
|
||||
initialise themselves.
|
||||
"""
|
||||
for plugin in self.plugins:
|
||||
if plugin[u'status'] == u'Active':
|
||||
plugin[u'plugin'].initialise()
|
||||
if plugin.status == PluginStatus.Active:
|
||||
plugin.initialise()
|
||||
|
||||
def finalise_plugins(self):
|
||||
"""
|
||||
@ -205,5 +202,5 @@ class PluginManager(object):
|
||||
clean themselves up
|
||||
"""
|
||||
for plugin in self.plugins:
|
||||
if plugin[u'status'] == u'Active':
|
||||
plugin[u'plugin'].finalise()
|
||||
if plugin.status == PluginStatus.Active:
|
||||
plugin.finalise()
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
import logging
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from openlp.core.lib import translate
|
||||
from openlp.core.lib import translate, PluginStatus
|
||||
|
||||
class PluginForm(QtGui.QDialog):
|
||||
global log
|
||||
@ -63,11 +63,14 @@ class PluginForm(QtGui.QDialog):
|
||||
for plugin in self.parent.plugin_manager.plugins:
|
||||
row = self.PluginViewList.rowCount()
|
||||
self.PluginViewList.setRowCount(row + 1)
|
||||
item1 = QtGui.QTableWidgetItem(plugin[u'plugin'].name)
|
||||
item1 = QtGui.QTableWidgetItem(plugin.name)
|
||||
item1.setTextAlignment(QtCore.Qt.AlignVCenter)
|
||||
item2 = QtGui.QTableWidgetItem(plugin[u'plugin'].version)
|
||||
item2 = QtGui.QTableWidgetItem(plugin.version)
|
||||
item2.setTextAlignment(QtCore.Qt.AlignVCenter)
|
||||
item3 = QtGui.QTableWidgetItem(translate(u'PluginForm', plugin[u'status']))
|
||||
if plugin.status == PluginStatus.Active:
|
||||
item3 = QtGui.QTableWidgetItem(translate(u'PluginForm', u'Active'))
|
||||
else:
|
||||
item3 = QtGui.QTableWidgetItem(translate(u'PluginForm', u'Inactive'))
|
||||
item3.setTextAlignment(QtCore.Qt.AlignVCenter)
|
||||
self.PluginViewList.setItem(row, 0, item1)
|
||||
self.PluginViewList.setItem(row, 1, item2)
|
||||
|
Loading…
Reference in New Issue
Block a user