Fix rendering problems and issues with CustomSlides

bzr-revno: 434
This commit is contained in:
Tim Bentley 2009-05-01 17:22:35 +01:00
commit 1868109190
11 changed files with 108 additions and 86 deletions

View File

@ -33,7 +33,7 @@ class Renderer:
"""All the functions for rendering a set of words onto a Device Context
How to use:
set the words to be displayed with a call to set_words_openlp() - this returns an array of screenfuls of data
set the words to be displayed with a call to format_slide() - this returns an array of screenfuls of data
set a theme (if you need) with set_theme
tell it which DC to render to with set_DC()
set the borders of where you want the text (if not the whole DC) with set_text_rectangle()
@ -102,8 +102,7 @@ class Renderer:
def format_slide(self, words, footer):
log.debug(u'format_slide %s', words)
verses=[]
words=words.replace(u'\r\n', u'\n')
verses_text = words.split(u'\n')
verses_text = words.splitlines()
for v in verses_text:
lines=v.split(u'\n')
verses.append(self.split_set_of_lines(lines, footer)[0])

View File

@ -43,32 +43,41 @@ class RenderManager:
self.calculate_default(self.screen_list[self.current_display-1][1])
self.frame = None
def set_default_theme(self, theme):
log.debug("default theme set to %s", theme)
self.default_theme = self.theme_manager.getThemeData(theme)
self.renderer.set_theme(self.default_theme)
self.renderer.set_text_rectangle(QtCore.QRect(10,0, self.width-1, self.height-1),
QtCore.QRect(10,self.footer_start, self.width-1, self.height-self.footer_start))
def set_theme(self, theme):
log.debug("theme set to %s", theme)
def set_override_theme(self, theme):
log.debug("set override theme to %s", theme)
if theme is not None:
self.theme = theme
self.renderer.set_theme(self.theme)
else:
self.theme = self.default_theme
log.debug("theme is now %s", self.theme)
self.themedata = self.theme_manager.getThemeData(self.theme)
self.renderer.set_theme(self.themedata)
self.build_text_rectangle(self.themedata)
def build_text_rectangle(self, theme):
main_rect = None
footer_rect = None
self.renderer.set_text_rectangle(QtCore.QRect(10,0, self.width-1, self.height-1),
QtCore.QRect(10,self.footer_start, self.width-1, self.height-self.footer_start))
if theme.font_main_override == False:
pass
main_rect = QtCore.QRect(10,0, self.width-1, self.height-1)
else:
main_rect = QtCore.QRect(int(theme.font_main_x) , int(theme.font_main_y),
int(theme.font_main_width)-1, int(theme.font_main_height)-1)
if theme.font_footer_override == False:
pass
footer_rect = QtCore.QRect(10,self.footer_start, self.width-1, self.height-self.footer_start)
else:
footer_rect = QtCore.QRect(int(theme.font_footer_x),int(theme.font_footer_y),
int(theme.font_footer_width)-1, int(theme.font_footer_height)-1)
def generate_preview(self):
self.renderer.set_text_rectangle(main_rect,footer_rect)
def generate_preview(self, themedata):
self.calculate_default(QtCore.QSize(800,600))
self.renderer.set_theme(themedata)
self.renderer.set_text_rectangle(QtCore.QRect(10,0, self.width-1, self.height-1),
QtCore.QRect(10,self.footer_start, self.width-1, self.height-self.footer_start))
self.build_text_rectangle(themedata)
frame = QtGui.QPixmap(self.width, self.height)
self.renderer.set_paint_dest(frame)
@ -87,22 +96,12 @@ class RenderManager:
def format_slide(self, words, footer):
self.calculate_default(QtCore.QSize(800,600))
self.renderer.set_text_rectangle(QtCore.QRect(10,0, self.width-1, self.height-1),
QtCore.QRect(10,self.footer_start, self.width-1, self.height-self.footer_start))
return self.renderer.format_slide(words, footer)
def generate_slide(self,main_text, footer_text, preview=True):
if preview == True:
self.calculate_default(QtCore.QSize(800,600))
self.renderer.set_text_rectangle(QtCore.QRect(10,0, self.width-1, self.height-1),
QtCore.QRect(10,self.footer_start, self.width-1, self.height-self.footer_start))
#frame = QtGui.QPixmap(self.width, self.height)
#self.renderer.set_paint_dest(frame)
#print main_text
answer=self.renderer.render_lines(main_text, footer_text)
return self.frame

View File

@ -81,6 +81,7 @@ class SongXMLParser():
iter=self.song_xml.getiterator()
verse_list = []
for element in iter:
#print element.tag, element.attrib, element.text
if element.tag == u'verse':
verse_list.append([element.attrib, element.text])
return verse_list

View File

@ -151,11 +151,12 @@ class ThemeXML():
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))
if override == u'True':
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):

View File

@ -111,12 +111,21 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
#else:
#newtheme.add_background_image(str(self.theme.))
new_theme.add_font(str(self.theme.font_main_name), str(self.theme.font_main_color), str(self.theme.font_main_proportion), u'False')
new_theme.add_font(str(self.theme.font_footer_name), str(self.theme.font_footer_color), str(self.theme.font_footer_proportion), u'False', u'footer')
new_theme.add_display(str(self.theme.display_shadow), str(self.theme.display_shadow_color), str(self.theme.display_outline), str(self.theme.display_outline_color),
str(self.theme.display_horizontalAlign), str(self.theme.display_verticalAlign), str(self.theme.display_wrapStyle))
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_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_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),
str(self.theme.display_outline), str(self.theme.display_outline_color),
str(self.theme.display_horizontalAlign), str(self.theme.display_verticalAlign),
str(self.theme.display_wrapStyle))
theme = new_theme.extract_xml()
self.thememanager.saveTheme(theme_name, theme)
return QtGui.QDialog.accept(self)
@ -124,6 +133,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.path = path
def loadTheme(self, theme):
log.debug(u'LoadTheme %s ', theme)
if theme == None:
self.theme.parse(self.baseTheme())
else:
@ -207,15 +217,13 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.theme.font_footer_proportion = value
self.previewTheme(self.theme)
def onFontFooterDefaultCheckBoxChanged(self):
self.stateChanging(self.theme)
self.previewTheme(self.theme)
def onFontFooterDefaultCheckBoxChanged(self, value):
if value == 2: # checked
self.theme.font_footer_override = False
else:
self.theme.font_footer_override = True
if int(self.theme.font_footer_x) == 0 and int(self.theme.font_footer_y) == 0 and \
int(self.theme.font_footer_width) == 0 and int(self.theme.font_footer_height) == 0:
self.theme.font_footer_x = u'10'
@ -228,7 +236,6 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.FontFooterWidthSpinBox.setValue(int(self.theme.font_footer_width))
self.FontFooterHeightSpinBox.setValue(int(self.theme.font_footer_height))
self.stateChanging(self.theme)
self.previewTheme(self.theme)
@ -354,19 +361,18 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
#Local Methods
#
def baseTheme(self):
log.debug(u'base Theme')
log.debug(u'base theme created')
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), False)
newtheme.add_font(str(QFont().family()), str(u'#FFFFFF'), str(12), False, u'footer')
newtheme.add_display(str(False), str(u'#FFFFFF'), str(False), str(u'#FFFFFF'),
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_display(u'False', str(u'#FFFFFF'), u'False', str(u'#FFFFFF'),
str(0), str(0), str(0))
return newtheme.extract_xml()
def paintUi(self, theme):
print theme # leave as helpful for initial development
self.stateChanging(theme)
self.ThemeNameEdit.setText(self.theme.theme_name)
if self.theme.background_mode == u'opaque':

View File

@ -143,7 +143,7 @@ class ServiceManager(QWidget):
QtCore.SIGNAL("activated(int)"), self.onThemeComboBoxSelected)
def onThemeComboBoxSelected(self, currentIndex):
self.renderManager.set_default_theme(self.ThemeComboBox.currentText())
self.renderManager.default_theme = self.ThemeComboBox.currentText()
def addServiceItem(self, item):
"""Adds service item"""
@ -197,5 +197,5 @@ class ServiceManager(QWidget):
self.ThemeComboBox.clear()
for theme in theme_list:
self.ThemeComboBox.addItem(theme)
self.renderManager.set_default_theme(self.ThemeComboBox.currentText())
self.renderManager.default_theme = self.ThemeComboBox.currentText()

View File

@ -33,31 +33,35 @@ class SlideController(QtGui.QWidget):
self.PaneLayout.setSpacing(50)
self.PaneLayout.setMargin(0)
# self.Controller = QtGui.QGraphicsView(self.Splitter)
#self.VerseListView = QtGui.QListWidget(customEditDialog)
#self.VerseListView.setObjectName("VerseListView")
#self.horizontalLayout_4.addWidget(self.VerseListView)
self.Controller = QtGui.QScrollArea(self.Splitter)
self.Controller.setWidgetResizable(True)
self.ControllerContents = QtGui.QWidget(self.Controller)
self.ControllerContents.setGeometry(QtCore.QRect(0, 0, 228, 536))
self.Controller.setGeometry(QtCore.QRect(0, 0, 828, 536))
self.Controller.setWidget(self.ControllerContents)
#self.Screen = QtGui.QGraphicsView(self.Splitter)
#self.Screen.setMaximumSize(QtCore.QSize(16777215, 250))
self.ThemePreview = QtGui.QLabel(self.Splitter)
self.SlidePreview = QtGui.QLabel(self.Splitter)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.ThemePreview.sizePolicy().hasHeightForWidth())
self.ThemePreview.setSizePolicy(sizePolicy)
self.ThemePreview.setMinimumSize(QtCore.QSize(250, 190))
self.ThemePreview.setFrameShape(QtGui.QFrame.WinPanel)
self.ThemePreview.setFrameShadow(QtGui.QFrame.Sunken)
self.ThemePreview.setLineWidth(1)
self.ThemePreview.setScaledContents(True)
self.ThemePreview.setObjectName("ThemePreview")
sizePolicy.setHeightForWidth(self.SlidePreview.sizePolicy().hasHeightForWidth())
self.SlidePreview.setSizePolicy(sizePolicy)
self.SlidePreview.setMinimumSize(QtCore.QSize(250, 190))
self.SlidePreview.setFrameShape(QtGui.QFrame.WinPanel)
self.SlidePreview.setFrameShadow(QtGui.QFrame.Sunken)
self.SlidePreview.setLineWidth(1)
self.SlidePreview.setScaledContents(True)
self.SlidePreview.setObjectName("SlidePreview")
def previewFrame(self, frame):
self.ThemePreview.setPixmap(frame)
self.SlidePreview.setPixmap(frame)
imageLabel = QtGui.QLabel()
imageLabel.setPixmap(frame)
self.Controller.setWidget(imageLabel)

View File

@ -219,7 +219,6 @@ class ThemeManager(QWidget):
def loadThemes(self):
log.debug(u'Load themes from dir')
# self.themelist = [u'African Sunset', u'Snowy Mountains', u'Wilderness', u'Wet and Windy London']
for root, dirs, files in os.walk(self.path):
for name in files:
if name.endswith(u'.png'):
@ -232,6 +231,7 @@ class ThemeManager(QWidget):
return self.Theme_data.getList()
def getThemeData(self, themename):
log.debug(u'getthemedata for theme %s', themename)
xml_file = os.path.join(self.path, str(themename), str(themename)+u'.xml')
xml = fileToXML(xml_file)
theme = ThemeXML()
@ -344,9 +344,8 @@ class ThemeManager(QWidget):
im.save(samplepathname, u'png')
log.debug(u'Theme image written to %s',samplepathname)
def generateImage(self, theme):
log.debug(u'generateImage %s ', theme)
self.renderManager.set_theme(theme)
frame = self.renderManager.generate_preview()
def generateImage(self, themedata):
log.debug(u'generateImage %s ', themedata)
frame = self.renderManager.generate_preview(themedata)
return frame

View File

@ -355,6 +355,7 @@ class BibleMediaItem(MediaManagerItem):
if len(footer_lines) <= 1:
footer_lines.append(book)
self.parent.render_manager.set_override_theme(None)
frame=self.parent.render_manager.generate_slide(main_lines, footer_lines)
self.parent.preview_controller.previewFrame(frame)

View File

@ -80,7 +80,7 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
if id != 0:
self.customSlide = self.custommanager.get_custom(id)
self.TitleEdit.setText(self.customSlide.title)
self.CreditEdit.setText(self.customSlide.title)
self.CreditEdit.setText(self.customSlide.credits)
songXML=SongXMLParser(self.customSlide.text)
verseList = songXML.get_verses()
@ -170,5 +170,9 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
self.TitleLabel.setStyleSheet('color: red')
else:
self.TitleLabel.setStyleSheet('color: black')
if self.VerseListView.count() == 0: # must have 1 slide
invalid += 1
if invalid == 1:
self.valid = False

View File

@ -189,20 +189,28 @@ class CustomMediaItem(MediaManagerItem):
main_lines=[]
footer_lines = []
slide = None
theme = None
for index in indexes:
id = self.CustomListData.getId(index)
customSlide = self.parent.custommanager.get_custom(id)
title = customSlide.title
credit = customSlide.title
credit = customSlide.credits
theme = customSlide.theme_name
if len(theme) == 0 or theme == None:
self.parent.render_manager.set_override_theme(None)
else:
self.parent.render_manager.set_override_theme(theme)
songXML=SongXMLParser(customSlide.text)
verseList = songXML.get_verses()
for verse in verseList:
slide = self.parent.render_manager.format_slide(verse[1], False)
print verse
print slide
footer_lines.append(title + u' '+ credit)
frame=self.parent.render_manager.generate_slide(slide, footer_lines)
if slide is not None:
frame=self.parent.render_manager.generate_slide(slide, footer_lines, False)
self.parent.preview_controller.previewFrame(frame)
def onCustomLiveClick(self):