← Back to team overview

openlp-core team mailing list archive

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

 

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

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

Revamped the rendering to do it when required.
No caching so memory usable will be reduced.
Handles different themes on preview and live at same time.

-- 
https://code.launchpad.net/~trb143/openlp/bugfixes/+merge/11821
Your team openlp.org Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/lib/renderer.py'
--- openlp/core/lib/renderer.py	2009-09-13 07:39:48 +0000
+++ openlp/core/lib/renderer.py	2009-09-15 19:06:40 +0000
@@ -51,9 +51,9 @@
         self._theme = None
         self._bg_image_filename = None
         self._frame = None
-        self._bg_frame = None
+        self.bg_frame = None
         self.bg_image = None
-        self._bg_frame_small = None
+        #self.bg_frame_small = None
 
     def set_debug(self, debug):
         """
@@ -73,7 +73,7 @@
         """
         log.debug(u'set theme')
         self._theme = theme
-        self._bg_frame = None
+        self.bg_frame = None
         self.bg_image = None
         self.theme_name = theme.theme_name
         self._set_theme_font()
@@ -131,14 +131,14 @@
             Defaults to *False*. Whether or not to generate a preview.
         """
         if preview == True:
-            self._bg_frame = None
+            self.bg_frame = None
         log.debug(u'set frame dest (frame) w %d h %d', frame_width,
             frame_height)
         self._frame = QtGui.QImage(frame_width, frame_height,
             QtGui.QImage.Format_ARGB32_Premultiplied)
         if self._bg_image_filename is not None and self.bg_image is None:
             self.scale_bg_image()
-        if self._bg_frame is None:
+        if self.bg_frame is None:
             self._generate_background_frame()
 
     def format_slide(self, words, footer):
@@ -257,7 +257,7 @@
         if footer_lines is not None:
             bbox1 = self._render_lines_unaligned(footer_lines, True)
         # reset the frame. first time do not worry about what you paint on.
-        self._frame = QtGui.QImage(self._bg_frame)
+        self._frame = QtGui.QImage(self.bg_frame)
         x, y = self._correctAlignment(self._rect, bbox)
         bbox = self._render_lines_unaligned(lines, False,  (x, y), True)
         if footer_lines is not None:
@@ -272,11 +272,11 @@
         Results are cached for performance reasons.
         """
         assert(self._theme)
