forked from openlp/openlp
More cleanups
Fix Rendering bugs with images Fix Theme choice bugs
This commit is contained in:
parent
190a371f56
commit
4c76ffdbaa
|
@ -177,13 +177,11 @@ class Renderer:
|
|||
painter.drawPath(rectPath)
|
||||
|
||||
elif self._theme.background_type== u'image': # image
|
||||
r = self._frame.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_color1)
|
||||
#if self._theme.background_color1 is not None:
|
||||
# p.fillRect(self._frame.rect(), self._theme.background_borderColor)
|
||||
#r = self._frame.rect()
|
||||
#log.debug(u'Image size details %d %d %d %d ', r.x(), r.y(), r.width(),r.height())
|
||||
if self.bg_image is not None:
|
||||
painter.drawPixmap(self.background_offsetx,self.background_offsety, self.bg_image)
|
||||
#painter.drawPixmap(self.background_offsetx,self.background_offsety, self.bg_image)
|
||||
painter.drawPixmap(0 ,0 , self.bg_image)
|
||||
else:
|
||||
painter.fillRect(self._frame.rect(), QtGui.QColor(u'#000000'))
|
||||
painter.end()
|
||||
|
@ -207,21 +205,22 @@ class Renderer:
|
|||
|
||||
numlines = len(lines)
|
||||
bottom = self._rect.bottom()
|
||||
for ratio in (numlines, numlines/2, numlines/3, numlines/4):
|
||||
good = 1
|
||||
startline = 0
|
||||
endline = startline + ratio
|
||||
while (endline <= numlines):
|
||||
by = 0
|
||||
for (x, y) in bboxes[startline:endline]:
|
||||
by += y
|
||||
if by > bottom:
|
||||
good=0
|
||||
break
|
||||
startline += ratio
|
||||
endline = startline+ratio
|
||||
if good == 1:
|
||||
#for ratio in (numlines): #, numlines/2, numlines/3, numlines/4):
|
||||
ratio = numlines
|
||||
good = 1
|
||||
startline = 0
|
||||
endline = startline + ratio
|
||||
while (endline <= numlines):
|
||||
by = 0
|
||||
for (x, y) in bboxes[startline:endline]:
|
||||
by += y
|
||||
if by > bottom:
|
||||
good=0
|
||||
break
|
||||
startline += ratio
|
||||
endline = startline+ratio
|
||||
# if good == 1:
|
||||
# break
|
||||
|
||||
retval = []
|
||||
numlines_per_page = ratio
|
||||
|
|
|
@ -84,11 +84,13 @@ class RenderManager:
|
|||
else:
|
||||
if theme is not None:
|
||||
self.theme = theme
|
||||
elif self.global_style == u'Service':
|
||||
elif self.global_style == u'Song' or self.global_style == u'Service':
|
||||
if self.service_theme == u'':
|
||||
self.theme = self.global_theme
|
||||
else:
|
||||
self.theme = self.service_theme
|
||||
else:
|
||||
self.theme = self.global_theme
|
||||
|
||||
if self.theme is not self.renderer.theme_name:
|
||||
log.debug(u'theme is now %s', self.theme)
|
||||
|
|
|
@ -69,12 +69,14 @@ class ThemeXML():
|
|||
# Create the minidom document
|
||||
self.theme_xml = Document()
|
||||
|
||||
def extend_filename(self, path):
|
||||
def extend_image_filename(self, path):
|
||||
"""
|
||||
Add the path name to the image name so the background can be rendered.
|
||||
"""
|
||||
if self.background_filename is not None:
|
||||
self.background_filename = os.path.join(path, self.theme_name, self.background_filename)
|
||||
|
||||
def new_document(self, name):
|
||||
# Create the <song> base element
|
||||
self.theme = self.theme_xml.createElement(u'theme')
|
||||
self.theme_xml.appendChild(self.theme)
|
||||
self.theme.setAttribute(u'version', u'1.0')
|
||||
|
@ -85,89 +87,92 @@ class ThemeXML():
|
|||
self.theme.appendChild(self.name)
|
||||
|
||||
def add_background_transparent(self):
|
||||
# Create the main <lyrics> element
|
||||
"""
|
||||
Add a transparent background.
|
||||
"""
|
||||
background = self.theme_xml.createElement(u'background')
|
||||
background.setAttribute(u'mode', u'transparent')
|
||||
self.theme.appendChild(background)
|
||||
|
||||
def add_background_solid(self, bkcolor):
|
||||
"""
|
||||
Add a Solid background.
|
||||
"""
|
||||
background = self.theme_xml.createElement(u'background')
|
||||
background.setAttribute(u'mode', u'opaque')
|
||||
background.setAttribute(u'type', u'solid')
|
||||
self.theme.appendChild(background)
|
||||
|
||||
color = self.theme_xml.createElement(u'color')
|
||||
bkc = self.theme_xml.createTextNode(bkcolor)
|
||||
color.appendChild(bkc)
|
||||
background.appendChild(color)
|
||||
self.child_element(background, u'color', bkcolor)
|
||||
|
||||
def add_background_gradient(self, startcolor, endcolor, direction):
|
||||
"""
|
||||
Add a gradient background.
|
||||
"""
|
||||
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'startColor')
|
||||
bkc = self.theme_xml.createTextNode(startcolor)
|
||||
color.appendChild(bkc)
|
||||
background.appendChild(color)
|
||||
|
||||
color = self.theme_xml.createElement(u'endColor')
|
||||
bkc = self.theme_xml.createTextNode(endcolor)
|
||||
color.appendChild(bkc)
|
||||
background.appendChild(color)
|
||||
|
||||
color = self.theme_xml.createElement(u'direction')
|
||||
bkc = self.theme_xml.createTextNode(direction)
|
||||
color.appendChild(bkc)
|
||||
background.appendChild(color)
|
||||
# Create startColor element
|
||||
self.child_element(background, u'startColor', startcolor)
|
||||
# Create endColor element
|
||||
self.child_element(background, u'endColor', endcolor)
|
||||
# Create direction element
|
||||
self.child_element(background, u'direction', direction)
|
||||
|
||||
def add_background_image(self, filename):
|
||||
"""
|
||||
Add a image background.
|
||||
"""
|
||||
background = self.theme_xml.createElement(u'background')
|
||||
background.setAttribute(u'mode', u'opaque')
|
||||
background.setAttribute(u'type', u'image')
|
||||
self.theme.appendChild(background)
|
||||
|
||||
color = self.theme_xml.createElement(u'filename')
|
||||
bkc = self.theme_xml.createCDATASection(filename)
|
||||
color.appendChild(bkc)
|
||||
background.appendChild(color)
|
||||
#Create Filename element
|
||||
self.child_element(background, u'filename', filename)
|
||||
|
||||
def add_font(self, name, color, proportion, override, fonttype=u'main', xpos=0, ypos=0 ,width=0, height=0):
|
||||
"""
|
||||
Add a Font.
|
||||
"""
|
||||
background = self.theme_xml.createElement(u'font')
|
||||
background.setAttribute(u'type',fonttype)
|
||||
self.theme.appendChild(background)
|
||||
|
||||
element = self.theme_xml.createElement(u'name')
|
||||
fn = self.theme_xml.createTextNode(name)
|
||||
element.appendChild(fn)
|
||||
background.appendChild(element)
|
||||
#Create Font name element
|
||||
self.child_element(background, u'name', name)
|
||||
|
||||
element = self.theme_xml.createElement(u'color')
|
||||
fn = self.theme_xml.createTextNode(color)
|
||||
element.appendChild(fn)
|
||||
background.appendChild(element)
|
||||
#Create Font color element
|
||||
self.child_element(background, u'color', color)
|
||||
|
||||
element = self.theme_xml.createElement(u'proportion')
|
||||
fn = self.theme_xml.createTextNode(proportion)
|
||||
element.appendChild(fn)
|
||||
background.appendChild(element)
|
||||
#Create Proportion name element
|
||||
self.child_element(background, u'proportion', proportion)
|
||||
|
||||
#Create Proportion name element
|
||||
self.child_element(background, u'proportion', proportion)
|
||||
|
||||
#Create Location element
|
||||
element = self.theme_xml.createElement(u'location')
|
||||
element.setAttribute(u'override',override)
|
||||
|
||||
if override == u'True':
|
||||
element.setAttribute(u'x',xpos)
|
||||
element.setAttribute(u'y',ypos)
|
||||
element.setAttribute(u'width',width)
|
||||
element.setAttribute(u'height',height)
|
||||
element.setAttribute(u'x', xpos)
|
||||
element.setAttribute(u'y', ypos)
|
||||
element.setAttribute(u'width', width)
|
||||
element.setAttribute(u'height', height)
|
||||
background.appendChild(element)
|
||||
|
||||
def add_display(self, shadow, shadowColor, outline, outlineColor, horizontal, vertical, wrap):
|
||||
"""
|
||||
Add a Display options.
|
||||
"""
|
||||
background = self.theme_xml.createElement(u'display')
|
||||
self.theme.appendChild(background)
|
||||
|
||||
tagElement = self.theme_xml.createElement(u'shadow')
|
||||
|
||||
tagElement.setAttribute(u'color',shadowColor)
|
||||
tagValue = self.theme_xml.createTextNode(shadow)
|
||||
tagElement.appendChild(tagValue)
|
||||
|
@ -194,15 +199,15 @@ class ThemeXML():
|
|||
tagElement.appendChild(tagValue)
|
||||
background.appendChild(tagElement)
|
||||
|
||||
def child_element(self, tag, value):
|
||||
tagElement = self.theme_xml.createElement(tag)
|
||||
tagValue = self.theme_xml.createTextNode(value)
|
||||
tagElement.appendChild(ftagValue)
|
||||
self.background.appendChild(tagElement)
|
||||
def child_element(self, element, tag, value):
|
||||
child = self.theme_xml.createElement(tag)
|
||||
child.appendChild(self.theme_xml.createTextNode(value))
|
||||
element.appendChild(child)
|
||||
return child
|
||||
|
||||
def dump_xml(self):
|
||||
# Debugging aid to see what we have
|
||||
print self.theme_xml.toprettyxml(indent=" ")
|
||||
print self.theme_xml.toprettyxml(indent=u' ')
|
||||
|
||||
def extract_xml(self):
|
||||
# Print our newly created XML
|
||||
|
@ -211,18 +216,19 @@ class ThemeXML():
|
|||
def parse(self, xml):
|
||||
self.baseParseXml()
|
||||
self.parse_xml(xml)
|
||||
self.theme_filename_extended = False
|
||||
|
||||
def baseParseXml(self):
|
||||
self.parse_xml(blankthemexml)
|
||||
|
||||
def parse_xml(self, xml):
|
||||
theme_xml = ElementTree(element=XML(xml))
|
||||
iter=theme_xml.getiterator()
|
||||
iter = theme_xml.getiterator()
|
||||
master = u''
|
||||
for element in iter:
|
||||
#print element.tag, element.text
|
||||
if len(element.getchildren()) > 0:
|
||||
master= element.tag + u'_'
|
||||
master = element.tag + u'_'
|
||||
if len(element.attrib) > 0:
|
||||
#print "D", element.tag , element.attrib
|
||||
for e in element.attrib.iteritems():
|
||||
|
@ -233,7 +239,7 @@ class ThemeXML():
|
|||
#print "b", master, element.tag, element.text, e[0], e[1]
|
||||
et = str_to_bool(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:
|
||||
field = master + e[0]
|
||||
e1 = e[1]
|
||||
|
@ -242,7 +248,7 @@ class ThemeXML():
|
|||
setattr(self, field, e1)
|
||||
else:
|
||||
#print "c", element.tag, element.text
|
||||
if element.tag is not None :
|
||||
if element.tag is not None:
|
||||
field = master + element.tag
|
||||
setattr(self, field, element.text)
|
||||
|
||||
|
@ -250,5 +256,5 @@ class ThemeXML():
|
|||
s = u''
|
||||
for k in dir(self):
|
||||
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
|
||||
|
|
|
@ -32,7 +32,9 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
|||
def __init__(self, thememanager, parent=None):
|
||||
QtGui.QDialog.__init__(self, parent)
|
||||
self.thememanager = thememanager
|
||||
self.theme = ThemeXML() # Needed here as UI setup generates Events
|
||||
# Needed here as UI setup generates Events
|
||||
self.path = None
|
||||
self.theme = ThemeXML()
|
||||
self.setupUi(self)
|
||||
|
||||
#define signals
|
||||
|
@ -111,15 +113,15 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
|||
else:
|
||||
(path, filename) =os.path.split(str(self.theme.background_filename))
|
||||
new_theme.add_background_image(filename)
|
||||
save_to= os.path.join(self.path, theme_name,filename )
|
||||
save_to= os.path.join(self.path, theme_name, filename )
|
||||
save_from = self.theme.background_filename
|
||||
|
||||
new_theme.add_font(str(self.theme.font_main_name), str(self.theme.font_main_color),
|
||||
str(self.theme.font_main_proportion), str(self.theme.font_main_override),u'main',
|
||||
str(self.theme.font_main_proportion), str(self.theme.font_main_override), u'main',
|
||||
str(self.theme.font_main_x), str(self.theme.font_main_y), str(self.theme.font_main_width),
|
||||
str(self.theme.font_main_height))
|
||||
new_theme.add_font(str(self.theme.font_footer_name), str(self.theme.font_footer_color),
|
||||
str(self.theme.font_footer_proportion), str(self.theme.font_footer_override),u'footer',
|
||||
str(self.theme.font_footer_proportion), str(self.theme.font_footer_override), u'footer',
|
||||
str(self.theme.font_footer_x), str(self.theme.font_footer_y), str(self.theme.font_footer_width),
|
||||
str(self.theme.font_footer_height) )
|
||||
new_theme.add_display(str(self.theme.display_shadow), str(self.theme.display_shadow_color),
|
||||
|
@ -132,9 +134,6 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
|||
self.thememanager.saveTheme(theme_name, theme, save_from, save_to)
|
||||
return QtGui.QDialog.accept(self)
|
||||
|
||||
def themePath(self, path):
|
||||
self.path = path
|
||||
|
||||
def loadTheme(self, theme):
|
||||
log.debug(u'LoadTheme %s', theme)
|
||||
if theme == None:
|
||||
|
@ -143,6 +142,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
|||
xml_file = os.path.join(self.path, theme, theme + u'.xml')
|
||||
xml = file_to_xml(xml_file)
|
||||
self.theme.parse(xml)
|
||||
self.theme.extend_image_filename(self.path)
|
||||
self.allowPreview = False
|
||||
self.paintUi(self.theme)
|
||||
self.allowPreview = True
|
||||
|
|
|
@ -231,3 +231,4 @@ class ServiceManager(QtGui.QWidget):
|
|||
id = 0 # Not Found
|
||||
self.service_theme = u''
|
||||
self.ThemeComboBox.setCurrentIndex(id)
|
||||
self.RenderManager.set_service_theme(self.service_theme)
|
||||
|
|
|
@ -28,7 +28,7 @@ from PyQt4 import QtCore, QtGui
|
|||
|
||||
from openlp.core.ui import AmendThemeForm, ServiceManager
|
||||
from openlp.core.theme import Theme
|
||||
from openlp.core.lib import Event, EventType, EventManager, OpenLPToolbar, ThemeXML, Renderer, translate
|
||||
from openlp.core.lib import Event, EventType, EventManager, OpenLPToolbar, ThemeXML, Renderer, translate, file_to_xml
|
||||
from openlp.core.utils import ConfigHelper
|
||||
|
||||
import logging
|
||||
|
@ -103,7 +103,6 @@ class ThemeData(QtCore.QAbstractListModel):
|
|||
retval = self.items[row][1]
|
||||
else:
|
||||
retval = QtCore.QVariant()
|
||||
#log.info("Returning"+ str(retval))
|
||||
if type(retval) is not type(QtCore.QVariant):
|
||||
return QtCore.QVariant(retval)
|
||||
else:
|
||||
|
@ -168,7 +167,7 @@ class ThemeManager(QtGui.QWidget):
|
|||
self.themelist = []
|
||||
self.path = os.path.join(ConfigHelper.get_data_path(), u'themes')
|
||||
self.checkThemesExists(self.path)
|
||||
self.amendThemeForm.themePath(self.path)
|
||||
self.amendThemeForm.path = self.path
|
||||
|
||||
def onAddTheme(self):
|
||||
self.amendThemeForm.loadTheme(None)
|
||||
|
@ -220,7 +219,6 @@ class ThemeManager(QtGui.QWidget):
|
|||
self.ServiceManager.updateThemeList(self.getThemes())
|
||||
self.parent.settingsForm.ThemesTab.updateThemeList(self.getThemes())
|
||||
|
||||
|
||||
def getThemes(self):
|
||||
return self.themeData.getList()
|
||||
|
||||
|
@ -228,19 +226,19 @@ class ThemeManager(QtGui.QWidget):
|
|||
log.debug(u'getthemedata for theme %s', themename)
|
||||
xml_file = os.path.join(self.path, str(themename), str(themename) + u'.xml')
|
||||
try:
|
||||
xml = fileToXML(xml_file)
|
||||
xml = file_to_xml(xml_file)
|
||||
except:
|
||||
newtheme = ThemeXML()
|
||||
newtheme.new_document(u'New Theme')
|
||||
newtheme.add_background_solid(str(u'#000000'))
|
||||
newtheme.add_font(str(QFont().family()), str(u'#FFFFFF'), str(30), u'False')
|
||||
newtheme.add_font(str(QFont().family()), str(u'#FFFFFF'), str(12), u'False', u'footer')
|
||||
newtheme.add_font(str(QtGui.QFont().family()), str(u'#FFFFFF'), str(30), u'False')
|
||||
newtheme.add_font(str(QtGui.QFont().family()), str(u'#FFFFFF'), str(12), u'False', u'footer')
|
||||
newtheme.add_display(u'False', str(u'#FFFFFF'), u'False', str(u'#FFFFFF'),
|
||||
str(0), str(0), str(0))
|
||||
xml = newtheme.extract_xml()
|
||||
theme = ThemeXML()
|
||||
theme.parse(xml)
|
||||
theme.extend_filename(self.path)
|
||||
theme.extend_image_filename(self.path)
|
||||
return theme
|
||||
|
||||
def checkThemesExists(self, dir):
|
||||
|
@ -347,7 +345,7 @@ class ThemeManager(QtGui.QWidget):
|
|||
log.debug(u'generateAndSaveImage %s %s %s', dir, name, theme_xml)
|
||||
theme = ThemeXML()
|
||||
theme.parse(theme_xml)
|
||||
theme.extend_filename(dir)
|
||||
theme.extend_image_filename(dir)
|
||||
frame = self.generateImage(theme)
|
||||
im = frame.toImage()
|
||||
samplepathname = os.path.join(self.path, name + u'.png')
|
||||
|
|
Loading…
Reference in New Issue