From 5d920e8fc6a0af90112b79af29281bb1e42e5045 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 21 Dec 2008 07:48:30 +0000 Subject: [PATCH] Add Utilitys class for plugins bzr-revno: 252 --- openlp/core/lib/__init__.py | 4 +-- openlp/core/lib/plugin.py | 2 ++ openlp/core/lib/pluginutils.py | 54 ++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 openlp/core/lib/pluginutils.py diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index a1b9d7180..667c0ecfa 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -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 Place, Suite 330, Boston, MA 02111-1307 USA """ - +from pluginutils import PluginUtils from pluginconfig import PluginConfig from plugin import Plugin from settingstab import SettingsTab @@ -25,5 +25,5 @@ from mediamanageritem import MediaManagerItem from event import Event from xmlrootclass import XmlRootClass -__all__ = ['PluginConfig', 'Plugin', 'SettingsTab', 'MediaManagerItem', 'Event', +__all__ = ['PluginConfig', 'Plugin', 'PluginUtils', 'SettingsTab', 'MediaManagerItem', 'Event', 'XmlRootClass'] diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 50eb5638b..8d10c6509 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -21,6 +21,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA import logging from openlp.core.lib import PluginConfig +from openlp.core.lib import PluginUtils class Plugin(object): """ @@ -85,6 +86,7 @@ class Plugin(object): self.version = version self.icon = None self.config = PluginConfig(self.name) + self.pluginutils = PluginUtils() self.weight = 0 # Set up logging self.log = logging.getLogger(self.name) diff --git a/openlp/core/lib/pluginutils.py b/openlp/core/lib/pluginutils.py new file mode 100644 index 000000000..882420da7 --- /dev/null +++ b/openlp/core/lib/pluginutils.py @@ -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