docs and class variable fix

This commit is contained in:
Andreas Preikschat 2012-05-05 20:34:26 +02:00
parent 7f7ac0c54e
commit 8b08fbbe32

View File

@ -100,7 +100,7 @@ class Image(object):
variables ``image`` and ``image_bytes`` to ``None`` and add the image object variables ``image`` and ``image_bytes`` to ``None`` and add the image object
to the queue of images to process. to the queue of images to process.
""" """
NUMBER = 0 secondary_priority = 0
def __init__(self, name, path, source, background): def __init__(self, name, path, source, background):
self.name = name self.name = name
self.path = path self.path = path
@ -109,19 +109,20 @@ class Image(object):
self.priority = Priority.Normal self.priority = Priority.Normal
self.source = source self.source = source
self.background = background self.background = background
self._number = Image.NUMBER self.secondary_priority = Image.secondary_priority
Image.NUMBER += 1 Image.secondary_priority += 1
class PriorityQueue(Queue.PriorityQueue): class PriorityQueue(Queue.PriorityQueue):
""" """
Customised ``Queue.PriorityQueue``. Customised ``Queue.PriorityQueue``.
Each item in the queue must be tuple with three values. The fist value Each item in the queue must be tuple with three values. The first value
is the priority, the second value the image's ``_number`` attribute. The is the :class:`Image`'s ``priority`` attribute, the second value
last value the :class:`Image` instance itself:: 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 Doing this, the :class:`Queue.PriorityQueue` will sort the images according
to their priorities, but also according to there number. However, the number to their priorities, but also according to there number. However, the number
@ -141,7 +142,7 @@ class PriorityQueue(Queue.PriorityQueue):
""" """
self.remove(image) self.remove(image)
image.priority = new_priority image.priority = new_priority
self.put((image.priority, image._number, image)) self.put((image.priority, image.secondary_priority, image))
def remove(self, image): def remove(self, image):
""" """
@ -150,8 +151,8 @@ class PriorityQueue(Queue.PriorityQueue):
``image`` ``image``
The image to remove. This should be an ``Image`` instance. The image to remove. This should be an ``Image`` instance.
""" """
if (image.priority, image._number, image) in self.queue: if (image.priority, image.secondary_priority, image) in self.queue:
self.queue.remove((image.priority, image._number, image)) self.queue.remove((image.priority, image.secondary_priority, image))
class ImageManager(QtCore.QObject): class ImageManager(QtCore.QObject):
@ -276,7 +277,8 @@ class ImageManager(QtCore.QObject):
if not name in self._cache: if not name in self._cache:
image = Image(name, path, source, background) image = Image(name, path, source, background)
self._cache[name] = image self._cache[name] = image
self._conversion_queue.put((image.priority, image._number, image)) self._conversion_queue.put(
(image.priority, image.secondary_priority, image))
else: else:
log.debug(u'Image in cache %s:%s' % (name, path)) log.debug(u'Image in cache %s:%s' % (name, path))
# We want only one thread. # We want only one thread.