Fix XML schema for naming

Fix ThemeManager and Renderer to cover changes
Move code for Boolean Config issues
Various code style fixes
This commit is contained in:
Tim Bentley 2009-04-15 05:58:51 +01:00
parent 6b4a5ff5d9
commit a662404122
10 changed files with 181 additions and 113 deletions

View File

@ -52,9 +52,9 @@ class OpenLP(QtGui.QApplication):
self.processEvents()
screens = []
# Decide how many screens we have and their size
for i in range (0 , self.desktop().numScreens()):
screens.insert(i, (i+1, self.desktop().availableGeometry(i+1)))
log.info(u'Screen %d found with resolution %s', i+1, self.desktop().availableGeometry(i+1))
for screen in xrange (0 , self.desktop().numScreens()):
screens.insert(screen, (screen+1, self.desktop().availableGeometry(screen+1)))
log.info(u'Screen %d found with resolution %s', screen+1, self.desktop().availableGeometry(screen+1))
# start the main app window
self.main_window = MainWindow(screens)
self.main_window.show()

View File

@ -15,3 +15,10 @@ 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
"""
__all__ = ['convertStringToBoolean']
def convertStringToBoolean(stringvalue):
if stringvalue.lower() == 'true':
return True
else:
return False

View File

@ -3,7 +3,7 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley
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
@ -23,11 +23,11 @@ from render import Renderer
from settingsmanager import SettingsManager
from pluginmanager import PluginManager
__all__ = ['Renderer', 'SettingsManager', 'PluginManager', 'translate', 'fileToXML']
__all__ = ['Renderer', 'SettingsManager', 'PluginManager', 'translate',
'fileToXML' ]
def translate(context, text):
return QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8)
def fileToXML(xmlfile):
return open(xmlfile).read()

View File

@ -19,7 +19,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
"""
from PyQt4 import QtCore, QtGui
from openlp.core.resources import *
from openlp.core.lib import PluginConfig
class SettingsTab(QtGui.QWidget):
@ -57,9 +56,3 @@ class SettingsTab(QtGui.QWidget):
def save(self):
pass
def convertStringToBoolean(self, stringvalue):
if stringvalue.lower() == 'true':
return True
else:
return False

View File

