← 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/67221

Hello,

- small image queue fix
When the QImage was created before it was requested the priority was set to Lowest, but it should be Low

- refactoring
-- 
https://code.launchpad.net/~googol/openlp/image-queue/+merge/67221
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/imagemanager.py'
--- openlp/core/lib/imagemanager.py	2011-06-27 11:28:58 +0000
+++ openlp/core/lib/imagemanager.py	2011-07-07 16:31:21 +0000
@@ -112,17 +112,29 @@
     """
     Customised ``Queue.PriorityQueue``.
     """
-    def remove(self, item):
-        """
-        Removes the given ``item`` from the queue.
-
-        ``item``
-            The item to remove. This should be a tuple::
-
-                ``(Priority, Image)``
-        """
-        if item in self.queue:
-            self.queue.remove(item)
+    def modify_priority(self, image, new_priority):
+        """
+        Modifies the priority of the given ``image``.
+
+        ``image``
+            The image to remove. This should be an ``Image`` instance.
+
+        ``new_priority``
+            The image's new priority.
+        """
+        self.remove(image)
+        image.priority = new_priority
+        self.put((image.priority, image))
+
+    def remove(self, image):
+        """
+        Removes the given ``image`` from the queue.
+
+        ``image``
+            The image to remove. This should be an ``Image`` instance.
+        """
+        if (image.priority, image) in self.queue:
+            self.queue.remove((image.priority, image))
 
 
 class ImageManager(QtCore.QObject):
@@ -168,12 +180,16 @@
         log.debug(u'get_image %s' % name)
         image = self._cache[name]
         if image.image is None:
-            self._conversion_queue.remove((image.priority, image))
-            image.priority = Priority.High
-            self._conversion_queue.put((image.priority, image))
+            self._conversion_queue.modify_priority(image, Priority.High)
             while image.image is None:
                 log.debug(u'get_image - waiting')
                 time.sleep(0.1)
+        elif image.image_bytes is None:
+            # Set the priority to Low, because the image was requested but the
+            # byte stream was not generated yet. However, we only need to do
+            # this, when the image was generated before it was requested
+            # (otherwise this is already taken care of).
+            self._conversion_queue.modify_priority(image, Priority.Low)
         return image.image
 
     def get_image_bytes(self, name):
@@ -184,9 +200,7 @@
         log.debug(u'get_image_bytes %s' % name)
         image = self._cache[name]
         if image.image_bytes is None:
-            self._conversion_queue.remove((image.priority, image))
-            image.priority = Priority.Urgent
-            self._conversion_queue.put((image.priority, image))
+            self._conversion_queue.modify_priority(image, Priority.Urgent)
             while image.image_bytes is None:
                 log.debug(u'get_image_bytes - waiting')
                 time.sleep(0.1)
@@ -198,8 +212,7 @@
         """
         log.debug(u'del_image %s' % name)
         if name in self._cache:
-            self._conversion_queue.remove(
-                (self._cache[name].priority, self._cache[name]))
+            self._conversion_queue.remove(self._cache[name])
             del self._cache[name]
 
     def add_image(self, name, path):
@@ -238,18 +251,14 @@
             # Set the priority to Lowest and stop here as we need to process
             # more important images first.
             if image.priority == Priority.Normal:
-                self._conversion_queue.remove((image.priority, image))
-                image.priority = Priority.Lowest
-                self._conversion_queue.put((image.priority, image))
+                self._conversion_queue.modify_priority(image, Priority.Lowest)
                 return
             # For image with high priority we set the priority to Low, as the
             # byte stream might be needed earlier the byte stream of image with
             # Normal priority. We stop here as we need to process more important
             # images first.
             elif image.priority == Priority.High:
-                self._conversion_queue.remove((image.priority, image))
-                image.priority = Priority.Low
-                self._conversion_queue.put((image.priority, image))
+                self._conversion_queue.modify_priority(image, Priority.Low)
                 return
         # Generate the byte stream for the image.
         if image.image_bytes is None:


Follow ups