forked from openlp/openlp
Using XmlRootClass. Added file.close
bzr-revno: 58
This commit is contained in:
parent
648646dcb5
commit
bf9b1c50fc
@ -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=\
|
||||
'''<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
@ -48,7 +43,7 @@ blankstylexml=\
|
||||
</Theme>
|
||||
'''
|
||||
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user