@ -21,9 +21,50 @@ from xml.etree.ElementTree import ElementTree, XML, dump
For XML Schema see wiki.openlp.org
"""
from openlp import convertStringToBoolean
from xml.dom.minidom import Document
from xml.etree.ElementTree import ElementTree, XML, dump
blankthemexml=\
'''<?xml version="1.0" encoding="iso-8859-1"?>
<theme version="1.0">
<name>BlankStyle</name>
<background mode="transparent"/>
<background type="solid" mode="opaque">
<color>#000000</color>
</background>
<background type="gradient" mode="opaque">
<startColor>#000000</startColor>
<endColor>#000000</endColor>
<direction>vertical</direction>
</background>
<background type="image" mode="opaque">
<filename>fred.bmp</filename>
</background>
<font type="main">
<name>Arial</name>
<color>#000000</color>
<proportion>30</proportion>
<location overide="False">
</location>
</font>
<font type="footer">
<name>Arial</name>
<color>#000000</color>
<proportion>12</proportion>
<location overide="True" x="10" y="10" width="100" height="150"/>
</font>
<display>
<shadow color="#000000">True</shadow>
<outline color="#000000">False</outline>
<horizontalAlign>0</horizontalAlign>
<verticalAlign>0</verticalAlign>
<wrapStyle>0</wrapStyle>
</display>
</theme>
'''
class ThemeXML():
def __init__(self):
# Create the minidom document
@ -31,11 +72,11 @@ class ThemeXML():
def new_document(self, name):
# Create the <song> base element
self.theme = self.theme_xml.createElement(u'Theme')
self.theme = self.theme_xml.createElement(u'theme')
self.theme_xml.appendChild(self.theme)
self.theme.setAttribute(u'version', u'1.0')
self.name = self.theme_xml.createElement(u'Name')
self.name = self.theme_xml.createElement(u'name')
ctn = self.theme_xml.createTextNode(name)
self.name.appendChild(ctn)
self.theme.appendChild(self.name)
@ -52,30 +93,23 @@ class ThemeXML():
background.setAttribute(u'type', u'solid')
self.theme.appendChild(background)
color = self.theme_xml.createElement(u'color1')
color = self.theme_xml.createElement(u'color')
bkc = self.theme_xml.createTextNode(bkcolor)
color.appendChild(bkc)
background.appendChild(color)
color = self.theme_xml.createElement(u'color2')
background.appendChild(color)
color = self.theme_xml.createElement(u'direction')
background.appendChild(color)
def add_background_gradient(self, startcolor, endcolor, direction):
background = self.theme_xml.createElement(u'background')
background.setAttribute(u'mode', u'opaque')
background.setAttribute(u'type', u'gradient')
self.theme.appendChild(background)
color = self.theme_xml.createElement(u'color1')
color = self.theme_xml.createElement(u'startcolor')
bkc = self.theme_xml.createTextNode(startcolor)
color.appendChild(bkc)
background.appendChild(color)
color = self.theme_xml.createElement(u'color2')
color = self.theme_xml.createElement(u'endcolor')
bkc = self.theme_xml.createTextNode(endcolor)
color.appendChild(bkc)
background.appendChild(color)
@ -96,33 +130,34 @@ class ThemeXML():
color.appendChild(bkc)
background.appendChild(color)
def add_font(self, fontname, fontcolor, fontproportion, override, fonttype=u'main', xpos=0, ypos=0 ,width=0, height=0):
def add_font(self, name, color, proportion, override, fonttype=u'main', xpos=0, ypos=0 ,width=0, height=0):
background = self.theme_xml.createElement(u'font')
background.setAttribute(u'type',fonttype)
self.theme.appendChild(background)
name = self.theme_xml.createElement(u'name')
fn = self.theme_xml.createTextNode(fontname)
name.appendChild(fn)
background.appendChild(name)
element = self.theme_xml.createElement(u'name')
fn = self.theme_xml.createTextNode(name)
element.appendChild(fn)
background.appendChild(element)
name = self.theme_xml.createElement(u'color')
fn = self.theme_xml.createTextNode(fontcolor)
name.appendChild(fn)
background.appendChild(name)
element = self.theme_xml.createElement(u'color')
fn = self.theme_xml.createTextNode(color)
element.appendChild(fn)
background.appendChild(element)
name = self.theme_xml.createElement(u'proportion')
fn = self.theme_xml.createTextNode(fontproportion)
name.appendChild(fn)
background.appendChild(name)
element = self.theme_xml.createElement(u'proportion')
fn = self.theme_xml.createTextNode(proportion)
element.appendChild(fn)
background.appendChild(element)
name = self.theme_xml.createElement(u'location')
name.setAttribute(u'override',override)
name.setAttribute(u'x',str(xpos))
name.setAttribute(u'y',str(ypos))
name.setAttribute(u'width',str(width))
name.setAttribute(u'height',str(height))
background.appendChild(name)
element = self.theme_xml.createElement(u'location')
element.setAttribute(u'override',override)
if override == True:
element.setAttribute(u'x',str(xpos))
element.setAttribute(u'y',str(ypos))
element.setAttribute(u'width',str(width))
element.setAttribute(u'height',str(height))
background.appendChild(element)
def add_display(self, shadow, shadowColor, outline, outlineColor, horizontal, vertical, wrap):
background = self.theme_xml.createElement(u'display')
@ -170,6 +205,13 @@ class ThemeXML():
return self.theme_xml.toxml()
def parse(self, xml):
self.baseParseXml()
self.parse_xml(xml)
def baseParseXml(self):
self.parse_xml(blankthemexml)
def parse_xml(self, xml):
theme_xml = ElementTree(element=XML(xml))
iter=theme_xml.getiterator()
master = u''
@ -185,13 +227,14 @@ class ThemeXML():
master += e[1] + u'_'
elif master == u'display_' and (element.tag == u'shadow' or element.tag == u'outline'):
#print "b", master, element.tag, element.text, e[0], e[1]
setattr(self, master + element.tag , element.text)
et = convertStringToBoolean(element.text)
setattr(self, master + element.tag , et)
setattr(self, master + element.tag +u'_'+ e[0], e[1])
else:
field = master + e[0]
setattr(self, field, e[1])
else:
#print "c", element.tag
#print "c", element.tag, element.text
if element.tag is not None :
field = master + element.tag
setattr(self, field, element.text)

View File

@ -18,12 +18,12 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
import os, os.path
import sys
from PyQt4 import QtGui, QtCore, Qt
from copy import copy
#from interpolate import interpolate
class Renderer:
@ -40,7 +40,7 @@ class Renderer:
tell it to render a particular screenfull with render_screen(n)
"""
def __init__(self):
def __init__(self, path=None):
self._rect=None
self._debug=0
self.words=None
@ -50,6 +50,7 @@ class Renderer:
self._theme=None
self._bg_image_filename=None
self._paint=None
self._path = path
def set_debug(self, debug):
self._debug=debug
@ -61,7 +62,9 @@ class Renderer:
def set_bg_image(self, filename):
log.debug(u'set bg image %s', filename)
self._bg_image_filename=filename
self._bg_image_filename=os.path.join(self._path, self._theme.theme_name, filename)
print self._bg_image_filename
if self._paint is not None:
self.scale_bg_image()
@ -71,6 +74,7 @@ class Renderer:
# rescale and offset
imw=i.width()
imh=i.height()
print imw, imh
dcw=self._paint.width()+1
dch=self._paint.height()
imratio=imw/float(imh)
@ -128,7 +132,7 @@ class Renderer:
p=QtGui.QPainter()
p.begin(self._paint)
if self._theme.background_type == u'solid':
p.fillRect(self._paint.rect(), QtGui.QColor(self._theme.background_color1))
p.fillRect(self._paint.rect(), QtGui.QColor(self._theme.background_color))
elif self._theme.background_type == u'gradient' : # gradient
gradient = None
if self._theme.background_direction == u'vertical':
@ -142,8 +146,8 @@ class Renderer:
h = int(self._paint.height())/2
gradient = QtGui.QRadialGradient(w, h, w) # Circular
gradient.setColorAt(0, QtGui.QColor(self._theme.background_color1))
gradient.setColorAt(1, QtGui.QColor(self._theme.background_color2))
gradient.setColorAt(0, QtGui.QColor(self._theme.background_startColor))
gradient.setColorAt(1, QtGui.QColor(self._theme.background_endColor))
p.setBrush(QtGui.QBrush(gradient))
rectPath = QtGui.QPainterPath()
@ -161,9 +165,9 @@ class Renderer:
elif self._theme.background_type== u'image': # image
r=self._paint.rect()
log.debug(u'Image size details %d %d %d %d ', r.x(), r.y(), r.width(),r.height())
log.debug(u' Background Parameter %d ', self._theme.background_borderColor)
if self._theme.Bbackground_borderColor is not None:
p.fillRect(self._paint.rect(), self._theme.background_borderColor)
#log.debug(u' Background Parameter %d ', self._theme.background_color1)
#if self._theme.background_color1 is not None:
# p.fillRect(self._paint.rect(), self._theme.background_borderColor)
p.drawPixmap(self.background_offsetx,self.background_offsety, self.img)
p.end()
log.debug(u'render background done')
@ -237,7 +241,7 @@ class Renderer:
y = rect.top()
elif int(self._theme.display_verticalAlign) == 1: # bottom align
y=rect.bottom()-bbox.height()
elif int(t.display_verticalAlign) == 2: # centre align
elif int(self._theme.display_verticalAlign) == 2: # centre align
y=rect.top()+(rect.height()-bbox.height())/2
else:
assert(0, u'Invalid value for theme.VerticalAlign:%s' % self._theme.display_verticalAlign)
@ -334,6 +338,7 @@ class Renderer:
rightextent=None
t=self._theme
align=t.display_horizontalAlign
wrapstyle=t.display_wrapStyle
for linenum in range(len(lines)):

