From bf9b1c50fc69f116fe39242dfde060b70df2f987 Mon Sep 17 00:00:00 2001 From: Carsten Tinggaard Date: Thu, 30 Oct 2008 11:33:49 +0000 Subject: [PATCH] Using XmlRootClass. Added file.close bzr-revno: 58 --- openlp/theme/theme.py | 67 ++++--------------------------------------- 1 file changed, 5 insertions(+), 62 deletions(-) diff --git a/openlp/theme/theme.py b/openlp/theme/theme.py index ac579a93a..8218504c9 100644 --- a/openlp/theme/theme.py +++ b/openlp/theme/theme.py @@ -16,18 +16,13 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -import platform -ver = platform.python_version() -if ver >= '2.5': - from xml.etree.ElementTree import ElementTree, XML -else: - from elementtree import ElementTree, XML +import sys +import os from PyQt4 import QtGui +sys.path.append(os.path.abspath("./../..")) -DelphiColors={"clRed":0xFF0000, - "clBlack":0x000000, - "clWhite":0xFFFFFF} +from openlp.core.xmlrootclass import XmlRootClass blankstylexml=\ ''' @@ -48,7 +43,7 @@ blankstylexml=\ ''' -class Theme: +class Theme(XmlRootClass): def __init__(self, xmlfile=None): """ stores the info about a theme attributes: @@ -93,55 +88,3 @@ class Theme: t=''.join(file.readlines()) # read the file and change list to a string self._set_from_XML(t) - def _get_as_string(self): - s="" - keys=dir(self) - keys.sort() - for k in keys: - if k[0:1] != "_": - s+= "_%s_" %(getattr(self,k)) - return s - def _set_from_XML(self, xml): - root=ElementTree(element=XML(xml)) - iter=root.getiterator() - for element in iter: - if element.tag != "Theme": - t=element.text -# print element.tag, t, type(t) - if type(t) == type(None): # easy! - val=t - if type(t) == type(" "): # strings need special handling to sort the colours out -# print "str", - if t[0] == "$": # might be a hex number -# print "hex", - try: - val=int(t[1:], 16) - except ValueError: # nope -# print "nope", - pass - elif DelphiColors.has_key(t): -# print "colour", - val=DelphiColors[t] - else: -# print "last chance", - try: - val=int(t) -# print "int", - 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 wx.Colour - val= QtGui.QColor((val>>16) & 0xFF, (val>>8)&0xFF, val&0xFF) - # print [val] - setattr(self,element.tag, val) - - - def __str__(self): - s="" - for k in dir(self): - if k[0:1] != "_": - s+= "%30s : %s\n" %(k,getattr(self,k)) - return s -