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 #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2009-12-31 12:52:01 +00:00
|
|
|
# Copyright (c) 2008-2010 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
|
2010-03-21 23:58:01 +00:00
|
|
|
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
|
|
|
|
# Thompson, Jon Tibble, Carsten Tinggaard #
|
2009-09-08 19:58:05 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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 #
|
|
|
|
###############################################################################
|
2010-06-10 01:57:59 +00:00
|
|
|
"""
|
|
|
|
OpenLP version 1 theme handling
|
2009-06-24 05:17:41 +00:00
|
|
|
|
2010-06-10 01:57:59 +00:00
|
|
|
Provides reference data, a default v1 XML theme and class wrapper for
|
|
|
|
processing version 1 themes in OpenLP version 2.
|
|
|
|
"""
|
2009-06-24 05:17:41 +00:00
|
|
|
import types
|
2008-10-23 19:49:13 +00:00
|
|
|
|
2009-09-25 00:43:42 +00:00
|
|
|
from xml.etree.ElementTree import ElementTree, XML
|
2009-09-29 12:51:38 +00:00
|
|
|
from PyQt4 import QtGui
|
2008-06-16 19:51:19 +00:00
|
|
|
|
2010-05-28 15:01:50 +00:00
|
|
|
DELPHI_COLORS = {"clRed":0xFF0000,
|
|
|
|
"clBlue":0x0000FF,
|
|
|
|
"clYellow":0xFFFF00,
|
|
|
|
"clBlack":0x000000,
|
|
|
|
"clWhite":0xFFFFFF}
|
2008-04-03 17:54:13 +00:00
|
|
|
|
2010-05-28 15:01:50 +00:00
|
|
|
BLANK_STYLE_XML = \
|
2008-04-03 17:54:13 +00:00
|
|
|
'''<?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-09-29 02:54:32 +00:00
|
|
|
class Theme(object):
|
2010-06-10 01:57:59 +00:00
|
|
|
"""
|
|
|
|
Provide a class wrapper storing data from an XML theme
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
name : theme name
|
|
|
|
|
|
|
|
BackgroundMode : 1 - Transparent
|
|
|
|
1 - Opaque
|
|
|
|
|
|
|
|
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 : size of font
|
|
|
|
FontUnits : whether size of font is in <pixels> or <points>
|
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
2009-04-06 18:45:45 +00:00
|
|
|
def __init__(self, xml):
|
2010-06-10 01:57:59 +00:00
|
|
|
"""
|
|
|
|
Initialise a theme with data from xml
|
2008-04-03 17:54:13 +00:00
|
|
|
"""
|
|
|
|
# init to defaults
|
2010-05-28 15:01:50 +00:00
|
|
|
self._set_from_XML(BLANK_STYLE_XML)
|
2009-04-06 18:45:45 +00:00
|
|
|
self._set_from_XML(xml)
|
2009-03-12 20:19:24 +00:00
|
|
|
|
|
|
|
def _get_as_string(self):
|
2010-06-10 01:57:59 +00:00
|
|
|
"""
|
|
|
|
Return single line string representation of a theme
|
|
|
|
"""
|
2009-09-29 02:54:32 +00:00
|
|
|
theme_strings = []
|
|
|
|
keys = dir(self)
|
2009-03-12 20:19:24 +00:00
|
|
|
keys.sort()
|
2009-09-29 02:54:32 +00:00
|
|
|
for key in keys:
|
|
|
|
if key[0:1] != u'_':
|
|
|
|
theme_strings.append(u'_%s_' % (getattr(self, key)))
|
|
|
|
return u''.join(theme_strings)
|
2009-06-24 05:17:41 +00:00
|
|
|
|
2009-03-12 20:19:24 +00:00
|
|
|
def _set_from_XML(self, xml):
|
2010-06-10 01:57:59 +00:00
|
|
|
"""
|
|
|
|
Set theme class attributes with data from 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:
|
2010-02-22 16:42:10 +00:00
|
|
|
delphiColorChange = False
|
2009-06-24 05:17:41 +00:00
|
|
|
if element.tag != u'Theme':
|
2010-05-27 14:41:47 +00:00
|
|
|
element_text = element.text
|
2009-06-24 05:17:41 +00:00
|
|
|
val = 0
|
|
|
|
# easy!
|
2010-05-27 14:41:47 +00:00
|
|
|
if element_text is None:
|
|
|
|
val = element_text
|
2009-06-24 05:17:41 +00:00
|
|
|
# strings need special handling to sort the colours out
|
2010-05-27 14:41:47 +00:00
|
|
|
if type(element_text) is types.StringType or \
|
|
|
|
type(element_text) is types.UnicodeType:
|
|
|
|
if element_text[0] == u'$': # might be a hex number
|
2009-03-12 20:19:24 +00:00
|
|
|
try:
|
2010-05-27 14:41:47 +00:00
|
|
|
val = int(element_text[1:], 16)
|
2009-03-12 20:19:24 +00:00
|
|
|
except ValueError: # nope
|
|
|
|
pass
|
2010-05-28 15:01:50 +00:00
|
|
|
elif DELPHI_COLORS.has_key(element_text):
|
|
|
|
val = DELPHI_COLORS[element_text]
|
2010-02-22 16:42:10 +00:00
|
|
|
delphiColorChange = True
|
2009-03-12 20:19:24 +00:00
|
|
|
else:
|
|
|
|
try:
|
2010-05-27 14:41:47 +00:00
|
|
|
val = int(element_text)
|
2009-03-12 20:19:24 +00:00
|
|
|
except ValueError:
|
2010-05-27 14:41:47 +00:00
|
|
|
val = element_text
|
2009-06-16 18:21:24 +00:00
|
|
|
if (element.tag.find(u'Color') > 0 or
|
2010-05-24 22:37:20 +00:00
|
|
|
(element.tag.find(u'BackgroundParameter') == 0 and
|
|
|
|
type(val) == type(0))):
|
2009-03-12 20:19:24 +00:00
|
|
|
# convert to a wx.Colour
|
2010-05-24 22:37:20 +00:00
|
|
|
if not delphiColorChange:
|
|
|
|
val = QtGui.QColor(
|
|
|
|
val&0xFF, (val>>8)&0xFF, (val>>16)&0xFF)
|
|
|
|
else:
|
|
|
|
val = QtGui.QColor(
|
|
|
|
(val>>16)&0xFF, (val>>8)&0xFF, val&0xFF)
|
2009-06-24 05:17:41 +00:00
|
|
|
setattr(self, element.tag, val)
|
2009-03-12 20:19:24 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2010-06-10 01:57:59 +00:00
|
|
|
"""
|
|
|
|
Provide Python string representation for the class (multiline output)
|
|
|
|
"""
|
2009-09-29 02:54:32 +00:00
|
|
|
theme_strings = []
|
|
|
|
for key in dir(self):
|
|
|
|
if key[0:1] != u'_':
|
|
|
|
theme_strings.append(u'%30s : %s' % (key, getattr(self, key)))
|
2010-03-21 23:58:01 +00:00
|
|
|
return u'\n'.join(theme_strings)
|
2010-06-10 01:57:59 +00:00
|
|
|
|