View File

@ -97,29 +97,44 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
def onBackgroundTypeComboBoxSelected(self):
if self.BackgroundTypeComboBox.currentIndex() == 0: # Solid
self.theme.background_type = u'solid'
if self.theme.background_direction == None: # never defined
self.theme.background_direction = u'horizontal'
if self.theme.background_startColor is None :
self.theme.background_startColor = u'#000000'
if self.theme.background_endColor is None :
self.theme.background_endColor = u'#000000'
elif self.BackgroundTypeComboBox.currentIndex() == 1: # Gradient
self.theme.background_type = u'gradient'
if self.theme.background_direction == None: # never defined
self.theme.background_direction = u'horizontal'
self.theme.background_color2 = u'#000000'
if self.theme.background_startColor is None :
self.theme.background_startColor = u'#000000'
if self.theme.background_endColor is None :
self.theme.background_endColor = u'#000000'
else:
self.theme.background_type = u'image'
self.stateChanging(self.theme)
self.generateImage(self.theme)
def onColor1PushButtonClicked(self):
self.theme.background_color1 = QtGui.QColorDialog.getColor(
QColor(self.theme.background_color1), self).name()
if self.theme.background_type == u'solid':
self.theme.background_color = QtGui.QColorDialog.getColor(
QColor(self.theme.background_color), self).name()
self.Color1PushButton.setStyleSheet(
'background-color: %s' % str(self.theme.background_color1))
'background-color: %s' % str(self.theme.background_color))
else:
self.theme.background_startColor = QtGui.QColorDialog.getColor(
QColor(self.theme.background_startColor), self).name()
self.Color1PushButton.setStyleSheet(
'background-color: %s' % str(self.theme.background_startColor))
self.generateImage(self.theme)
def onColor2PushButtonClicked(self):
self.theme.background_color2 = QtGui.QColorDialog.getColor(
QColor(self.theme.background_color2), self).name()
self.theme.background_endColor = QtGui.QColorDialog.getColor(
QColor(self.theme.background_endColor), self).name()
self.Color2PushButton.setStyleSheet(
'background-color: %s' % str(self.theme.background_color2))
'background-color: %s' % str(self.theme.background_endColor))
self.generateImage(self.theme)
@ -165,7 +180,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
def stateChanging(self, theme):
if theme.background_type == u'solid':
self.Color1PushButton.setStyleSheet(
'background-color: %s' % str(theme.background_color1))
'background-color: %s' % str(theme.background_color))
self.Color1Label.setText(translate(u'ThemeManager', u'Background Font:'))
self.Color1Label.setVisible(True)
self.Color1PushButton.setVisible(True)
@ -173,9 +188,9 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.Color2PushButton.setVisible(False)
elif theme.background_type == u'gradient':
self.Color1PushButton.setStyleSheet(
'background-color: %s' % str(theme.background_color1))
'background-color: %s' % str(theme.background_startColor))
self.Color2PushButton.setStyleSheet(
'background-color: %s' % str(theme.background_color2))
'background-color: %s' % str(theme.background_endColor))
self.Color1Label.setText(translate(u'ThemeManager', u'First Color:'))
self.Color2Label.setText(translate(u'ThemeManager', u'Second Color:'))
self.Color1Label.setVisible(True)
@ -197,7 +212,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
frame=TstFrame(size)
frame=frame
paintdest=frame.GetPixmap()
r=Renderer()
r=Renderer(self.path)
r.set_paint_dest(paintdest)
r.set_theme(theme) # set default theme

