From 2dfbe1dcfc204e7f405be0e816cb6d966b1cf285 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 21 May 2009 06:15:51 +0100 Subject: [PATCH] Phase2 Operation Cleanup. --- openlp/__init__.py | 2 +- openlp/core/__init__.py | 1 - openlp/core/lib/__init__.py | 47 ++++++++++++++------------ openlp/core/lib/themexmlhandler.py | 6 ++-- openlp/core/ui/amendthemeform.py | 4 +-- openlp/core/ui/servicemanager.py | 3 +- openlp/plugins/bibles/bibleplugin.py | 9 ++--- openlp/plugins/bibles/lib/biblestab.py | 9 +++-- openlp/plugins/bibles/lib/mediaitem.py | 5 +-- openlp/plugins/media/lib/mediaitem.py | 3 +- openlp/plugins/media/lib/mediatab.py | 9 +++-- openlp/plugins/media/mediaplugin.py | 1 - 12 files changed, 46 insertions(+), 53 deletions(-) diff --git a/openlp/__init__.py b/openlp/__init__.py index b16ed4f5a..6bcd6d97a 100644 --- a/openlp/__init__.py +++ b/openlp/__init__.py @@ -1,7 +1,7 @@ """ OpenLP - Open Source Lyrics Projection Copyright (c) 2008 Raoul Snyman -Portions copyright (c) 2008 Martin Thompson, Tim Bentley +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 diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 49b685f44..e123886b5 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -22,4 +22,3 @@ from openlp.core.lib.pluginmanager import PluginManager __all__ = ['SettingsManager', 'PluginManager' ] - diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 47a5f2719..6da7517b8 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -19,6 +19,31 @@ Place, Suite 330, Boston, MA 02111-1307 USA """ import types from PyQt4 import QtCore, QtGui + +def translate(context, text): + return QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8) + +def file_to_xml(xmlfile): + return open(xmlfile).read() + +def str_to_bool(stringvalue): + return stringvalue.strip().lower() in (u'true', u'yes', u'y') + +def buildIcon(icon): + 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: + ButtonIcon.addPixmap(QtGui.QPixmap.fromImage(QImage(icon)), + QtGui.QIcon.Normal, QtGui.QIcon.Off) + return ButtonIcon + + from pluginconfig import PluginConfig from plugin import Plugin from settingstab import SettingsTab @@ -41,27 +66,7 @@ from rendermanager import RenderManager # 'XmlRootClass', 'ServiceItem', 'Receiver', 'OpenLPToolbar', 'SongXMLBuilder', # 'SongXMLParser', 'EventManager', 'ThemeXML', 'RenderManager'] -__all__ = [ 'translate', 'fileToXML', 'convertStringToBoolean','buildIcon' ] +__all__ = [ 'translate', 'file_to_xml', 'str_to_bool'] -def translate(context, text): - return QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8) -def fileToXML(xmlfile): - return open(xmlfile).read() -def convertStringToBoolean(stringvalue): - return stringvalue.strip().lower() in (u'true', u'yes', u'y') - -def buildIcon(icon): - 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: - ButtonIcon.addPixmap(QtGui.QPixmap.fromImage(QImage(icon)), - QtGui.QIcon.Normal, QtGui.QIcon.Off) - return ButtonIcon diff --git a/openlp/core/lib/themexmlhandler.py b/openlp/core/lib/themexmlhandler.py index 31063b28f..724ac57ab 100644 --- a/openlp/core/lib/themexmlhandler.py +++ b/openlp/core/lib/themexmlhandler.py @@ -22,7 +22,7 @@ from xml.etree.ElementTree import ElementTree, XML, dump For XML Schema see wiki.openlp.org """ import os, os.path -from openlp import convertStringToBoolean +from openlp.core.lib import str_to_bool from xml.dom.minidom import Document from xml.etree.ElementTree import ElementTree, XML, dump @@ -231,14 +231,14 @@ class ThemeXML(): master += e[1] + u'_' elif master == u'display_' and (element.tag == u'shadow' or element.tag == u'outline'): #print "b", master, element.tag, element.text, e[0], e[1] - et = convertStringToBoolean(element.text) + et = str_to_bool(element.text) setattr(self, master + element.tag , et) setattr(self, master + element.tag +u'_'+ e[0], e[1]) else: field = master + e[0] e1 = e[1] if e[1] == u'True' or e[1] == u'False': - e1 = convertStringToBoolean(e[1]) + e1 = str_to_bool(e[1]) setattr(self, field, e1) else: #print "c", element.tag, element.text diff --git a/openlp/core/ui/amendthemeform.py b/openlp/core/ui/amendthemeform.py index 2d0885cae..d2869317e 100644 --- a/openlp/core/ui/amendthemeform.py +++ b/openlp/core/ui/amendthemeform.py @@ -21,7 +21,7 @@ import logging import os, os.path from PyQt4 import QtCore, QtGui -from openlp.core.lib import ThemeXML, Renderer, fileToXML, translate +from openlp.core.lib import ThemeXML, Renderer, file_to_xml, translate from amendthemedialog import Ui_AmendThemeDialog @@ -141,7 +141,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog): self.theme.parse(self.baseTheme()) else: xml_file = os.path.join(self.path, theme, theme + u'.xml') - xml = fileToXML(xml_file) + xml = file_to_xml(xml_file) self.theme.parse(xml) self.allowPreview = False self.paintUi(self.theme) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 67141f61b..06a914d0f 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -21,8 +21,7 @@ import os import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import PluginConfig, OpenLPToolbar, ServiceItem, RenderManager, Event, EventType, EventManager, translate -from openlp import buildIcon +from openlp.core.lib import PluginConfig, OpenLPToolbar, ServiceItem, RenderManager, Event, EventType, EventManager, translate, buildIcon class ServiceManager(QtGui.QWidget): diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index d279c6aab..2385af506 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -21,10 +21,8 @@ import logging from PyQt4 import QtCore, QtGui from PyQt4.QtCore import * -from PyQt4.QtGui import * -from openlp.core.lib import Plugin, Event -from openlp.core.lib import EventType +from openlp.core.lib import Plugin, Event, EventType, translate from openlp.plugins.bibles.lib import BibleManager, BiblesTab, BibleMediaItem from openlp.plugins.bibles.lib.tables import * @@ -59,7 +57,7 @@ class BiblePlugin(Plugin): self.ImportBibleItem = QtGui.QAction(import_menu) self.ImportBibleItem.setObjectName("ImportBibleItem") import_menu.addAction(self.ImportBibleItem) - self.ImportBibleItem.setText(QtGui.QApplication.translate("main_window", "&Bible", None, QtGui.QApplication.UnicodeUTF8)) + self.ImportBibleItem.setText(translate("BiblePlugin", "&Bible")) # Signals and slots QtCore.QObject.connect(self.ImportBibleItem, QtCore.SIGNAL("triggered()"), self.onBibleNewClick) @@ -67,8 +65,7 @@ class BiblePlugin(Plugin): self.ExportBibleItem = QtGui.QAction(export_menu) self.ExportBibleItem.setObjectName("ExportBibleItem") export_menu.addAction(self.ExportBibleItem) - self.ExportBibleItem.setText( - QtGui.QApplication.translate("main_window", u'&Bible', None, QtGui.QApplication.UnicodeUTF8)) + self.ExportBibleItem.setText(translate("BiblePlugin", u'&Bible')) def initialise(self): pass diff --git a/openlp/plugins/bibles/lib/biblestab.py b/openlp/plugins/bibles/lib/biblestab.py index 8c3d96a5d..1f3d1b8a1 100644 --- a/openlp/plugins/bibles/lib/biblestab.py +++ b/openlp/plugins/bibles/lib/biblestab.py @@ -20,8 +20,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA from PyQt4 import Qt, QtCore, QtGui -from openlp.core import translate -from openlp import convertStringToBoolean +from openlp.core.lib import translate, str_to_bool from openlp.core.lib import SettingsTab class BiblesTab(SettingsTab): @@ -187,11 +186,11 @@ class BiblesTab(SettingsTab): self.bible_search = True def load(self): - self.paragraph_style = convertStringToBoolean(self.config.get_config(u'paragraph style', u'True')) - self.show_new_chapters = convertStringToBoolean(self.config.get_config(u'display new chapter', u"False")) + self.paragraph_style = str_to_bool(self.config.get_config(u'paragraph style', u'True')) + self.show_new_chapters = str_to_bool(self.config.get_config(u'display new chapter', u"False")) self.display_style = int(self.config.get_config(u'display brackets', u'0')) self.bible_theme = self.config.get_config(u'bible theme', u'0') - self.bible_search = convertStringToBoolean(self.config.get_config(u'search as type', u'True')) + self.bible_search = str_to_bool(self.config.get_config(u'search as type', u'True')) if self.paragraph_style: self.ParagraphRadioButton.setChecked(True) else: diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 5f0cb3f2c..e1d2c8a3a 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -21,10 +21,7 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core import translate -from openlp.core.lib import MediaManagerItem, Receiver -from openlp.core.lib import ServiceItem - +from openlp.core.lib import ServiceItem, MediaManagerItem, Receiver, translate from openlp.plugins.bibles.forms import BibleImportForm from openlp.plugins.bibles.lib import TextListData diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index b21d549b7..95eeeeb07 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -22,8 +22,7 @@ import os from PyQt4 import QtCore, QtGui -from openlp.core import translate -from openlp.core.lib import MediaManagerItem +from openlp.core.lib import MediaManagerItem, translate from openlp.plugins.media.lib import MediaTab from openlp.plugins.media.lib import FileListData diff --git a/openlp/plugins/media/lib/mediatab.py b/openlp/plugins/media/lib/mediatab.py index 1afe340d9..f557fde47 100644 --- a/openlp/plugins/media/lib/mediatab.py +++ b/openlp/plugins/media/lib/mediatab.py @@ -20,9 +20,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA from PyQt4 import QtCore, QtGui -from openlp.core import translate -from openlp import convertStringToBoolean -from openlp.core.lib import SettingsTab +from openlp.core.lib import SettingsTab, str_to_bool, translate class MediaTab(SettingsTab): """ @@ -67,11 +65,12 @@ class MediaTab(SettingsTab): def onVMRCheckBoxChanged(self): use_vmr_mode = self.UseVMRCheckBox.checkState() self.use_vmr_mode = False - if use_vmr_mode == 2: # we have a set value convert to True/False + if use_vmr_mode == 2: + # we have a set value convert to True/False self.use_vmr_mode = True def load(self): - self.use_vmr_mode = convertStringToBoolean(self.config.get_config(u'use mode layout', u'False')) + self.use_vmr_mode = str_to_bool(self.config.get_config(u'use mode layout', u'False')) if self.use_vmr_mode : self.UseVMRCheckBox.setChecked(True) diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index b04d4c32b..495dbe89c 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -20,7 +20,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA import os from PyQt4 import QtCore, QtGui -from openlp.core.resources import * from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab from openlp.plugins.media.lib import MediaTab,MediaMediaItem