docs and class variable fix

This commit is contained in:
Andreas Preikschat 2012-05-05 20:34:26 +02:00
parent 7f7ac0c54e
commit 8b08fbbe32
1 changed files with 13 additions and 11 deletions

View File

@ -100,7 +100,7 @@ class Image(object):
variables ``image`` and ``image_bytes`` to ``None`` and add the image object
to the queue of images to process.
"""
NUMBER = 0
secondary_priority = 0
def __init__(self, name, path, source, background):
self.name = name
self.path = path
@ -109,19 +109,20 @@ class Image(object):
self.priority = Priority.Normal
self.source = source
self.background = background
self._number = Image.NUMBER
Image.NUMBER += 1
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 fist value
is the priority, the second value the image's ``_number`` attribute. The
last value the :class:`Image` instance itself::
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::
(Priority.Normal, image._number, image)
(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
@ -141,7 +142,7 @@ class PriorityQueue(Queue.PriorityQueue):
"""
self.remove(image)
image.priority = new_priority
self.put((image.priority, image._number, image))
self.put((image.priority, image.secondary_priority, image))
def remove(self, image):
"""
@ -150,8 +151,8 @@ class PriorityQueue(Queue.PriorityQueue):
``image``
The image to remove. This should be an ``Image`` instance.
"""
if (image.priority, image._number, image) in self.queue:
self.queue.remove((image.priority, image._number, image))
if (image.priority, image.secondary_priority, image) in self.queue:
self.queue.remove((image.priority, image.secondary_priority, image))
class ImageManager(QtCore.QObject):
@ -276,7 +277,8 @@ class ImageManager(QtCore.QObject):
if not name in self._cache:
image = Image(name, path, source, background)
self._cache[name] = image
self._conversion_queue.put((image.priority, image._number, 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.