View File

@ -236,6 +236,8 @@ class ThemeManager(QWidget):
def unzipTheme(self, filename, dir):
log.debug(u'Unzipping theme %s', filename)
zip = zipfile.ZipFile(str(filename))
filexml = None
themename = None
for file in zip.namelist():
if file.endswith('/'):
theme_dir = os.path.join(dir, file)
@ -243,21 +245,25 @@ class ThemeManager(QWidget):
os.mkdir(os.path.join(dir, file))
else:
fullpath = os.path.join(dir, file)
if themename is None:
names = file.split(u'/')
themename = names[0]
xml_data = zip.read(file)
if os.path.splitext (file) [1].lower () in [u'.xml']:
if self.checkVersion1(xml_data):
filexml = self.migrateVersion122(filename, fullpath, xml_data)
else:
file_xml = xml_data
outfile = open(fullpath, 'w')
outfile.write(filexml)
outfile.close()
self.generateImage(dir,names[0], filexml)
else:
if os.path.splitext (file) [1].lower () in [u'.bmp']:
if fullpath is not os.path.join(dir, file):
print os.path.splitext (file)
else:
outfile = open(fullpath, 'w')
outfile.write(zip.read(file))
outfile.close()
self.generateImage(dir,themename, filexml)
def checkVersion1(self, xmlfile):
log.debug(u'checkVersion1 ')
@ -297,7 +303,7 @@ class ThemeManager(QWidget):
return newtheme.extract_xml()
def generateImage(self, dir, name, theme_xml):
log.debug(u'generateImage %s %s ', dir, theme_xml)
log.debug(u'generateImage %s %s %s', dir, name, theme_xml)
theme = ThemeXML()
theme.parse(theme_xml)
#print theme
@ -305,11 +311,10 @@ class ThemeManager(QWidget):
frame=TstFrame(size)
frame=frame
paintdest=frame.GetPixmap()
r=Renderer()
r=Renderer(dir)
r.set_paint_dest(paintdest)
r.set_theme(theme) # set default theme
r._render_background()
r.set_text_rectangle(QtCore.QRect(0,0, size.width()-1, size.height()-1), QtCore.QRect(10,560, size.width()-1, size.height()-1))
lines=[]

