forked from openlp/openlp
Moved Theme specific bits from xmlrootclass to theme
bzr-revno: 210
This commit is contained in:
parent
c64f1bd792
commit
822d3d9a0e
@ -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
|
||||
|
||||
|
@ -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():
|
||||
|
@ -45,6 +45,10 @@ blankstylexml=\
|
||||
</Theme>
|
||||
'''
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user