Add Utilitys class for plugins

bzr-revno: 252
This commit is contained in:
Tim Bentley 2008-12-21 07:48:30 +00:00
parent e1f5e5723a
commit 5d920e8fc6
3 changed files with 58 additions and 2 deletions

View File

@ -17,7 +17,7 @@ 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from pluginutils import PluginUtils
from pluginconfig import PluginConfig from pluginconfig import PluginConfig
from plugin import Plugin from plugin import Plugin
from settingstab import SettingsTab from settingstab import SettingsTab
@ -25,5 +25,5 @@ from mediamanageritem import MediaManagerItem
from event import Event from event import Event
from xmlrootclass import XmlRootClass from xmlrootclass import XmlRootClass
__all__ = ['PluginConfig', 'Plugin', 'SettingsTab', 'MediaManagerItem', 'Event', __all__ = ['PluginConfig', 'Plugin', 'PluginUtils', 'SettingsTab', 'MediaManagerItem', 'Event',
'XmlRootClass'] 'XmlRootClass']

View File

@ -21,6 +21,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
import logging import logging
from openlp.core.lib import PluginConfig from openlp.core.lib import PluginConfig
from openlp.core.lib import PluginUtils
class Plugin(object): class Plugin(object):
""" """
@ -85,6 +86,7 @@ class Plugin(object):
self.version = version self.version = version
self.icon = None self.icon = None
self.config = PluginConfig(self.name) self.config = PluginConfig(self.name)
self.pluginutils = PluginUtils()
self.weight = 0 self.weight = 0
# Set up logging # Set up logging
self.log = logging.getLogger(self.name) self.log = logging.getLogger(self.name)

View File

@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
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 types
from PyQt4 import QtCore, QtGui
class PluginUtils(object):
def __init__(self):
"""
IClass for plugin helpers so the Plugin class is just a simple interface
"""
pass
def add_separator(self, base):
action = QtGui.QAction("", base)
action.setSeparator(True)
return action
def add_to_context_menu(self, base, icon, text, slot):
"""
Utility method to help build context menus for plugins
"""
if type(icon) is QtGui.QIcon:
ButtonIcon = icon
elif type(icon) is types.StringType:
ButtonIcon = QtGui.QIcon()
if icon.startswith(':/'):
ButtonIcon.addPixmap(QtGui.QPixmap(icon), QtGui.QIcon.Normal,
QtGui.QIcon.Off)
else:
ButtonIcon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
action = QtGui.QAction(text, base)
action .setIcon(ButtonIcon)
QtCore.QObject.connect(action, QtCore.SIGNAL("triggered()"), slot)
return action