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() self.processEvents()
screens = [] screens = []
# Decide how many screens we have and their size # Decide how many screens we have and their size
for i in range (0 , self.desktop().numScreens()): for screen in xrange (0 , self.desktop().numScreens()):
screens.insert(i, (i+1, self.desktop().availableGeometry(i+1))) screens.insert(screen, (screen+1, self.desktop().availableGeometry(screen+1)))
log.info(u'Screen %d found with resolution %s', i+1, self.desktop().availableGeometry(i+1)) log.info(u'Screen %d found with resolution %s', screen+1, self.desktop().availableGeometry(screen+1))
# start the main app window # start the main app window
self.main_window = MainWindow(screens) self.main_window = MainWindow(screens)
self.main_window.show() 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 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
""" """
__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 OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman 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 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 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 settingsmanager import SettingsManager
from pluginmanager import PluginManager from pluginmanager import PluginManager
__all__ = ['Renderer', 'SettingsManager', 'PluginManager', 'translate', 'fileToXML'] __all__ = ['Renderer', 'SettingsManager', 'PluginManager', 'translate',
'fileToXML' ]
def translate(context, text): def translate(context, text):
return QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8) return QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8)
def fileToXML(xmlfile): def fileToXML(xmlfile):
return open(xmlfile).read() return open(xmlfile).read()

View File

