diff --git a/theme/test_theme.py b/theme/test_theme.py
new file mode 100644
index 000000000..2b6d9f421
--- /dev/null
+++ b/theme/test_theme.py
@@ -0,0 +1,43 @@
+from theme import Theme
+import wx
+import os.path
+def test_read_theme():
+ dir=os.path.split(__file__)[0]
+ # test we can read a theme
+ t=Theme(os.path.join(dir, "testtheme.xml"))
+ print t
+ assert(t.BackgroundParameter1 == "sunset1.jpg")
+ assert(t.BackgroundParameter2 == None)
+ assert(t.BackgroundParameter3 == None)
+ assert(t.BackgroundType == 2)
+ assert(t.FontColor == wx.Colour(255,255,255))
+ assert(t.FontName == "Tahoma")
+ assert(t.FontProportion == 16)
+ assert(t.HorizontalAlign == 2)
+ assert(t.Name == "openlp.org Packaged Theme")
+ assert(t.Outline == -1)
+ assert(t.OutlineColor == wx.Colour(255,0,0))
+ assert(t.Shadow == -1)
+ assert(t.ShadowColor == wx.Colour(0,0,1))
+ assert(t.VerticalAlign == 0)
+ # test we create a "blank" theme correctly
+ t=Theme()
+ print t
+ assert(t.BackgroundParameter1 == wx.Colour(0,0,0))
+ assert(t.BackgroundParameter2 == None)
+ assert(t.BackgroundParameter3 == None)
+ assert(t.BackgroundType == 0)
+ assert(t.FontColor == wx.Colour(255,255,255))
+ assert(t.FontName == "Arial")
+ assert(t.FontProportion == 30)
+ assert(t.HorizontalAlign == 0)
+ assert(t.Name == "BlankStyle")
+ assert(t.Outline == 0)
+ assert(t.Shadow == 0)
+ assert(t.VerticalAlign == 0)
+
+
+ print "Tests passed"
+
+if __name__=="__main__":
+ test_read_theme()
diff --git a/theme/testtheme.xml b/theme/testtheme.xml
new file mode 100644
index 000000000..63dfc1519
--- /dev/null
+++ b/theme/testtheme.xml
@@ -0,0 +1,17 @@
+
+
+ openlp.org Packaged Theme
+ 2
+ sunset1.jpg
+
+
+ Tahoma
+ clWhite
+ 16
+ -1
+ $00000001
+ -1
+ clRed
+ 2
+ 0
+
diff --git a/theme/theme.py b/theme/theme.py
new file mode 100644
index 000000000..4c0c484ad
--- /dev/null
+++ b/theme/theme.py
@@ -0,0 +1,124 @@
+from elementtree.ElementTree import ElementTree, XML
+import wx
+DelphiColors={"clRed":0xFF0000,
+ "clBlack":0x000000,
+ "clWhite":0xFFFFFF}
+
+blankstylexml=\
+'''
+
+ BlankStyle
+ 0
+ $000000
+
+
+ Arial
+ clWhite
+ 30
+ 0
+ 0
+ 0
+ 0
+
+
+'''
+
+class Theme:
+ def __init__(self, xmlfile=None):
+ """ stores the info about a theme
+ attributes:
+ name : theme name
+
+ BackgroundType : 0 - solid color
+ 1 - gradient color
+ 2 - image
+
+ BackgroundParameter1 : for image - filename
+ for gradient - start color
+ for solid - color
+ BackgroundParameter2 : for image - border colour
+ for gradient - end color
+ for solid - N/A
+ BackgroundParameter3 : for image - N/A
+ for gradient - 0 -> vertical, 1 -> horizontal
+
+ FontName : name of font to use
+ FontColor : color for main font
+ FontProportion : point size of font
+
+ Shadow : 0 - no shadow, non-zero use shadow
+ ShadowColor : color for drop shadow
+ Outline : 0 - no outline, non-zero use outline
+ OutlineColor : color for outline (or None for no outline)
+
+ HorizontalAlign : 0 - left align
+ 1 - right align
+ 2 - centre align
+ VerticalAlign : 0 - top align
+ 1 - bottom align
+ 2 - centre align
+ WrapStyle : 0 - normal
+ 1 - lyrics
+ """
+ # init to defaults
+ self._set_from_XML(blankstylexml)
+ 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)
+
+ 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= wx.Colour((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
+
+if __name__=="__main__":
+ test_theme.test_read_theme()