← 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:
  Tim Bentley (trb143)
  Raoul Snyman (raoul-snyman)

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

Hello,

I have added a secondary criterion for the image queue to privilege images which were added later over images which were added earlier when both have the same priority.

NOTE: Do not be confused by the commit message. I mixed things up :-( (And if you do not know what I am talking about, then don't waste any further second...)
-- 
https://code.launchpad.net/~googol/openlp/image-queue/+merge/104849
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/lib/imagemanager.py'
--- openlp/core/lib/imagemanager.py	2012-03-12 22:12:16 +0000
+++ openlp/core/lib/imagemanager.py	2012-05-05 18:36:21 +0000
@@ -100,6 +100,7 @@
     variables ``image`` and ``image_bytes`` to ``None`` and add the image object
     to the queue of images to process.
     """
+    secondary_priority = 0
     def __init__(self, name, path, source, background):
         self.name = name
         self.path = path
@@ -108,25 +109,40 @@
         self.priority = Priority.Normal
         self.source = source
         self.background = background
+        self.secondary_priority = Image.secondary_priority
+        Image.secondary_priority += 1
 
 
 class PriorityQueue(Queue.PriorityQueue):
     """
     Customised ``Queue.PriorityQueue``.
+
+    Each item in the queue must be 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::
+
+        (image.priority, image.secondary_priority, image)
+
+    Doing this, the :class:`Queue.PriorityQueue` will sort the images according
+    to their priorities, but also according to there number. However, the number
+    only has an impact on the result if there are more images with the same
+    priority. In such case the image which has been added earlier is privileged.
     """
     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.
+            The image to remove. This should be an :class:`Image` instance.
 
         ``new_priority``
-            The image's new priority.
+            The image's new priority. See the :class:`Priority` class for
+            priorities.
         """
         self.remove(image)
         image.priority = new_priority
-        self.put((image.priority, image))
+        self.put((image.priority, image.secondary_priority, image))
 
     def remove(self, image):
         """
@@ -135,8 +151,8 @@
         ``image``
             The image to remove. This should be an ``Image`` instance.
         """
-        if (image.priority, image) in self.queue:
-            self.queue.remove((image.priority, image))
+        if (image.priority, image.secondary_priority, image) in self.queue:
+            self.queue.remove((image.priority, image.secondary_priority, image))
 
 
 class ImageManager(QtCore.QObject):
@@ -261,7 +277,8 @@
         if not name in self._cache:
             image = Image(name, path, source, background)
             self._cache[name] = image
-            self._conversion_queue.put((image.priority, image))
+            self._conversion_queue.put(
+                (image.priority, image.secondary_priority, image))
         else:
             log.debug(u'Image in cache %s:%s' % (name, path))
         # We want only one thread.
@@ -282,7 +299,7 @@
         Actually does the work.
         """
         log.debug(u'_process_cache')
-        image = self._conversion_queue.get()[1]
+        image = self._conversion_queue.get()[2]
         # Generate the QImage for the image.
         if image.image is None:
             image.image = resize_image(image.path, self.width, self.height,


Follow ups