@ -19,7 +19,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.resources import *
from openlp.core.lib import PluginConfig from openlp.core.lib import PluginConfig
class SettingsTab(QtGui.QWidget): class SettingsTab(QtGui.QWidget):
@ -39,7 +38,7 @@ class SettingsTab(QtGui.QWidget):
else: else:
self.config = PluginConfig(str(title)) self.config = PluginConfig(str(title))
self.load() self.load()
def setTitle(self, title): def setTitle(self, title):
self.tabTitle = title self.tabTitle = title
@ -51,15 +50,9 @@ class SettingsTab(QtGui.QWidget):
def retranslateUi(self): def retranslateUi(self):
pass pass
def load(self): def load(self):
pass pass
def save(self): def save(self):
pass 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 For XML Schema see wiki.openlp.org
""" """
from openlp import convertStringToBoolean
from xml.dom.minidom import Document from xml.dom.minidom import Document
from xml.etree.ElementTree import ElementTree, XML, dump 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(): class ThemeXML():
def __init__(self): def __init__(self):
# Create the minidom document # Create the minidom document
@ -31,11 +72,11 @@ class ThemeXML():
def new_document(self, name): def new_document(self, name):
# Create the <song> base element # 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_xml.appendChild(self.theme)
self.theme.setAttribute(u'version', u'1.0') 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) ctn = self.theme_xml.createTextNode(name)
self.name.appendChild(ctn) self.name.appendChild(ctn)
self.theme.appendChild(self.name) self.theme.appendChild(self.name)
@ -52,30 +93,23 @@ class ThemeXML():
background.setAttribute(u'type', u'solid') background.setAttribute(u'type', u'solid')
self.theme.appendChild(background) self.theme.appendChild(background)
color = self.theme_xml.createElement(u'color1') color = self.theme_xml.createElement(u'color')
bkc = self.theme_xml.createTextNode(bkcolor) bkc = self.theme_xml.createTextNode(bkcolor)
color.appendChild(bkc) color.appendChild(bkc)
background.appendChild(color) 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): def add_background_gradient(self, startcolor, endcolor, direction):
background = self.theme_xml.createElement(u'background') background = self.theme_xml.createElement(u'background')
background.setAttribute(u'mode', u'opaque') background.setAttribute(u'mode', u'opaque')
background.setAttribute(u'type', u'gradient') background.setAttribute(u'type', u'gradient')
self.theme.appendChild(background) self.theme.appendChild(background)
color = self.theme_xml.createElement(u'color1') color = self.theme_xml.createElement(u'startcolor')
bkc = self.theme_xml.createTextNode(startcolor) bkc = self.theme_xml.createTextNode(startcolor)
color.appendChild(bkc) color.appendChild(bkc)
background.appendChild(color) background.appendChild(color)
color = self.theme_xml.createElement(u'color2') color = self.theme_xml.createElement(u'endcolor')
bkc = self.theme_xml.createTextNode(endcolor) bkc = self.theme_xml.createTextNode(endcolor)
color.appendChild(bkc) color.appendChild(bkc)
background.appendChild(color) background.appendChild(color)
@ -96,33 +130,34 @@ class ThemeXML():
color.appendChild(bkc) color.appendChild(bkc)
background.appendChild(color) 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 = self.theme_xml.createElement(u'font')
background.setAttribute(u'type',fonttype) background.setAttribute(u'type',fonttype)
self.theme.appendChild(background) self.theme.appendChild(background)
name = self.theme_xml.createElement(u'name') element = self.theme_xml.createElement(u'name')
fn = self.theme_xml.createTextNode(fontname) fn = self.theme_xml.createTextNode(name)
name.appendChild(fn) element.appendChild(fn)
background.appendChild(name) background.appendChild(element)
name = self.theme_xml.createElement(u'color') element = self.theme_xml.createElement(u'color')
fn = self.theme_xml.createTextNode(fontcolor) fn = self.theme_xml.createTextNode(color)
name.appendChild(fn) element.appendChild(fn)
background.appendChild(name) background.appendChild(element)
name = self.theme_xml.createElement(u'proportion') element = self.theme_xml.createElement(u'proportion')
fn = self.theme_xml.createTextNode(fontproportion) fn = self.theme_xml.createTextNode(proportion)
name.appendChild(fn) element.appendChild(fn)
background.appendChild(name) background.appendChild(element)
name = self.theme_xml.createElement(u'location') element = self.theme_xml.createElement(u'location')
name.setAttribute(u'override',override) element.setAttribute(u'override',override)
name.setAttribute(u'x',str(xpos)) if override == True:
name.setAttribute(u'y',str(ypos)) element.setAttribute(u'x',str(xpos))
name.setAttribute(u'width',str(width)) element.setAttribute(u'y',str(ypos))
name.setAttribute(u'height',str(height)) element.setAttribute(u'width',str(width))
background.appendChild(name) element.setAttribute(u'height',str(height))
background.appendChild(element)
def add_display(self, shadow, shadowColor, outline, outlineColor, horizontal, vertical, wrap): def add_display(self, shadow, shadowColor, outline, outlineColor, horizontal, vertical, wrap):
background = self.theme_xml.createElement(u'display') background = self.theme_xml.createElement(u'display')
@ -170,6 +205,13 @@ class ThemeXML():
return self.theme_xml.toxml() return self.theme_xml.toxml()
def parse(self, xml): 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)) theme_xml = ElementTree(element=XML(xml))
iter=theme_xml.getiterator() iter=theme_xml.getiterator()
master = u'' master = u''
@ -185,13 +227,14 @@ class ThemeXML():
master += e[1] + u'_' master += e[1] + u'_'
elif master == u'display_' and (element.tag == u'shadow' or element.tag == u'outline'): 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] #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]) setattr(self, master + element.tag +u'_'+ e[0], e[1])
else: else:
field = master + e[0] field = master + e[0]
setattr(self, field, e[1]) setattr(self, field, e[1])
else: else:
#print "c", element.tag #print "c", element.tag, element.text
if element.tag is not None : if element.tag is not None :
field = master + element.tag field = master + element.tag
setattr(self, field, element.text) 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 Place, Suite 330, Boston, MA 02111-1307 USA
""" """
import logging import logging
import os, os.path
import sys import sys
from PyQt4 import QtGui, QtCore, Qt from PyQt4 import QtGui, QtCore, Qt
from copy import copy from copy import copy
#from interpolate import interpolate
class Renderer: class Renderer:
@ -40,7 +40,7 @@ class Renderer:
tell it to render a particular screenfull with render_screen(n) tell it to render a particular screenfull with render_screen(n)
""" """
def __init__(self): def __init__(self, path=None):
self._rect=None self._rect=None
self._debug=0 self._debug=0
self.words=None self.words=None
@ -50,6 +50,7 @@ class Renderer:
self._theme=None self._theme=None
self._bg_image_filename=None self._bg_image_filename=None
self._paint=None self._paint=None
self._path = path
def set_debug(self, debug): def set_debug(self, debug):
self._debug=debug self._debug=debug
@ -61,7 +62,9 @@ class Renderer:
def set_bg_image(self, filename): def set_bg_image(self, filename):
log.debug(u'set bg image %s', 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: if self._paint is not None:
self.scale_bg_image() self.scale_bg_image()
@ -71,6 +74,7 @@ class Renderer:
# rescale and offset # rescale and offset
imw=i.width() imw=i.width()
imh=i.height() imh=i.height()
print imw, imh
dcw=self._paint.width()+1 dcw=self._paint.width()+1
dch=self._paint.height() dch=self._paint.height()
imratio=imw/float(imh) imratio=imw/float(imh)
@ -128,7 +132,7 @@ class Renderer:
p=QtGui.QPainter() p=QtGui.QPainter()
p.begin(self._paint) p.begin(self._paint)
if self._theme.background_type == u'solid': 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 elif self._theme.background_type == u'gradient' : # gradient
gradient = None gradient = None
if self._theme.background_direction == u'vertical': if self._theme.background_direction == u'vertical':
@ -142,8 +146,8 @@ class Renderer:
h = int(self._paint.height())/2 h = int(self._paint.height())/2
gradient = QtGui.QRadialGradient(w, h, w) # Circular gradient = QtGui.QRadialGradient(w, h, w) # Circular
gradient.setColorAt(0, QtGui.QColor(self._theme.background_color1)) gradient.setColorAt(0, QtGui.QColor(self._theme.background_startColor))
gradient.setColorAt(1, QtGui.QColor(self._theme.background_color2)) gradient.setColorAt(1, QtGui.QColor(self._theme.background_endColor))
p.setBrush(QtGui.QBrush(gradient)) p.setBrush(QtGui.QBrush(gradient))
rectPath = QtGui.QPainterPath() rectPath = QtGui.QPainterPath()
@ -161,9 +165,9 @@ class Renderer:
elif self._theme.background_type== u'image': # image elif self._theme.background_type== u'image': # image
r=self._paint.rect() 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'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) #log.debug(u' Background Parameter %d ', self._theme.background_color1)
if self._theme.Bbackground_borderColor is not None: #if self._theme.background_color1 is not None:
p.fillRect(self._paint.rect(), self._theme.background_borderColor) # p.fillRect(self._paint.rect(), self._theme.background_borderColor)
p.drawPixmap(self.background_offsetx,self.background_offsety, self.img) p.drawPixmap(self.background_offsetx,self.background_offsety, self.img)
p.end() p.end()
log.debug(u'render background done') log.debug(u'render background done')
@ -192,7 +196,7 @@ class Renderer:
endline=startline+ratio endline=startline+ratio
while (endline<=numlines): while (endline<=numlines):
by=0 by=0
for (x,y) in bboxes[startline:endline]: for (x, y) in bboxes[startline:endline]:
by+=y by+=y
if by > bottom: if by > bottom:
good=0 good=0
@ -220,7 +224,7 @@ class Renderer:
endline=startline+1 endline=startline+1
while (endline<=numlines): while (endline<=numlines):
by=0 by=0
for (x,y) in bboxes[startline:endline]: for (x, y) in bboxes[startline:endline]:
by+=y by+=y
if by > bottom: if by > bottom:
retval.append(lines[startline:endline-1]) retval.append(lines[startline:endline-1])
@ -237,7 +241,7 @@ class Renderer:
y = rect.top() y = rect.top()
elif int(self._theme.display_verticalAlign) == 1: # bottom align elif int(self._theme.display_verticalAlign) == 1: # bottom align
y=rect.bottom()-bbox.height() 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 y=rect.top()+(rect.height()-bbox.height())/2
else: else:
assert(0, u'Invalid value for theme.VerticalAlign:%s' % self._theme.display_verticalAlign) assert(0, u'Invalid value for theme.VerticalAlign:%s' % self._theme.display_verticalAlign)
@ -254,11 +258,11 @@ class Renderer:
# put stuff on background so need to reset before doing the job properly. # put stuff on background so need to reset before doing the job properly.
self._render_background() self._render_background()
x, y = self._correctAlignment(self._rect, bbox) x, y = self._correctAlignment(self._rect, bbox)
bbox=self._render_lines_unaligned(lines, False, (x,y)) bbox=self._render_lines_unaligned(lines, False, (x, y))
if lines1 is not None: if lines1 is not None:
x, y = self._correctAlignment(self._rect_footer, bbox1) x, y = self._correctAlignment(self._rect_footer, bbox1)
bbox=self._render_lines_unaligned(lines1, True, (x,y) ) bbox=self._render_lines_unaligned(lines1, True, (x, y) )
log.debug(u'render lines DONE') log.debug(u'render lines DONE')
@ -273,7 +277,7 @@ class Renderer:
Returns the bounding box of the text as QRect""" Returns the bounding box of the text as QRect"""
log.debug(u'render unaligned %s', lines) log.debug(u'render unaligned %s', lines)
x,y=tlcorner x, y=tlcorner
brx=x brx=x
bry=y bry=y
for line in lines: for line in lines:
@ -284,7 +288,7 @@ class Renderer:
(thisx, bry) = self._render_single_line(line, footer, (x,bry)) (thisx, bry) = self._render_single_line(line, footer, (x,bry))
if (thisx > brx): if (thisx > brx):
brx=thisx brx=thisx
retval=QtCore.QRect(x,y,brx-x, bry-y) retval=QtCore.QRect(x, y,brx-x, bry-y)
if self._debug: if self._debug:
p=QtGui.QPainter() p=QtGui.QPainter()
p.begin(self._paint) p.begin(self._paint)
@ -303,10 +307,10 @@ class Renderer:
If the line is too wide for the context, it wraps, but If the line is too wide for the context, it wraps, but
right-aligns the surplus words in the manner of song lyrics right-aligns the surplus words in the manner of song lyrics
Returns the bottom-right corner (of what was rendered) as a tuple(x,y). Returns the bottom-right corner (of what was rendered) as a tuple(x, y).
""" """
#log.debug(u'Render single line %s @ %s '%( line, tlcorner)) #log.debug(u'Render single line %s @ %s '%( line, tlcorner))
x,y=tlcorner x, y=tlcorner
# We draw the text to see how big it is and then iterate to make it fit # We draw the text to see how big it is and then iterate to make it fit
# when we line wrap we do in in the "lyrics" style, so the second line is # when we line wrap we do in in the "lyrics" style, so the second line is
# right aligned with a "hanging indent" # right aligned with a "hanging indent"
@ -334,12 +338,13 @@ class Renderer:
rightextent=None rightextent=None
t=self._theme t=self._theme
align=t.display_horizontalAlign align=t.display_horizontalAlign
wrapstyle=t.display_wrapStyle wrapstyle=t.display_wrapStyle
for linenum in range(len(lines)): for linenum in range(len(lines)):
line=lines[linenum] line=lines[linenum]
#find out how wide line is #find out how wide line is
w,h=self._get_extent_and_render(line, footer, tlcorner=(x,y), draw=False) w,h=self._get_extent_and_render(line, footer, tlcorner=(x, y), draw=False)
if t.display_shadow: if t.display_shadow:
w+=self._shadow_offset w+=self._shadow_offset
@ -367,8 +372,8 @@ class Renderer:
draw=True, color = t.display_shadow_color) draw=True, color = t.display_shadow_color)
if t.display_outline: if t.display_outline:
self._get_extent_and_render(line, footer,(x+self._outline_offset,y), draw=True, color = t.display_outline_color) self._get_extent_and_render(line, footer,(x+self._outline_offset,y), draw=True, color = t.display_outline_color)
self._get_extent_and_render(line, footer,(x,y+self._outline_offset), draw=True, color = t.display_outline_color) self._get_extent_and_render(line, footer,(x, y+self._outline_offset), draw=True, color = t.display_outline_color)
self._get_extent_and_render(line, footer,(x,y-self._outline_offset), draw=True, color = t.display_outline_color) self._get_extent_and_render(line, footer,(x, y-self._outline_offset), draw=True, color = t.display_outline_color)
self._get_extent_and_render(line, footer,(x-self._outline_offset,y), draw=True, color = t.display_outline_color) self._get_extent_and_render(line, footer,(x-self._outline_offset,y), draw=True, color = t.display_outline_color)
if self._outline_offset > 1: if self._outline_offset > 1:
self._get_extent_and_render(line, footer,(x+self._outline_offset,y+self._outline_offset), draw=True, color = t.display_outline_color) self._get_extent_and_render(line, footer,(x+self._outline_offset,y+self._outline_offset), draw=True, color = t.display_outline_color)
@ -376,7 +381,7 @@ class Renderer:
self._get_extent_and_render(line, footer,(x+self._outline_offset,y-self._outline_offset), draw=True, color = t.display_outline_color) self._get_extent_and_render(line, footer,(x+self._outline_offset,y-self._outline_offset), draw=True, color = t.display_outline_color)
self._get_extent_and_render(line, footer,(x-self._outline_offset,y-self._outline_offset), draw=True, color = t.display_outline_color) self._get_extent_and_render(line, footer,(x-self._outline_offset,y-self._outline_offset), draw=True, color = t.display_outline_color)
self._get_extent_and_render(line, footer,tlcorner=(x,y), draw=True) self._get_extent_and_render(line, footer,tlcorner=(x, y), draw=True)
# log.debug(u'Line %2d: Render '%s' at (%d, %d) wh=(%d,%d)' % ( linenum, line, x, y,w,h) # log.debug(u'Line %2d: Render '%s' at (%d, %d) wh=(%d,%d)' % ( linenum, line, x, y,w,h)
y += h y += h
if linenum == 0: if linenum == 0:
@ -386,7 +391,7 @@ class Renderer:
p=QtGui.QPainter() p=QtGui.QPainter()
p.begin(self._paint) p.begin(self._paint)
p.setPen(QtGui.QPen(QtGui.QColor(0,255,0))) p.setPen(QtGui.QPen(QtGui.QColor(0,255,0)))
p.drawRect(startx,starty,rightextent-startx,y-starty) p.drawRect(startx,starty,rightextent-startx, y-starty)
p.end() p.end()
brcorner=(rightextent,y) brcorner=(rightextent,y)
@ -429,12 +434,12 @@ class Renderer:
p.setPen(QtGui.QColor(self._theme.font_main_color)) p.setPen(QtGui.QColor(self._theme.font_main_color))
else: else:
p.setPen(QtGui.QColor(color)) p.setPen(QtGui.QColor(color))
x,y=tlcorner x, y=tlcorner
metrics=QtGui.QFontMetrics(font) metrics=QtGui.QFontMetrics(font)
# xxx some fudges to make it exactly like wx! Take 'em out later # xxx some fudges to make it exactly like wx! Take 'em out later
w=metrics.width(line) w=metrics.width(line)
h=metrics.height()-2 h=metrics.height()-2
if draw: if draw:
p.drawText(x,y+metrics.height()-metrics.descent()-1, line) p.drawText(x, y+metrics.height()-metrics.descent()-1, line)
p.end() p.end()
return (w, h) return (w, h)

