openlp/openlp/core/lib/__init__.py

133 lines
5.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2009 Raoul Snyman #
# Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten #
# Tinggaard, Jon Tibble, Jonathan Corwin, Maikel Stuivenberg, Scott Guerrieri #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
"""
The :mod:`lib` module contains most of the components and libraries that make
OpenLP work.
"""
2009-05-20 20:17:20 +00:00
import types
from PyQt4 import QtCore, QtGui
2009-05-21 05:15:51 +00:00
def translate(context, text):
"""
A special shortcut method to wrap around the Qt4 translation functions.
This abstracts the translation procedure so that we can change it if at a
later date if necessary, without having to redo the whole of OpenLP.
``context``
The translation context, used to give each string a context or a
namespace.
``text``
The text to put into the translation tables for translation.
"""
return QtGui.QApplication.translate(context, text, None,
QtGui.QApplication.UnicodeUTF8)
2009-05-21 05:15:51 +00:00
def file_to_xml(xmlfile):
"""
Open a file and return the contents of the file.
``xmlfile``
The name of the file.
"""
2009-05-21 05:15:51 +00:00
return open(xmlfile).read()
def str_to_bool(stringvalue):
"""
Convert a string version of a boolean into a real boolean.
``stringvalue``
The string value to examine and convert to a boolean type.
"""
if stringvalue is True or stringvalue is False:
return stringvalue
2009-05-21 05:15:51 +00:00
return stringvalue.strip().lower() in (u'true', u'yes', u'y')
def buildIcon(icon):
"""
Build a QIcon instance from an existing QIcon, a resource location, or a
physical file location. If the icon is a QIcon instance, that icon is
simply returned. If not, it builds a QIcon instance from the resource or
file name.
``icon``
The icon to build. This can be a QIcon, a resource string in the form
``:/resource/file.png``, or a file location like ``/path/to/file.png``.
"""
2009-05-21 05:15:51 +00:00
ButtonIcon = None
if type(icon) is QtGui.QIcon:
ButtonIcon = icon
elif type(icon) is types.StringType or type(icon) is types.UnicodeType:
ButtonIcon = QtGui.QIcon()
if icon.startswith(u':/'):
ButtonIcon.addPixmap(QtGui.QPixmap(icon), QtGui.QIcon.Normal,
QtGui.QIcon.Off)
else:
2009-06-29 05:13:06 +00:00
ButtonIcon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)),
2009-05-21 05:15:51 +00:00
QtGui.QIcon.Normal, QtGui.QIcon.Off)
elif type(icon) is QtGui.QImage:
ButtonIcon = QtGui.QIcon()
ButtonIcon.addPixmap(QtGui.QPixmap.fromImage(icon),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
2009-05-21 05:15:51 +00:00
return ButtonIcon
def contextMenuAction(base, icon, text, slot):
"""
Utility method to help build context menus for plugins
"""
action = QtGui.QAction(text, base)
action .setIcon(buildIcon(icon))
QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered()'), slot)
return action
def contextMenuSeparator(base):
action = QtGui.QAction("", base)
action.setSeparator(True)
return action
2009-05-21 05:15:51 +00:00
2009-09-04 22:50:19 +00:00
from eventreceiver import Receiver
2009-07-08 17:18:48 +00:00
from settingsmanager import SettingsManager
from pluginconfig import PluginConfig
2009-09-21 18:59:14 +00:00
from plugin import PluginStatus, Plugin
2009-07-08 17:18:48 +00:00
from pluginmanager import PluginManager
from settingstab import SettingsTab
from mediamanageritem import MediaManagerItem
from xmlrootclass import XmlRootClass
from serviceitem import ServiceItem
from serviceitem import ServiceType
2009-03-04 21:53:09 +00:00
from serviceitem import ServiceItem
from toolbar import OpenLPToolbar
2009-09-19 11:25:01 +00:00
from dockwidget import OpenLPDockWidget
from songxmlhandler import SongXMLBuilder, SongXMLParser
from themexmlhandler import ThemeXML
from renderer import Renderer
from rendermanager import RenderManager
2009-06-23 20:59:38 +00:00
from mediamanageritem import MediaManagerItem
2009-06-29 05:13:06 +00:00
from baselistwithdnd import BaseListWithDnD
2009-06-23 20:53:06 +00:00
__all__ = [ 'translate', 'file_to_xml', 'str_to_bool',
2009-07-08 17:18:48 +00:00
'contextMenuAction', 'contextMenuSeparator','ServiceItem']