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