2009-06-24 05:17:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2009 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten #
|
|
|
|
# Tinggaard, Jon Tibble, Jonathan Corwin, Maikel Stuivenberg, Scott Guerrieri #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2009-06-24 05:17:41 +00:00
|
|
|
|
2009-03-12 20:19:24 +00:00
|
|
|
import platform
|
2009-06-24 05:17:41 +00:00
|
|
|
import types
|
|
|
|
from xml.etree.ElementTree import ElementTree, XML
|
2008-10-23 19:49:13 +00:00
|
|
|
|
2008-06-16 19:51:19 +00:00
|
|
|
from PyQt4 import QtGui
|
|
|
|
|
2009-03-12 20:19:24 +00:00
|
|
|
DelphiColors={"clRed":0xFF0000,
|
2009-03-29 14:38:23 +00:00
|
|
|
"clBlue":0x0000FF,
|
|
|
|
"clYellow":0x0FFFF00,
|
2009-03-12 20:19:24 +00:00
|
|
|
"clBlack":0x000000,
|
|
|
|
"clWhite":0xFFFFFF}
|
2008-04-03 17:54:13 +00:00
|
|
|
|
|
|
|
blankstylexml=\
|
|
|
|
'''<?xml version="1.0" encoding="iso-8859-1"?>
|
|
|
|
<Theme>
|
|
|
|
<Name>BlankStyle</Name>
|
2009-03-22 07:13:34 +00:00
|
|
|
<BackgroundMode>1</BackgroundMode>
|
2009-03-29 14:38:23 +00:00
|
|
|
<BackgroundType>0</BackgroundType>
|
2008-04-03 17:54:13 +00:00
|
|
|
<BackgroundParameter1>$000000</BackgroundParameter1>
|
|
|
|
<BackgroundParameter2/>
|
|
|
|
<BackgroundParameter3/>
|
|
|
|
<FontName>Arial</FontName>
|
|
|
|
<FontColor>clWhite</FontColor>
|
|
|
|
<FontProportion>30</FontProportion>
|
2009-03-12 20:19:24 +00:00
|
|
|
<FontUnits>pixels</FontUnits>
|
2008-04-03 17:54:13 +00:00
|
|
|
<Shadow>0</Shadow>
|
|
|
|
<Outline>0</Outline>
|
|
|
|
<HorizontalAlign>0</HorizontalAlign>
|
|
|
|
<VerticalAlign>0</VerticalAlign>
|
2008-06-16 19:51:19 +00:00
|
|
|
<WrapStyle>0</WrapStyle>
|
2008-04-03 17:54:13 +00:00
|
|
|
</Theme>
|
|
|
|
'''
|
|
|
|
|
2009-03-12 20:19:24 +00:00
|
|
|
class Theme:
|
2009-04-06 18:45:45 +00:00
|
|
|
def __init__(self, xml):
|
2008-04-03 17:54:13 +00:00
|
|
|
""" stores the info about a theme
|
|
|
|
attributes:
|
|
|
|
name : theme name
|
2009-03-29 14:38:23 +00:00
|
|
|
|
2009-03-22 07:13:34 +00:00
|
|
|
BackgroundMode : 1 - Transparent
|
|
|
|
1 - Opaque
|
2009-03-29 14:38:23 +00:00
|
|
|
|
2008-04-03 17:54:13 +00:00
|
|
|
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
|
2009-03-29 14:38:23 +00:00
|
|
|
|
2008-04-03 17:54:13 +00:00
|
|
|
FontName : name of font to use
|
|
|
|
FontColor : color for main font
|
2009-03-12 20:19:24 +00:00
|
|
|
FontProportion : size of font
|
2009-06-24 05:17:41 +00:00
|
|
|
FontUnits : whether size of font is in <pixels> or <points>
|
2008-04-03 17:54:13 +00:00
|
|
|
|
|
|
|
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
|
2009-03-12 20:19:24 +00:00
|
|
|
self._set_from_XML(blankstylexml)
|
2009-04-06 18:45:45 +00:00
|
|
|
self._set_from_XML(xml)
|
2009-06-24 05:17:41 +00:00
|
|
|
# print self.__str__()
|
2009-03-12 20:19:24 +00:00
|
|
|
|
|
|
|
def _get_as_string(self):
|
2009-06-24 05:17:41 +00:00
|
|
|
s = u''
|
2009-03-12 20:19:24 +00:00
|
|
|
keys=dir(self)
|
|
|
|
keys.sort()
|
|
|
|
for k in keys:
|
2009-06-24 05:17:41 +00:00
|
|
|
if k[0:1] != u'_':
|
|
|
|
s += u'_%s_' %(getattr(self,k))
|
2009-03-12 20:19:24 +00:00
|
|
|
return s
|
2009-06-24 05:17:41 +00:00
|
|
|
|
2009-03-12 20:19:24 +00:00
|
|
|
def _set_from_XML(self, xml):
|
2009-06-24 05:17:41 +00:00
|
|
|
root = ElementTree(element=XML(xml))
|
|
|
|
iter = root.getiterator()
|
2009-03-12 20:19:24 +00:00
|
|
|
for element in iter:
|
2009-06-24 05:17:41 +00:00
|
|
|
if element.tag != u'Theme':
|
|
|
|
t = element.text
|
|
|
|
# print element.tag, t, type(t)
|
|
|
|
val = 0
|
|
|
|
# easy!
|
|
|
|
if type(t) == type(None):
|
|
|
|
val = t
|
|
|
|
# strings need special handling to sort the colours out
|
|
|
|
if type(t) is types.StringType or type(t) is types.UnicodeType:
|
|
|
|
# print u'str',
|
|
|
|
if t[0] == u'$': # might be a hex number
|
|
|
|
# print u'hex',
|
2009-03-12 20:19:24 +00:00
|
|
|
try:
|
2009-06-24 05:17:41 +00:00
|
|
|
val = int(t[1:], 16)
|
2009-03-12 20:19:24 +00:00
|
|
|
except ValueError: # nope
|
2009-06-24 05:17:41 +00:00
|
|
|
# print u'nope'
|
2009-03-12 20:19:24 +00:00
|
|
|
pass
|
|
|
|
elif DelphiColors.has_key(t):
|
2009-06-24 05:17:41 +00:00
|
|
|
# print u'colour ', t
|
|
|
|
val = DelphiColors[t]
|
2009-03-12 20:19:24 +00:00
|
|
|
else:
|
|
|
|
try:
|
2009-06-24 05:17:41 +00:00
|
|
|
val = int(t)
|
2009-03-12 20:19:24 +00:00
|
|
|
except ValueError:
|
2009-06-24 05:17:41 +00:00
|
|
|
val = t
|
2009-06-16 18:21:24 +00:00
|
|
|
if (element.tag.find(u'Color') > 0 or
|
|
|
|
(element.tag.find(u'BackgroundParameter') == 0 and type(val) == type(0))):
|
2009-03-12 20:19:24 +00:00
|
|
|
# convert to a wx.Colour
|
|
|
|
val= QtGui.QColor((val>>16) & 0xFF, (val>>8)&0xFF, val&0xFF)
|
2009-06-24 05:17:41 +00:00
|
|
|
# print [val]
|
|
|
|
# print u'>> ', element.tag, val
|
|
|
|
setattr(self, element.tag, val)
|
2009-03-12 20:19:24 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2009-06-24 05:17:41 +00:00
|
|
|
s = u''
|
2009-03-12 20:19:24 +00:00
|
|
|
for k in dir(self):
|
2009-06-24 05:17:41 +00:00
|
|
|
if k[0:1] != u'_':
|
|
|
|
s += u'%30s : %s\n' %(k, getattr(self, k))
|
|
|
|
return s
|