View File

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

View File

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

View File

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

View File

@ -21,8 +21,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core import translate from openlp.core import translate
from openlp import convertStringToBoolean
from openlp.core.lib import SettingsTab from openlp.core.lib import SettingsTab
from openlp.core.resources import *
class VideoTab(SettingsTab): class VideoTab(SettingsTab):
""" """
@ -49,12 +49,12 @@ class VideoTab(SettingsTab):
self.UseVMRLabel = QtGui.QLabel(self.VideoModeGroupBox) self.UseVMRLabel = QtGui.QLabel(self.VideoModeGroupBox)
self.UseVMRLabel.setObjectName("UseVMRLabel") self.UseVMRLabel.setObjectName("UseVMRLabel")
self.VideoModeLayout.addWidget(self.UseVMRLabel) self.VideoModeLayout.addWidget(self.UseVMRLabel)
self.VideoLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.VideoModeGroupBox) self.VideoLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.VideoModeGroupBox)
# Signals and slots # Signals and slots
QtCore.QObject.connect(self.UseVMRCheckBox, QtCore.QObject.connect(self.UseVMRCheckBox,
QtCore.SIGNAL("stateChanged(int)"), self.onVMRCheckBoxChanged) QtCore.SIGNAL("stateChanged(int)"), self.onVMRCheckBoxChanged)
def retranslateUi(self): def retranslateUi(self):
self.VideoModeGroupBox.setTitle(translate("SettingsForm", "Video Mode")) self.VideoModeGroupBox.setTitle(translate("SettingsForm", "Video Mode"))
self.UseVMRCheckBox.setText(translate("SettingsForm", "Use Video Mode Rendering")) self.UseVMRCheckBox.setText(translate("SettingsForm", "Use Video Mode Rendering"))
@ -69,11 +69,11 @@ class VideoTab(SettingsTab):
self.use_vmr_mode = False self.use_vmr_mode = False
if use_vmr_mode == 2: # we have a set value convert to True/False if use_vmr_mode == 2: # we have a set value convert to True/False
self.use_vmr_mode = True self.use_vmr_mode = True
def load(self): 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 : if self.use_vmr_mode :
self.UseVMRCheckBox.setChecked(True) self.UseVMRCheckBox.setChecked(True)
def save(self): def save(self):
self.config.set_config(u'use mode layout', str(self.use_vmr_mode)) self.config.set_config(u'use mode layout', str(self.use_vmr_mode))