added new priority and fixed comments

This commit is contained in:
Andreas Preikschat 2011-06-25 07:34:07 +02:00
parent 356ea8fff8
commit 1730f5a99f
1 changed files with 34 additions and 9 deletions

View File

@ -43,8 +43,8 @@ log = logging.getLogger(__name__)
class ImageThread(QtCore.QThread): class ImageThread(QtCore.QThread):
""" """
A special Qt thread class to speed up the display of text based frames. A special Qt thread class to speed up the display of images. This is
This is threaded so it loads the frames in background threaded so it loads the frames and generates byte stream in background.
""" """
def __init__(self, manager): def __init__(self, manager):
QtCore.QThread.__init__(self, None) QtCore.QThread.__init__(self, None)
@ -61,22 +61,33 @@ class Priority(object):
""" """
Enumeration class for different priorities. Enumeration class for different priorities.
``Lowest``
Only the image's byte stream has to be generated. But neither the
``QImage`` nor the byte stream has been requested yet.
``Low`` ``Low``
Only the image's byte stream has to be generated. Neither the QImage nor Only the image's byte stream has to be generated. Because the image's
the byte stream has been requested yet. ``QImage`` has been requested previously it is reasonable to assume that
the byte stream will be needed before the byte stream of other images
which ``QImage`` were not generated due to a request.
``Normal`` ``Normal``
The image's byte stream as well as the image has to be generated. The image's byte stream as well as the image has to be generated.
Neither the QImage nor the byte stream has been requested yet. Neither the ``QImage`` nor the byte stream has been requested yet.
``High`` ``High``
The image's byte stream as well as the image has to be generated. The The image's byte stream as well as the image has to be generated. The
QImage for this image has been requested. ``QImage`` for this image has been requested.
**Note**, this priority is only set when the ``QImage`` has not been
generated yet.
``Urgent`` ``Urgent``
The image's byte stream as well as the image has to be generated. The The image's byte stream as well as the image has to be generated. The
byte stream for this image has been requested. byte stream for this image has been requested.
**Note**, this priority is only set when the byte stream has not been
generated yet.
""" """
Lowest = 4
Low = 3 Low = 3
Normal = 2 Normal = 2
High = 1 High = 1
@ -84,6 +95,11 @@ class Priority(object):
class Image(object): 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.
"""
def __init__(self, name='', path=''): def __init__(self, name='', path=''):
self.name = name self.name = name
self.path = path self.path = path
@ -217,9 +233,18 @@ class ImageManager(QtCore.QObject):
# Generate the QImage for the image. # Generate the QImage for the image.
if image.image is None: if image.image is None:
image.image = resize_image(image.path, self.width, self.height) image.image = resize_image(image.path, self.width, self.height)
# If the priority is not urgent, then set the priority to low and # Set the priority to Lowest and stop here as we need to process
# do not start to generate the byte stream. # more important images first.
if image.priority != Priority.Urgent: if image.priority == Priority.Normal:
self._clean_queue.remove((image.priority, image))
image.priority = Priority.Lowest
self._clean_queue.put((image.priority, image))
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._clean_queue.remove((image.priority, image)) self._clean_queue.remove((image.priority, image))
image.priority = Priority.Low image.priority = Priority.Low
self._clean_queue.put((image.priority, image)) self._clean_queue.put((image.priority, image))