-        self._bg_frame = QtGui.QImage(self._frame.width(), self._frame.height(),
+        self.bg_frame = QtGui.QImage(self._frame.width(), self._frame.height(),
             QtGui.QImage.Format_ARGB32_Premultiplied)
         log.debug(u'render background %s start', self._theme.background_type)
         painter = QtGui.QPainter()
-        painter.begin(self._bg_frame)
+        painter.begin(self.bg_frame)
         if self._theme.background_mode == u'transparent':
             painter.fillRect(self._frame.rect(), QtCore.Qt.transparent)
         else:
@@ -321,8 +321,8 @@
                 if self.bg_image is not None:
                     painter.drawImage(0, 0, self.bg_image)
         painter.end()
-        self._bg_frame_small = self._bg_frame.scaled(QtCore.QSize(280, 210),
-            QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
+#        self.bg_frame_small = self.bg_frame.scaled(QtCore.QSize(280, 210),
+#            QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
         log.debug(u'render background End')
 
     def _correctAlignment(self, rect, bbox):

=== modified file 'openlp/core/lib/serviceitem.py'
--- openlp/core/lib/serviceitem.py	2009-09-13 07:39:48 +0000
+++ openlp/core/lib/serviceitem.py	2009-09-15 19:06:40 +0000
@@ -61,14 +61,11 @@
         self.items = []
         self.iconic_representation = None
         self.raw_slides = None
-        self.frame_titles = []
-        self.command_files = []
         self.frames = []
         self.raw_footer = None
         self.theme = None
         self.service_item_path = None
         self.service_item_type = None
-        #log.debug(u'Service item created for %s ', self.shortname)
         self.service_frames = []
 
     def addIcon(self, icon):
@@ -95,12 +92,19 @@
                 self.RenderManager.set_override_theme(None)
             else:
                 self.RenderManager.set_override_theme(self.theme)
+            firstTime = True
             for slide in self.service_frames:
                 formated = self.RenderManager.format_slide(slide[u'raw_slide'])
                 for format in formated:
-                    frame = self.RenderManager.generate_slide(format,
-                        self.raw_footer)
-                    self.frames.append({u'title': slide[u'title'],
+                    frame = None
+                    if firstTime:
+                        frame = self.RenderManager.generate_slide(format,
+                            self.raw_footer)
+                        firstTime = False
+                    lines = u''
+                    for line in format:
+                        lines += line + u'\n'
+                    self.frames.append({u'title': slide[u'title'],u'text':lines,
                         u'image': frame})
         elif self.service_item_type == ServiceType.Command:
             self.frames = self.service_frames
@@ -112,6 +116,17 @@
         else:
             log.error(u'Invalid value renderer :%s' % self.service_item_type)
 
+    def render_individual(self, row):
+        log.debug(u'render individual')
+        if self.theme == None:
+            self.RenderManager.set_override_theme(None)
+        else:
+            self.RenderManager.set_override_theme(self.theme)
+        format = self.frames[row][u'text'].split(u'\n')
+        frame = self.RenderManager.generate_slide(format,
+                        self.raw_footer)
+        return frame
+
     def add_from_image(self, path, frame_title, image):
         """
         Add an image slide to the service item.
@@ -127,7 +142,7 @@
         """
         self.service_item_type = ServiceType.Image
         self.service_item_path = path
-        self.service_frames.append({u'title': frame_title, u'image': image})
+        self.service_frames.append({u'title': frame_title, u'text':None, u'image': image})
 
     def add_from_text(self, frame_title, raw_slide):
         """

=== modified file 'openlp/core/ui/slidecontroller.py'
--- openlp/core/ui/slidecontroller.py	2009-09-14 19:36:50 +0000
+++ openlp/core/ui/slidecontroller.py	2009-09-15 19:06:40 +0000
@@ -166,7 +166,7 @@
         self.Toolbar.setSizePolicy(sizeToolbarPolicy)
         # Screen preview area
         self.PreviewFrame = QtGui.QFrame(self.Splitter)
-        self.PreviewFrame.setGeometry(QtCore.QRect(0, 0, self.settingsmanager.slidecontroller_image, 225))
+        self.PreviewFrame.setGeometry(QtCore.QRect(0, 0, 300, 225))
         self.PreviewFrame.setSizePolicy(QtGui.QSizePolicy(
             QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum))
         self.PreviewFrame.setFrameShape(QtGui.QFrame.StyledPanel)
@@ -293,12 +293,15 @@
         self.PreviewListWidget.setColumnWidth(0, slide_width)
         for framenumber, frame in enumerate(self.serviceitem.frames):
             self.PreviewListWidget.setRowCount(self.PreviewListWidget.rowCount() + 1)
-            pixmap = self.parent.RenderManager.resize_image(frame[u'image'], slide_width, slide_height)
             item = QtGui.QTableWidgetItem()
             label = QtGui.QLabel()
             label.setMargin(8)
-            label.setScaledContents(True)
-            label.setPixmap(QtGui.QPixmap.fromImage(pixmap))
+            if frame[u'text'] == None:
+                pixmap = self.parent.RenderManager.resize_image(frame[u'image'], slide_width, slide_height)
+                label.setScaledContents(True)
+                label.setPixmap(QtGui.QPixmap.fromImage(pixmap))
+            else:
+                label.setText(frame[u'text'])
             self.PreviewListWidget.setCellWidget(framenumber, 0, label)
             self.PreviewListWidget.setItem(framenumber, 0, item)
             self.PreviewListWidget.setRowHeight(framenumber, slide_height)
@@ -335,9 +338,12 @@
         row = self.PreviewListWidget.currentRow()
         if row > -1 and row < self.PreviewListWidget.rowCount():
             label = self.PreviewListWidget.cellWidget(row, 0)
-            smallframe = label.pixmap()
             frame = self.serviceitem.frames[row][u'image']
-            self.SlidePreview.setPixmap(smallframe)
+            before = time.time()
+            if frame == None:
+                frame = self.serviceitem.render_individual(row)
+            self.SlidePreview.setPixmap(QtGui.QPixmap.fromImage(frame))
+            log.info(u'Slide Rendering took %4s' % (time.time() - before))
             if self.isLive:
                 self.parent.mainDisplay.frameView(frame)
 
@@ -390,7 +396,7 @@
     def timerEvent(self, event):
         if event.timerId() == self.timer_id:
             self.onSlideSelectedNext()
-    
+
     def onGoLive(self):
         row = self.PreviewListWidget.currentRow()
         if row > -1 and row < self.PreviewListWidget.rowCount():


Follow ups