From 822d3d9a0e0daf552bb546e6dc553587b56cbc0b Mon Sep 17 00:00:00 2001 From: Martin Thompson Date: Wed, 10 Dec 2008 21:40:19 +0000 Subject: [PATCH] Moved Theme specific bits from xmlrootclass to theme bzr-revno: 210 --- openlp/core/lib/xmlrootclass.py | 20 +++++++------------- openlp/core/theme/test/test_theme.py | 4 ++-- openlp/core/theme/theme.py | 17 +++++++++++++++-- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/openlp/core/lib/xmlrootclass.py b/openlp/core/lib/xmlrootclass.py index e96ba6546..23fbe19ae 100644 --- a/openlp/core/lib/xmlrootclass.py +++ b/openlp/core/lib/xmlrootclass.py @@ -31,15 +31,15 @@ else: from elementtree import ElementTree, XML -# borrowed from theme - can be common -DelphiColors={"clRed":0xFF0000, - "clBlack":0x000000, - "clWhite":0xFFFFFF} - class XmlRootClass(object): """Root class for themes, songs etc provides interface for parsing xml files into object attributes + + if you overload this class and provide a function called + post_tag_hook, it will be called thusly for each tag,value pair: + + (element.tag, val) = self.post_tag_hook(element.tag, val) """ def _setFromXml(self, xml, rootTag): """Set song properties from given xml content @@ -66,9 +66,6 @@ class XmlRootClass(object): except ValueError: # nope #print "nope", pass - elif DelphiColors.has_key(t): - #print "colour", - val=DelphiColors[t] else: #print "last chance", try: @@ -77,11 +74,8 @@ class XmlRootClass(object): except ValueError: #print "give up", val=t - if (element.tag.find("Color") > 0 or - (element.tag.find("BackgroundParameter") == 0 and type(val) == type(0))): - # convert to a QtGui.Color - val= QtGui.QColor((val>>16) & 0xFF, (val>>8)&0xFF, val&0xFF) - #print [val] + if hasattr(self, "post_tag_hook"): + (element.tag, val) = self.post_tag_hook(element.tag, val) setattr(self,element.tag, val) pass diff --git a/openlp/core/theme/test/test_theme.py b/openlp/core/theme/test/test_theme.py index 64e13724c..5ab7791ec 100644 --- a/openlp/core/theme/test/test_theme.py +++ b/openlp/core/theme/test/test_theme.py @@ -20,10 +20,10 @@ import os import sys mypath=os.path.split(os.path.abspath(__file__))[0] -sys.path.insert(0,(os.path.join(mypath, '..' ,'..', '..'))) +sys.path.insert(0,(os.path.join(mypath, '..' ,'..', '..','..'))) print sys.path -from openlp.theme import Theme +from openlp.core.theme import Theme import os.path from PyQt4 import QtGui def test_read_theme(): diff --git a/openlp/core/theme/theme.py b/openlp/core/theme/theme.py index 30f05736d..a56e67e3b 100644 --- a/openlp/core/theme/theme.py +++ b/openlp/core/theme/theme.py @@ -45,6 +45,10 @@ blankstylexml=\ ''' +DelphiColors={"clRed":0xFF0000, + "clBlack":0x000000, + "clWhite":0xFFFFFF} + class Theme(XmlRootClass): def __init__(self, xmlfile=None): """ stores the info about a theme @@ -83,10 +87,19 @@ class Theme(XmlRootClass): 1 - lyrics """ # init to defaults - self._set_from_XML(blankstylexml) + self._setFromXml(blankstylexml, 'Theme') if xmlfile != None: # init from xmlfile file=open(xmlfile) t=''.join(file.readlines()) # read the file and change list to a string - self._set_from_XML(t) + self._setFromXml(t, 'Theme') + def post_tag_hook(self, tag, val): + if DelphiColors.has_key(val): + val=DelphiColors[val] + if (tag.find("Color") > 0 or + (tag.find("BackgroundParameter") == 0 and type(val) == type(0))): + # convert to a QtGui.Color + val= QtGui.QColor((val>>16) & 0xFF, (val>>8)&0xFF, val&0xFF) + + return (tag, val)