← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol/openlp/image-queue into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol/openlp/image-queue into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~googol/openlp/image-queue/+merge/110793

NOT TO BE REVIEWED PRIOR TO THE 1.9.10 RELEASE!

Hello

- update the image cache when the image timestamp changes

1) Display/preview an image.
2) Edit the image.
3) Send it live/preview again.

Result:
Cache is not updated.

Expected:
Cache is updated. You especially expect this when you delete and add the image again.
-- 
https://code.launchpad.net/~googol/openlp/image-queue/+merge/110793
Your team OpenLP Core is requested to review the proposed merge of lp:~googol/openlp/image-queue into lp:openlp.
=== modified file 'openlp/core/lib/__init__.py'
--- openlp/core/lib/__init__.py	2012-04-22 19:50:18 +0000
+++ openlp/core/lib/__init__.py	2012-06-18 12:09:20 +0000
@@ -264,6 +264,7 @@
     if image_ratio == resize_ratio:
         # We neither need to centre the image nor add "bars" to the image.
         return preview
+    #FIXME: change variables to real_width and real_height
     realw = preview.width()
     realh = preview.height()
     # and move it to the centre of the preview space

=== modified file 'openlp/core/lib/imagemanager.py'
--- openlp/core/lib/imagemanager.py	2012-06-04 10:22:47 +0000
+++ openlp/core/lib/imagemanager.py	2012-06-18 12:09:20 +0000
@@ -31,6 +31,7 @@
 to wait for the conversion to happen.
 """
 import logging
+import os
 import time
 import Queue
 
@@ -96,19 +97,39 @@
 
 class Image(object):
     """
-    This class represents an image. To mark an image as *dirty* set the instance
-    variables ``image`` and ``image_bytes`` to ``None`` and add the image object
-    to the queue of images to process.
+    This class represents an image. To mark an image as *dirty* call the
+    :class:`ImageManager`'s ``_resetImage`` method with the Image instance as
+    argument.
     """
     secondary_priority = 0
+    
     def __init__(self, name, path, source, background):
+        """
+        Create an image for the :class:`ImageManager`'s cache.
+        
+        ``name``
+            The image name. This does not have to be part of the ``path``. It
+            can be of any value. It can be considered an ID.
+            
+        ``path``
+            The image's file path. This should be an existing file path.
+            
+        ``source``
+            The source describes the image's origin. Possible values are
+            ``image`` and ``theme``.
+            
+        ``background``
+            A ``QtGui.QColor`` object specifying the colour to be used to fill
+            the gabs if the image's ratio does not match with the display ratio.
+        """
         self.name = name
         self.path = path
         self.image = None
         self.image_bytes = None
-        self.priority = Priority.Normal
         self.source = source
         self.background = background
+        self.timestamp = os.stat(path).st_mtime
+        self.priority = Priority.Normal
         self.secondary_priority = Image.secondary_priority
         Image.secondary_priority += 1
 
@@ -117,7 +138,7 @@
     """
     Customised ``Queue.PriorityQueue``.
 
-    Each item in the queue must be tuple with three values. The first value
+    Each item in the queue must be a tuple with three values. The first value
     is the :class:`Image`'s ``priority`` attribute, the second value
     the :class:`Image`'s ``secondary_priority`` attribute. The last value the
     :class:`Image` instance itself::
@@ -186,7 +207,7 @@
         for image in self._cache.values():
             self._resetImage(image)
 
-    def updateImages(self, imageType, background):
+    def updateImagesBorder(self, source, background):
         """
         Border has changed so update all the images affected.
         """
@@ -194,23 +215,27 @@
         # Mark the images as dirty for a rebuild by setting the image and byte
         # stream to None.
         for image in self._cache.values():
-            if image.source == imageType:
+            if image.source == source:
                 image.background = background
                 self._resetImage(image)
 
-    def updateImage(self, name, imageType, background):
+    def updateImageBorder(self, name, source, background):
         """
         Border has changed so update the image affected.
         """
         log.debug(u'updateImage')
-        # Mark the images as dirty for a rebuild by setting the image and byte
+        # Mark the image as dirty for a rebuild by setting the image and byte
         # stream to None.
-        for image in self._cache.values():
-            if image.source == imageType and image.name == name:
-                image.background = background
-                self._resetImage(image)
+        image = self._cache[name]
+        if image.source == source:
+            image.background = background
+            self._resetImage(image)
 
     def _resetImage(self, image):
+        """
+        Mark the given :class:`Image` instance as dirt by setting its ``image``
+        and ``image_bytes`` attributes to None.
+        """
         image.image = None
         image.image_bytes = None
         self._conversionQueue.modify_priority(image, Priority.Normal)
@@ -281,6 +306,12 @@
             self._conversionQueue.put(
                 (image.priority, image.secondary_priority, image))
         else:
+            image = self._cache[name]
+            if os.path.isfile(path) and \
+                image.timestamp != os.stat(path).st_mtime:
+                image.path = path
+                image.timestamp = os.stat(path).st_mtime
+                self._resetImage(image)
             log.debug(u'Image in cache %s:%s' % (name, path))
         # We want only one thread.
         if not self.imageThread.isRunning():

=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py	2012-06-15 16:19:46 +0000
+++ openlp/core/ui/thememanager.py	2012-06-18 12:09:20 +0000
@@ -668,7 +668,7 @@
         self._writeTheme(theme, image_from, image_to)
         if theme.background_type == \
             BackgroundType.to_string(BackgroundType.Image):
-            self.mainwindow.imageManager.updateImage(theme.theme_name,
+            self.mainwindow.imageManager.updateImageBorder(theme.theme_name,
                 u'theme', QtGui.QColor(theme.background_border_color))
             self.mainwindow.imageManager.processUpdates()
         self.loadThemes()

=== modified file 'openlp/plugins/images/imageplugin.py'
--- openlp/plugins/images/imageplugin.py	2012-06-09 04:23:24 +0000
+++ openlp/plugins/images/imageplugin.py	2012-06-18 12:09:20 +0000
@@ -97,4 +97,5 @@
         """
         background = QtGui.QColor(Settings().value(self.settingsSection
             + u'/background color', QtCore.QVariant(u'#000000')))
-        self.liveController.imageManager.updateImages(u'image', background)
+        self.liveController.imageManager.updateImagesBorder(
+            u'image', background)


Follow ups