View File

@ -21,8 +21,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
from PyQt4 import QtCore, QtGui
from openlp.core import translate
from openlp import convertStringToBoolean
from openlp.core.lib import SettingsTab
from openlp.core.resources import *
class BiblesTab(SettingsTab):
"""
@ -182,11 +182,11 @@ class BiblesTab(SettingsTab):
self.bible_search = True
def load(self):
self.paragraph_style = self.convertStringToBoolean(self.config.get_config('paragraph style', u'True'))
self.show_new_chapters = self.convertStringToBoolean(self.config.get_config('display new chapter', u"False"))
self.paragraph_style = convertStringToBoolean(self.config.get_config('paragraph style', u'True'))
self.show_new_chapters = convertStringToBoolean(self.config.get_config('display new chapter', u"False"))
self.display_style = int(self.config.get_config('display brackets', '0'))
self.bible_theme = int(self.config.get_config('bible theme', '0'))
self.bible_search = self.convertStringToBoolean(self.config.get_config('search as type', u'True'))
self.bible_search = convertStringToBoolean(self.config.get_config('search as type', u'True'))
if self.paragraph_style:
self.ParagraphRadioButton.setChecked(True)
else:

View File

@ -21,8 +21,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
from PyQt4 import QtCore, QtGui
from openlp.core import translate
from openlp import convertStringToBoolean
from openlp.core.lib import SettingsTab
from openlp.core.resources import *
class VideoTab(SettingsTab):
"""
@ -71,7 +71,7 @@ class VideoTab(SettingsTab):
self.use_vmr_mode = True
def load(self):
self.use_vmr_mode = self.convertStringToBoolean(self.config.get_config(u'use mode layout', u'False'))
self.use_vmr_mode = convertStringToBoolean(self.config.get_config(u'use mode layout', u'False'))
if self.use_vmr_mode :
self.UseVMRCheckBox.setChecked(True)