forked from openlp/openlp
Fix bugs from unicode migration in theme
Correct errors in Theme handling More code style fixes on route
This commit is contained in:
parent
0b0013331a
commit
d1b9b5b218
|
@ -16,8 +16,6 @@ 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
|
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
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
from xml.dom.minidom import Document
|
|
||||||
from xml.etree.ElementTree import ElementTree, XML, dump
|
|
||||||
|
|
||||||
For XML Schema see wiki.openlp.org
|
For XML Schema see wiki.openlp.org
|
||||||
"""
|
"""
|
||||||
|
@ -256,5 +254,5 @@ class ThemeXML():
|
||||||
s = u''
|
s = u''
|
||||||
for k in dir(self):
|
for k in dir(self):
|
||||||
if k[0:1] != u'_':
|
if k[0:1] != u'_':
|
||||||
s += u'%30s : %s\n' %(k,getattr(self,k))
|
s += u'%30s : %s\n' %(k, getattr(self, k))
|
||||||
return s
|
return s
|
||||||
|
|
|
@ -1,9 +1,26 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
||||||
|
"""
|
||||||
|
OpenLP - Open Source Lyrics Projection
|
||||||
|
Copyright (c) 2008 Raoul Snyman
|
||||||
|
Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten Tinggaard
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
"""
|
||||||
import platform
|
import platform
|
||||||
ver = platform.python_version()
|
import types
|
||||||
if ver >= '2.5':
|
from xml.etree.ElementTree import ElementTree, XML
|
||||||
from xml.etree.ElementTree import ElementTree, XML
|
|
||||||
else:
|
|
||||||
from elementtree import ElementTree, XML
|
|
||||||
|
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
|
@ -59,7 +76,7 @@ class Theme:
|
||||||
FontName : name of font to use
|
FontName : name of font to use
|
||||||
FontColor : color for main font
|
FontColor : color for main font
|
||||||
FontProportion : size of font
|
FontProportion : size of font
|
||||||
FontUnits : whether size of font is in <pixels> or <points>
|
FontUnits : whether size of font is in <pixels> or <points>
|
||||||
|
|
||||||
Shadow : 0 - no shadow, non-zero use shadow
|
Shadow : 0 - no shadow, non-zero use shadow
|
||||||
ShadowColor : color for drop shadow
|
ShadowColor : color for drop shadow
|
||||||
|
@ -78,52 +95,57 @@ class Theme:
|
||||||
# init to defaults
|
# init to defaults
|
||||||
self._set_from_XML(blankstylexml)
|
self._set_from_XML(blankstylexml)
|
||||||
self._set_from_XML(xml)
|
self._set_from_XML(xml)
|
||||||
|
# print self.__str__()
|
||||||
|
|
||||||
def _get_as_string(self):
|
def _get_as_string(self):
|
||||||
s=""
|
s = u''
|
||||||
keys=dir(self)
|
keys=dir(self)
|
||||||
keys.sort()
|
keys.sort()
|
||||||
for k in keys:
|
for k in keys:
|
||||||
if k[0:1] != "_":
|
if k[0:1] != u'_':
|
||||||
s+= "_%s_" %(getattr(self,k))
|
s += u'_%s_' %(getattr(self,k))
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def _set_from_XML(self, xml):
|
def _set_from_XML(self, xml):
|
||||||
root=ElementTree(element=XML(xml))
|
root = ElementTree(element=XML(xml))
|
||||||
iter=root.getiterator()
|
iter = root.getiterator()
|
||||||
for element in iter:
|
for element in iter:
|
||||||
if element.tag != "Theme":
|
if element.tag != u'Theme':
|
||||||
t=element.text
|
t = element.text
|
||||||
# print element.tag, t, type(t)
|
# print element.tag, t, type(t)
|
||||||
if type(t) == type(None): # easy!
|
val = 0
|
||||||
val=t
|
# easy!
|
||||||
if type(t) == type(u' '): # strings need special handling to sort the colours out
|
if type(t) == type(None):
|
||||||
# print "str",
|
val = t
|
||||||
if t[0] == "$": # might be a hex number
|
# strings need special handling to sort the colours out
|
||||||
# print "hex",
|
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',
|
||||||
try:
|
try:
|
||||||
val=int(t[1:], 16)
|
val = int(t[1:], 16)
|
||||||
except ValueError: # nope
|
except ValueError: # nope
|
||||||
# print "nope",
|
# print u'nope'
|
||||||
pass
|
pass
|
||||||
elif DelphiColors.has_key(t):
|
elif DelphiColors.has_key(t):
|
||||||
# print "colour",
|
# print u'colour ', t
|
||||||
val=DelphiColors[t]
|
val = DelphiColors[t]
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
val=int(t)
|
val = int(t)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
val=t
|
val = t
|
||||||
if (element.tag.find(u'Color') > 0 or
|
if (element.tag.find(u'Color') > 0 or
|
||||||
(element.tag.find(u'BackgroundParameter') == 0 and type(val) == type(0))):
|
(element.tag.find(u'BackgroundParameter') == 0 and type(val) == type(0))):
|
||||||
# convert to a wx.Colour
|
# convert to a wx.Colour
|
||||||
val= QtGui.QColor((val>>16) & 0xFF, (val>>8)&0xFF, val&0xFF)
|
val= QtGui.QColor((val>>16) & 0xFF, (val>>8)&0xFF, val&0xFF)
|
||||||
# print [val]
|
# print [val]
|
||||||
setattr(self,element.tag, val)
|
# print u'>> ', element.tag, val
|
||||||
|
setattr(self, element.tag, val)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s=""
|
s = u''
|
||||||
for k in dir(self):
|
for k in dir(self):
|
||||||
if k[0:1] != "_":
|
if k[0:1] != u'_':
|
||||||
s+= "%30s : %s\n" %(k,getattr(self,k))
|
s += u'%30s : %s\n' %(k, getattr(self, k))
|
||||||
return s
|
return s
|
||||||
|
|
|
@ -57,9 +57,9 @@ class ThemeData(QtCore.QAbstractListModel):
|
||||||
|
|
||||||
def insertRow(self, row, filename):
|
def insertRow(self, row, filename):
|
||||||
self.beginInsertRows(QtCore.QModelIndex(), row, row)
|
self.beginInsertRows(QtCore.QModelIndex(), row, row)
|
||||||
log.info(u'insert row %d:%s' % (row, filename))
|
log.debug(u'insert row %d:%s' % (row, filename))
|
||||||
(prefix, shortfilename) = os.path.split(unicode(filename))
|
(prefix, shortfilename) = os.path.split(unicode(filename))
|
||||||
log.info(u'shortfilename = %s' % shortfilename)
|
log.debug(u'shortfilename = %s' % shortfilename)
|
||||||
theme = shortfilename.split(u'.')
|
theme = shortfilename.split(u'.')
|
||||||
# create a preview image
|
# create a preview image
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
|
@ -81,7 +81,7 @@ class ThemeData(QtCore.QAbstractListModel):
|
||||||
pixmap.fill(QtCore.Qt.black)
|
pixmap.fill(QtCore.Qt.black)
|
||||||
# finally create the row
|
# finally create the row
|
||||||
self.items.insert(row, (filename, pixmap, shortfilename, theme[0]))
|
self.items.insert(row, (filename, pixmap, shortfilename, theme[0]))
|
||||||
log.info(u'Items: %s' % self.items)
|
log.debug(u'Items: %s' % self.items)
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
|
|
||||||
def removeRow(self, row):
|
def removeRow(self, row):
|
||||||
|
@ -190,8 +190,13 @@ class ThemeManager(QtGui.QWidget):
|
||||||
try:
|
try:
|
||||||
os.remove(os.path.join(self.path, th))
|
os.remove(os.path.join(self.path, th))
|
||||||
except:
|
except:
|
||||||
pass #if not present do not worry
|
#if not present do not worry
|
||||||
shutil.rmtree(os.path.join(self.path, theme))
|
pass
|
||||||
|
try:
|
||||||
|
shutil.rmtree(os.path.join(self.path, theme))
|
||||||
|
except:
|
||||||
|
#if not present do not worry
|
||||||
|
pass
|
||||||
self.themeData.clearItems()
|
self.themeData.clearItems()
|
||||||
self.loadThemes()
|
self.loadThemes()
|
||||||
|
|
||||||
|
@ -201,7 +206,7 @@ class ThemeManager(QtGui.QWidget):
|
||||||
def onImportTheme(self):
|
def onImportTheme(self):
|
||||||
files = QtGui.QFileDialog.getOpenFileNames(None,
|
files = QtGui.QFileDialog.getOpenFileNames(None,
|
||||||
translate(u'ThemeManager', u'Select Theme Import File'),
|
translate(u'ThemeManager', u'Select Theme Import File'),
|
||||||
self.path, u'Theme (*.theme)')
|
self.path, u'Theme (*.*)')
|
||||||
log.info(u'New Themes %s', unicode(files))
|
log.info(u'New Themes %s', unicode(files))
|
||||||
if len(files) > 0:
|
if len(files) > 0:
|
||||||
for file in files:
|
for file in files:
|
||||||
|
@ -335,7 +340,7 @@ class ThemeManager(QtGui.QWidget):
|
||||||
outfile = open(theme_file, u'w')
|
outfile = open(theme_file, u'w')
|
||||||
outfile.write(theme_xml)
|
outfile.write(theme_xml)
|
||||||
outfile.close()
|
outfile.close()
|
||||||
if image_from is not None and image_from is not image_to:
|
if image_from is not None and image_from != image_to:
|
||||||
shutil.copyfile(image_from, image_to)
|
shutil.copyfile(image_from, image_to)
|
||||||
self.generateAndSaveImage(self.path, name, theme_xml)
|
self.generateAndSaveImage(self.path, name, theme_xml)
|
||||||
self.themeData.clearItems()
|
self.themeData.clearItems()
|
||||||
|
|
Loading…
Reference in New Issue