From 1a7ad33bf969ed7673f4fa8f98a69caebe8eb244 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Tue, 29 Sep 2009 03:54:32 +0100 Subject: [PATCH] Use buildIcon and general fixes all over --- openlp.pyw | 18 ++-- openlp/core/lib/__init__.py | 32 ++++--- openlp/core/lib/baselistwithdnd.py | 15 ++-- openlp/core/lib/dockwidget.py | 7 +- openlp/core/lib/eventreceiver.py | 10 +-- openlp/core/lib/plugin.py | 7 +- openlp/core/lib/settingsmanager.py | 38 ++++---- openlp/core/lib/settingstab.py | 6 +- openlp/core/lib/themexmlhandler.py | 10 +-- openlp/core/lib/toolbar.py | 26 ++---- openlp/core/theme/theme.py | 28 +++--- openlp/core/ui/about.py | 5 +- openlp/core/ui/alertform.py | 5 +- openlp/core/ui/amendthemedialog.py | 8 +- openlp/core/ui/mainwindow.py | 61 ++++--------- openlp/core/ui/splashscreen.py | 8 +- openlp/core/utils/confighelper.py | 2 +- openlp/plugins/audit/auditplugin.py | 10 +-- openlp/plugins/audit/forms/auditdeleteform.py | 6 +- openlp/plugins/bibles/bibleplugin.py | 7 +- .../plugins/bibles/forms/bibleimportdialog.py | 8 +- openlp/plugins/bibles/lib/mediaitem.py | 2 +- openlp/plugins/custom/customplugin.py | 8 +- .../plugins/custom/forms/editcustomdialog.py | 11 +-- openlp/plugins/images/imageplugin.py | 8 +- openlp/plugins/media/lib/__init__.py | 3 +- openlp/plugins/media/mediaplugin.py | 10 +-- .../presentations/presentationplugin.py | 9 +- openlp/plugins/songs/forms/editsongdialog.py | 6 +- .../plugins/songs/forms/openlpexportform.py | 17 ++-- .../plugins/songs/forms/openlpimportform.py | 17 ++-- .../plugins/songs/forms/opensongexportform.py | 17 ++-- .../plugins/songs/forms/opensongimportform.py | 8 +- .../songs/forms/songmaintenancedialog.py | 86 ++++++++----------- openlp/plugins/songs/lib/mediaitem.py | 2 +- openlp/plugins/songs/songsplugin.py | 6 +- 36 files changed, 210 insertions(+), 317 deletions(-) diff --git a/openlp.pyw b/openlp.pyw index 2132c99fd..0c4b86126 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -25,10 +25,11 @@ import sys import logging -import logging.handlers +from logging.handlers import RotatingFileHandler from optparse import OptionParser -from PyQt4 import QtCore, QtGui +from PyQt4.QtCore import QObject, SIGNAL +from PyQt4.QtGui import QApplication from openlp.core.lib import Receiver, str_to_bool from openlp.core.resources import qInitResources @@ -37,7 +38,7 @@ from openlp.core.utils import ConfigHelper log = logging.getLogger() -class OpenLP(QtGui.QApplication): +class OpenLP(QApplication): """ The core application class. This class inherits from Qt's QApplication class in order to provide the core of the application. @@ -55,8 +56,8 @@ class OpenLP(QtGui.QApplication): except: pass #provide a listener for widgets to reqest a screen update. - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'process_events'), self.processEvents) + QObject.connect(Receiver.get_receiver(), + SIGNAL(u'process_events'), self.processEvents) self.setApplicationName(u'OpenLP') self.setApplicationVersion(u'1.9.0') show_splash = str_to_bool(ConfigHelper.get_registry().get_value( @@ -94,10 +95,9 @@ def main(): action="store_true", help="set logging to DEBUG level") # Set up logging filename = u'openlp.log' - logfile = logging.handlers.RotatingFileHandler( - filename, maxBytes=200000, backupCount=5) - logfile.setFormatter( - logging.Formatter(u'%(asctime)s %(name)-15s %(levelname)-8s %(message)s')) + logfile = RotatingFileHandler(filename, maxBytes=200000, backupCount=5) + logfile.setFormatter(logging.Formatter( + u'%(asctime)s %(name)-15s %(levelname)-8s %(message)s')) log.addHandler(logfile) # Parse command line options and deal with them. (options, args) = parser.parse_args() diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index e8aab6bfb..2775f3866 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -29,7 +29,8 @@ OpenLP work. import types -from PyQt4 import QtCore, QtGui +from PyQt4.QtCore import QObject, SIGNAL +from PyQt4.QtGui import QAction, QIcon, QImage, QPixmap, QApplication as QApp def translate(context, text): """ @@ -44,8 +45,7 @@ def translate(context, text): ``text`` The text to put into the translation tables for translation. """ - return QtGui.QApplication.translate(context, text, None, - QtGui.QApplication.UnicodeUTF8) + return QApp.translate(context, text, None, QApp.UnicodeUTF8) def file_to_xml(xmlfile): """ @@ -79,33 +79,31 @@ def buildIcon(icon): ``:/resource/file.png``, or a file location like ``/path/to/file.png``. """ ButtonIcon = None - if type(icon) is QtGui.QIcon: + if type(icon) is QIcon: ButtonIcon = icon elif type(icon) is types.StringType or type(icon) is types.UnicodeType: - ButtonIcon = QtGui.QIcon() + ButtonIcon = QIcon() if icon.startswith(u':/'): - ButtonIcon.addPixmap(QtGui.QPixmap(icon), QtGui.QIcon.Normal, - QtGui.QIcon.Off) + ButtonIcon.addPixmap(QPixmap(icon), QIcon.Normal, QIcon.Off) else: - ButtonIcon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)), - 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) + ButtonIcon.addPixmap(QPixmap.fromImage(QImage(icon)), + QIcon.Normal, QIcon.Off) + elif type(icon) is QImage: + ButtonIcon = QIcon() + ButtonIcon.addPixmap(QPixmap.fromImage(icon), QIcon.Normal, QIcon.Off) 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) + action = QAction(text, base) + action.setIcon(buildIcon(icon)) + QObject.connect(action, SIGNAL(u'triggered()'), slot) return action def contextMenuSeparator(base): - action = QtGui.QAction("", base) + action = QAction("", base) action.setSeparator(True) return action diff --git a/openlp/core/lib/baselistwithdnd.py b/openlp/core/lib/baselistwithdnd.py index 60b001402..4f95e282f 100644 --- a/openlp/core/lib/baselistwithdnd.py +++ b/openlp/core/lib/baselistwithdnd.py @@ -22,17 +22,18 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -from PyQt4 import QtCore, QtGui +from PyQt4.QtCore import QMimeData, Qt +from PyQt4.QtGui import QDrag, QListWidget from openlp.core.lib.toolbar import * -class BaseListWithDnD(QtGui.QListWidget): +class BaseListWithDnD(QListWidget): """ Please put a short description of what this class does in here. """ def __init__(self, parent=None): - QtGui.QListWidget.__init__(self, parent) + QListWidget.__init__(self, parent) # this must be set by the class which is inheriting assert(self.PluginName) @@ -42,10 +43,10 @@ class BaseListWithDnD(QtGui.QListWidget): as the recipient will use events to request the data move just tell it what plugin to call """ - if event.buttons() != QtCore.Qt.LeftButton: + if event.buttons() != Qt.LeftButton: return - drag = QtGui.QDrag(self) - mimeData = QtCore.QMimeData() + drag = QDrag(self) + mimeData = QMimeData() drag.setMimeData(mimeData) mimeData.setText(self.PluginName) - dropAction = drag.start(QtCore.Qt.CopyAction) + dropAction = drag.start(Qt.CopyAction) diff --git a/openlp/core/lib/dockwidget.py b/openlp/core/lib/dockwidget.py index 50b8fe51a..90a19f71c 100644 --- a/openlp/core/lib/dockwidget.py +++ b/openlp/core/lib/dockwidget.py @@ -24,9 +24,9 @@ import logging -from PyQt4 import QtGui +from PyQt4.QtGui import QDockWidget -class OpenLPDockWidget(QtGui.QDockWidget): +class OpenLPDockWidget(QDockWidget): """ Custom DockWidget class to handle events """ @@ -34,10 +34,11 @@ class OpenLPDockWidget(QtGui.QDockWidget): """ Initialise the DockWidget """ - QtGui.QDockWidget.__init__(self, parent) + QDockWidget.__init__(self, parent) self.parent = parent if name is not None: self.setObjectName(name) + self.setFloating(False) self.log = logging.getLogger(u'OpenLPDockWidget') self.log.debug(u'Init done') diff --git a/openlp/core/lib/eventreceiver.py b/openlp/core/lib/eventreceiver.py index ad5aac289..2ad2f131c 100644 --- a/openlp/core/lib/eventreceiver.py +++ b/openlp/core/lib/eventreceiver.py @@ -24,9 +24,9 @@ import logging -from PyQt4 import QtCore +from PyQt4.QtCore import QObject, SIGNAL -class EventReceiver(QtCore.QObject): +class EventReceiver(QObject): """ Class to allow events to be passed from different parts of the system. This is a private class and should not be used directly @@ -91,7 +91,7 @@ class EventReceiver(QtCore.QObject): """ Initialise the event receiver, calling the parent constructor. """ - QtCore.QObject.__init__(self) + QObject.__init__(self) def send_message(self, event, msg=None): """ @@ -104,7 +104,7 @@ class EventReceiver(QtCore.QObject): Defaults to *None*. The message to send with the event. """ log.debug(u'Event %s passed with payload %s' % (event, msg)) - self.emit(QtCore.SIGNAL(event), msg) + self.emit(SIGNAL(event), msg) class Receiver(): @@ -141,5 +141,3 @@ class Receiver(): Get the global ``eventreceiver`` instance. """ return Receiver.eventreceiver - - diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 56914df9e..dfa085fec 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -23,7 +23,8 @@ ############################################################################### import logging -from PyQt4 import QtCore + +from PyQt4.QtCore import QObject, SIGNAL from openlp.core.lib import PluginConfig, Receiver @@ -137,8 +138,8 @@ class Plugin(object): self.render_manager = plugin_helpers[u'render'] self.service_manager = plugin_helpers[u'service'] self.settings = plugin_helpers[u'settings'] - QtCore.QObject.connect(Receiver.get_receiver(), - QtCore.SIGNAL(u'%s_add_service_item'% self.name), self.process_add_service_event) + QObject.connect(Receiver.get_receiver(), + SIGNAL(u'%s_add_service_item'% self.name), self.process_add_service_event) def check_pre_conditions(self): """ diff --git a/openlp/core/lib/settingsmanager.py b/openlp/core/lib/settingsmanager.py index dff197100..b4566e1b7 100644 --- a/openlp/core/lib/settingsmanager.py +++ b/openlp/core/lib/settingsmanager.py @@ -1,24 +1,26 @@ # -*- 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-2009 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 -""" +############################################################################### +# 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 # +############################################################################### from openlp.core.lib import str_to_bool from openlp.core.utils import ConfigHelper diff --git a/openlp/core/lib/settingstab.py b/openlp/core/lib/settingstab.py index ef46ba781..167fb206e 100644 --- a/openlp/core/lib/settingstab.py +++ b/openlp/core/lib/settingstab.py @@ -22,11 +22,11 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -from PyQt4 import QtGui +from PyQt4.QtGui import QWidget from openlp.core.lib import PluginConfig -class SettingsTab(QtGui.QWidget): +class SettingsTab(QWidget): """ SettingsTab is a helper widget for plugins to define Tabs for the settings dialog. @@ -43,7 +43,7 @@ class SettingsTab(QtGui.QWidget): Defaults to *None*. This is the section in the configuration file to write to when the ``save`` method is called. """ - QtGui.QWidget.__init__(self) + QWidget.__init__(self) self.tabTitle = title self.setupUi() self.retranslateUi() diff --git a/openlp/core/lib/themexmlhandler.py b/openlp/core/lib/themexmlhandler.py index 7778bffb0..610f30eec 100644 --- a/openlp/core/lib/themexmlhandler.py +++ b/openlp/core/lib/themexmlhandler.py @@ -372,8 +372,8 @@ class ThemeXML(object): """ Return a string representation of this object. """ - s = u'' - for k in dir(self): - if k[0:1] != u'_': - s += u'%30s: %s\n' %(k, getattr(self, k)) - return s + theme_strings = [] + for key in dir(self): + if key[0:1] != u'_': + theme_strings.append(u'%30s: %s' % (key, getattr(self, key))) + return u'\n'.join(theme_strings) diff --git a/openlp/core/lib/toolbar.py b/openlp/core/lib/toolbar.py index fcb443af6..1669e87be 100644 --- a/openlp/core/lib/toolbar.py +++ b/openlp/core/lib/toolbar.py @@ -22,12 +22,14 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -import types import logging -from PyQt4 import QtCore, QtGui +from PyQt4.QtGui import QToolBar, QIcon +from PyQt4.QtCore import QSize -class OpenLPToolbar(QtGui.QToolBar): +from openlp.core.lib import buildIcon + +class OpenLPToolbar(QToolBar): """ Lots of toolbars around the place, so it makes sense to have a common way to manage them. This is the base toolbar class. @@ -36,10 +38,10 @@ class OpenLPToolbar(QtGui.QToolBar): """ Initialise the toolbar. """ - QtGui.QToolBar.__init__(self, None) + QToolBar.__init__(self, None) # useful to be able to reuse button icons... self.icons = {} - self.setIconSize(QtCore.QSize(20, 20)) + self.setIconSize(QSize(20, 20)) self.actions = {} self.log = logging.getLogger(u'OpenLPToolbar') self.log.debug(u'Init done') @@ -66,17 +68,7 @@ class OpenLPToolbar(QtGui.QToolBar): ``objectname`` The name of the object, as used in `