← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/ThemeManager2 into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/ThemeManager2 into lp:openlp.

Requested reviews:
    openlp.org Core (openlp-core)

More Renderer cleanups
Fix bugs in custom where it is possible to have no slides
RenderManager not handles theme decisions correctly and allows the overrides to work.

Fix up themes so most functions work correctly. (You can even have footers at the top of the page)
-- 
https://code.launchpad.net/~trb143/openlp/ThemeManager2/+merge/6073
Your team openlp.org Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/lib/renderer.py'
--- openlp/core/lib/renderer.py	2009-04-28 19:20:03 +0000
+++ openlp/core/lib/renderer.py	2009-05-01 05:02:53 +0000
@@ -33,7 +33,7 @@
     """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 @@
     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])

=== modified file 'openlp/core/lib/rendermanager.py'
--- openlp/core/lib/rendermanager.py	2009-04-25 06:38:21 +0000
+++ openlp/core/lib/rendermanager.py	2009-05-01 05:02:53 +0000
@@ -43,32 +43,41 @@
         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)
-        self.theme = theme
-        self.renderer.set_theme(self.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_override_theme(self, theme):
+        log.debug("set override theme to %s",  theme)
+        if theme is not None:
+            self.theme = 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
+
         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
-
-    def generate_preview(self):
+            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)
+
+        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 @@
 
     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
 

=== modified file 'openlp/core/lib/songxmlhandler.py'
--- openlp/core/lib/songxmlhandler.py	2009-04-06 18:45:45 +0000
+++ openlp/core/lib/songxmlhandler.py	2009-04-30 21:02:28 +0000
@@ -81,6 +81,7 @@
         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

=== modified file 'openlp/core/lib/themexmlhandler.py'
--- openlp/core/lib/themexmlhandler.py	2009-04-21 19:45:50 +0000
+++ openlp/core/lib/themexmlhandler.py	2009-04-30 21:02:28 +0000
@@ -151,11 +151,12 @@
 
         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):

=== modified file 'openlp/core/ui/amendthemeform.py'
--- openlp/core/ui/amendthemeform.py	2009-04-28 19:20:03 +0000
+++ openlp/core/ui/amendthemeform.py	2009-04-30 21:02:28 +0000
@@ -111,12 +111,21 @@
         #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 @@
         self.path = path
 
     def loadTheme(self, theme):
+        log.debug(u'LoadTheme %s ', theme)
         if theme == None:
             self.theme.parse(self.baseTheme())
         else:
@@ -207,27 +217,24 @@
         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'
-                self.theme.font_footer_y = u'730'
-                self.theme.font_footer_width = u'1024'
-                self.theme.font_footer_height = u'38'
-
-                self.FontFooterXSpinBox.setValue(int(self.theme.font_footer_x))
-                self.FontFooterYSpinBox.setValue(int(self.theme.font_footer_y))
-                self.FontFooterWidthSpinBox.setValue(int(self.theme.font_footer_width))
-                self.FontFooterHeightSpinBox.setValue(int(self.theme.font_footer_height))
-
+
+        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'
+            self.theme.font_footer_y = u'730'
+            self.theme.font_footer_width = u'1024'
+            self.theme.font_footer_height = u'38'
+
+            self.FontFooterXSpinBox.setValue(int(self.theme.font_footer_x))
+            self.FontFooterYSpinBox.setValue(int(self.theme.font_footer_y))
+            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 @@
     #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':

=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py	2009-04-28 19:20:03 +0000
+++ openlp/core/ui/servicemanager.py	2009-04-30 21:02:28 +0000
@@ -143,7 +143,7 @@
             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 @@
         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()
 

=== modified file 'openlp/core/ui/slidecontroller.py'
--- openlp/core/ui/slidecontroller.py	2009-04-25 06:11:15 +0000
+++ openlp/core/ui/slidecontroller.py	2009-04-30 21:02:28 +0000
@@ -33,31 +33,35 @@
         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)

=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py	2009-04-28 19:20:03 +0000
+++ openlp/core/ui/thememanager.py	2009-04-29 19:07:13 +0000
@@ -219,7 +219,6 @@
 
     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 @@
         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 @@
         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
 

=== modified file 'openlp/plugins/bibles/lib/mediaitem.py'
--- openlp/plugins/bibles/lib/mediaitem.py	2009-04-25 06:11:15 +0000
+++ openlp/plugins/bibles/lib/mediaitem.py	2009-04-29 19:07:13 +0000
@@ -355,6 +355,7 @@
             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)
 

=== modified file 'openlp/plugins/custom/forms/editcustomform.py'
--- openlp/plugins/custom/forms/editcustomform.py	2009-04-07 19:03:36 +0000
+++ openlp/plugins/custom/forms/editcustomform.py	2009-05-01 05:02:53 +0000
@@ -80,7 +80,7 @@
         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 @@
             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

=== modified file 'openlp/plugins/custom/lib/mediaitem.py'
--- openlp/plugins/custom/lib/mediaitem.py	2009-04-25 06:11:15 +0000
+++ openlp/plugins/custom/lib/mediaitem.py	2009-04-30 21:02:28 +0000
@@ -189,21 +189,29 @@
         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)
-        self.parent.preview_controller.previewFrame(frame)
+        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):
         pass


Follow ups