From f2884f05936648b785bdf5a13d905572e68ab1bf Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 18 Jun 2012 14:07:26 +0200 Subject: [PATCH 1/6] update image in cache when timestamp changed; docs --- openlp/core/lib/__init__.py | 1 + openlp/core/lib/imagemanager.py | 57 +++++++++++++++++++++------- openlp/core/ui/thememanager.py | 2 +- openlp/plugins/images/imageplugin.py | 3 +- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 9af8debb8..24786ff55 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -264,6 +264,7 @@ def resize_image(image_path, width, height, background=u'#000000'): if image_ratio == resize_ratio: # We neither need to centre the image nor add "bars" to the image. return preview + #FIXME: change variables to real_width and real_height realw = preview.width() realh = preview.height() # and move it to the centre of the preview space diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index 1e2a3a698..1922cef34 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -31,6 +31,7 @@ A Thread is used to convert the image to a byte array so the user does not need to wait for the conversion to happen. """ import logging +import os import time import Queue @@ -96,19 +97,39 @@ class Priority(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. + This class represents an image. To mark an image as *dirty* call the + :class:`ImageManager`'s ``_resetImage`` method with the Image instance as + argument. """ secondary_priority = 0 + def __init__(self, name, path, source, background): + """ + Create an image for the :class:`ImageManager`'s cache. + + ``name`` + The image name. This does not have to be part of the ``path``. It + can be of any value. It can be considered an ID. + + ``path`` + The image's file path. This should be an existing file path. + + ``source`` + The source describes the image's origin. Possible values are + ``image`` and ``theme``. + + ``background`` + A ``QtGui.QColor`` object specifying the colour to be used to fill + the gabs if the image's ratio does not match with the display ratio. + """ self.name = name self.path = path self.image = None self.image_bytes = None - self.priority = Priority.Normal self.source = source self.background = background + self.timestamp = os.stat(path).st_mtime + self.priority = Priority.Normal self.secondary_priority = Image.secondary_priority Image.secondary_priority += 1 @@ -117,7 +138,7 @@ class PriorityQueue(Queue.PriorityQueue): """ Customised ``Queue.PriorityQueue``. - Each item in the queue must be tuple with three values. The first value + Each item in the queue must be a 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:: @@ -186,7 +207,7 @@ class ImageManager(QtCore.QObject): for image in self._cache.values(): self._resetImage(image) - def updateImages(self, imageType, background): + def updateImagesBorder(self, source, background): """ Border has changed so update all the images affected. """ @@ -194,23 +215,27 @@ class ImageManager(QtCore.QObject): # Mark the images as dirty for a rebuild by setting the image and byte # stream to None. for image in self._cache.values(): - if image.source == imageType: + if image.source == source: image.background = background self._resetImage(image) - def updateImage(self, name, imageType, background): + def updateImageBorder(self, name, source, background): """ Border has changed so update the image affected. """ log.debug(u'updateImage') - # Mark the images as dirty for a rebuild by setting the image and byte + # Mark the image as dirty for a rebuild by setting the image and byte # stream to None. - for image in self._cache.values(): - if image.source == imageType and image.name == name: - image.background = background - self._resetImage(image) + image = self._cache[name] + if image.source == source: + image.background = background + self._resetImage(image) def _resetImage(self, image): + """ + Mark the given :class:`Image` instance as dirt by setting its ``image`` + and ``image_bytes`` attributes to None. + """ image.image = None image.image_bytes = None self._conversionQueue.modify_priority(image, Priority.Normal) @@ -281,6 +306,12 @@ class ImageManager(QtCore.QObject): self._conversionQueue.put( (image.priority, image.secondary_priority, image)) else: + image = self._cache[name] + if os.path.isfile(path) and \ + image.timestamp != os.stat(path).st_mtime: + image.path = path + image.timestamp = os.stat(path).st_mtime + self._resetImage(image) log.debug(u'Image in cache %s:%s' % (name, path)) # We want only one thread. if not self.imageThread.isRunning(): diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 7ca56ce08..497b50d33 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -668,7 +668,7 @@ class ThemeManager(QtGui.QWidget): self._writeTheme(theme, image_from, image_to) if theme.background_type == \ BackgroundType.to_string(BackgroundType.Image): - self.mainwindow.imageManager.updateImage(theme.theme_name, + self.mainwindow.imageManager.updateImageBorder(theme.theme_name, u'theme', QtGui.QColor(theme.background_border_color)) self.mainwindow.imageManager.processUpdates() self.loadThemes() diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index e148f5625..95fc8c68a 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -97,4 +97,5 @@ class ImagePlugin(Plugin): """ background = QtGui.QColor(Settings().value(self.settingsSection + u'/background color', QtCore.QVariant(u'#000000'))) - self.liveController.imageManager.updateImages(u'image', background) + self.liveController.imageManager.updateImagesBorder( + u'image', background) From d1f11138511c7807354c92ee9af530669ff26d8d Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 18 Jun 2012 14:27:04 +0200 Subject: [PATCH 2/6] use the update mechanism to reset images instead of deleting them (leading to a time advantage when the image did not change) --- openlp/core/lib/imagemanager.py | 9 --------- openlp/core/lib/renderer.py | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index 1922cef34..fe1cd00f6 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -286,15 +286,6 @@ class ImageManager(QtCore.QObject): time.sleep(0.1) return image.image_bytes - def deleteImage(self, name): - """ - Delete the Image from the cache. - """ - log.debug(u'deleteImage %s' % name) - if name in self._cache: - self._conversionQueue.remove(self._cache[name]) - del self._cache[name] - def addImage(self, name, path, source, background): """ Add image to cache if it is not already there. diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index e35c78559..8fe2eed9b 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -134,6 +134,7 @@ class Renderer(object): else: theme_data, main_rect, footer_rect = \ self._theme_dimensions[theme_name] + #FIXME: REMOVE deleteImage() call which will be added soon. # if No file do not update cache if theme_data.background_filename: self.image_manager.addImage(theme_data.theme_name, @@ -236,7 +237,6 @@ class Renderer(object): # make big page for theme edit dialog to get line count serviceItem.add_from_text(VERSE_FOR_LINE_COUNT) else: - self.image_manager.deleteImage(theme_data.theme_name) serviceItem.add_from_text(VERSE) serviceItem.renderer = self serviceItem.raw_footer = FOOTER From 9da23266c6d39d0eb4dfcd42902be8b24f705908 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 30 Jun 2012 17:19:33 +0200 Subject: [PATCH 3/6] reworked image manager _cache to contain unique images (to be cleaned up) --- openlp/core/lib/imagemanager.py | 61 ++++++++++--------- openlp/core/lib/renderer.py | 9 ++- openlp/core/lib/serviceitem.py | 8 +-- openlp/core/ui/maindisplay.py | 44 ++++++------- openlp/core/ui/slidecontroller.py | 14 +++-- openlp/core/ui/thememanager.py | 5 +- openlp/plugins/images/imageplugin.py | 2 +- openlp/plugins/images/lib/mediaitem.py | 3 +- .../presentations/lib/messagelistener.py | 3 +- 9 files changed, 77 insertions(+), 72 deletions(-) diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index 9e9a882b2..265f3b3cd 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -96,6 +96,15 @@ class Priority(object): Urgent = 0 +class ImageSource(object): + """ + This enumeration class represents different image sources. An image sources + states where an image is used. + """ + ImagePlugin = 1 + Theme = 2 + + class Image(object): """ This class represents an image. To mark an image as *dirty* call the @@ -103,27 +112,22 @@ class Image(object): argument. """ secondary_priority = 0 - - def __init__(self, name, path, source, background): + + def __init__(self, path, source, background): """ Create an image for the :class:`ImageManager`'s cache. - - ``name`` - The image name. This does not have to be part of the ``path``. It - can be of any value. It can be considered an ID. - + ``path`` The image's file path. This should be an existing file path. - + ``source`` The source describes the image's origin. Possible values are ``image`` and ``theme``. - + ``background`` A ``QtGui.QColor`` object specifying the colour to be used to fill the gabs if the image's ratio does not match with the display ratio. """ - self.name = name self.path = path self.image = None self.image_bytes = None @@ -192,6 +196,7 @@ class ImageManager(QtCore.QObject): self.imageThread = ImageThread(self) self._conversionQueue = PriorityQueue() self.stopManager = False + self.imageSource = ImageSource() QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.processUpdates) @@ -220,14 +225,14 @@ class ImageManager(QtCore.QObject): image.background = background self._resetImage(image) - def updateImageBorder(self, name, source, background): + def updateImageBorder(self, path, source, background): """ Border has changed so update the image affected. """ log.debug(u'updateImage') # Mark the image as dirty for a rebuild by setting the image and byte # stream to None. - image = self._cache[name] + image = self._cache[(path, source)] if image.source == source: image.background = background self._resetImage(image) @@ -249,13 +254,13 @@ class ImageManager(QtCore.QObject): if not self.imageThread.isRunning(): self.imageThread.start() - def getImage(self, name): + def getImage(self, path, source): """ Return the ``QImage`` from the cache. If not present wait for the background thread to process it. """ - log.debug(u'getImage %s' % name) - image = self._cache[name] + log.debug(u'getImage %s' % path) + image = self._cache[(path, source)] if image.image is None: self._conversionQueue.modify_priority(image, Priority.High) # make sure we are running and if not give it a kick @@ -271,13 +276,13 @@ class ImageManager(QtCore.QObject): self._conversionQueue.modify_priority(image, Priority.Low) return image.image - def getImageBytes(self, name): + def getImageBytes(self, path, source): """ Returns the byte string for an image. If not present wait for the background thread to process it. """ - log.debug(u'getImageBytes %s' % name) - image = self._cache[name] + log.debug(u'getImageBytes %s' % path) + image = self._cache[(path, source)] if image.image_bytes is None: self._conversionQueue.modify_priority(image, Priority.Urgent) # make sure we are running and if not give it a kick @@ -287,24 +292,22 @@ class ImageManager(QtCore.QObject): time.sleep(0.1) return image.image_bytes - def addImage(self, name, path, source, background): + def addImage(self, path, source, background): """ Add image to cache if it is not already there. """ - log.debug(u'addImage %s:%s' % (name, path)) - if not name in self._cache: - image = Image(name, path, source, background) - self._cache[name] = image + log.debug(u'addImage %s' % path) + if not (path, source) in self._cache: + image = Image(path, source, background) + self._cache[(path, source)] = image self._conversionQueue.put( (image.priority, image.secondary_priority, image)) - else: - image = self._cache[name] - if os.path.isfile(path) and \ - image.timestamp != os.stat(path).st_mtime: - image.path = path + # Check if the there are any images with the same path and check if the + # timestamp has changed. + for image in self._cache.values(): + if image.path == path and image.timestamp != os.stat(path).st_mtime: image.timestamp = os.stat(path).st_mtime self._resetImage(image) - log.debug(u'Image in cache %s:%s' % (name, path)) # We want only one thread. if not self.imageThread.isRunning(): self.imageThread.start() diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 2646b3904..c7b697fb1 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -135,11 +135,10 @@ class Renderer(object): else: theme_data, main_rect, footer_rect = \ self._theme_dimensions[theme_name] - #FIXME: REMOVE deleteImage() call which will be added soon. # if No file do not update cache if theme_data.background_filename: - self.image_manager.addImage(theme_data.theme_name, - theme_data.background_filename, u'theme', + self.image_manager.addImage(theme_data.background_filename, + self.image_manager.imageSource.Theme, QtGui.QColor(theme_data.background_border_color)) def pre_render(self, override_theme_data=None): @@ -243,8 +242,8 @@ class Renderer(object): serviceItem.raw_footer = FOOTER # if No file do not update cache if theme_data.background_filename: - self.image_manager.addImage(theme_data.theme_name, - theme_data.background_filename, u'theme', + self.image_manager.addImage(theme_data.background_filename, + self.image_manager.imageSource.Theme, QtGui.QColor(theme_data.background_border_color)) theme_data, main, footer = self.pre_render(theme_data) serviceItem.themedata = theme_data diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index c2b775344..d0622a130 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -217,7 +217,8 @@ class ServiceItem(object): self.image_border = background self.service_item_type = ServiceItemType.Image self._raw_frames.append({u'title': title, u'path': path}) - self.renderer.image_manager.addImage(title, path, u'image', + self.renderer.image_manager.addImage(path, + self.renderer.image_manager.imageSource.ImagePlugin, self.image_border) self._new_item() @@ -432,13 +433,12 @@ class ServiceItem(object): def get_rendered_frame(self, row): """ - Returns the correct frame for a given list and - renders it if required. + Returns the correct frame for a given list and renders it if required. """ if self.service_item_type == ServiceItemType.Text: return self._display_frames[row][u'html'].split(u'\n')[0] elif self.service_item_type == ServiceItemType.Image: - return self._raw_frames[row][u'title'] + return self._raw_frames[row][u'path'] else: return self._raw_frames[row][u'image'] diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index cdb08b6a7..48f9aaa8e 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -274,31 +274,33 @@ class MainDisplay(Display): self.setVisible(False) self.setGeometry(self.screen[u'size']) - def directImage(self, name, path, background): + def directImage(self, path, background): """ API for replacement backgrounds so Images are added directly to cache. """ - self.imageManager.addImage(name, path, u'image', background) - if hasattr(self, u'serviceItem'): - self.override[u'image'] = name - self.override[u'theme'] = self.serviceItem.themedata.theme_name - self.image(name) - # Update the preview frame. - if self.isLive: - self.parent().updatePreview() - return True - return False + self.imageManager.addImage(path, self.imageManager.imageSource.ImagePlugin, background) + if not hasattr(self, u'serviceItem'): + return False + self.override[u'image'] = path + self.override[u'theme'] = self.serviceItem.themedata.background_filename + self.image(path) + # Update the preview frame. + if self.isLive: + self.parent().updatePreview() + return True - def image(self, name): + def image(self, path): """ Add an image as the background. The image has already been added to the cache. - ``name`` - The name of the image to be displayed. + ``path`` + The path to the image to be displayed. **Note**, the path is only + passed to identify the image. If the image has changed it has to be + re-added to the image manager. """ log.debug(u'image to display') - image = self.imageManager.getImageBytes(name) + image = self.imageManager.getImageBytes(path, self.imageManager.imageSource.ImagePlugin) self.controller.mediaController.video_reset(self.controller) self.displayImage(image) @@ -360,7 +362,7 @@ class MainDisplay(Display): self.setVisible(True) return QtGui.QPixmap.grabWidget(self) - def buildHtml(self, serviceItem, image=None): + def buildHtml(self, serviceItem, image_path=u''): """ Store the serviceItem and build the new HTML from it. Add the HTML to the display @@ -377,20 +379,20 @@ class MainDisplay(Display): Receiver.send_message(u'video_background_replaced') self.override = {} # We have a different theme. - elif self.override[u'theme'] != serviceItem.themedata.theme_name: + elif self.override[u'theme'] != serviceItem.themedata.background_filename: Receiver.send_message(u'live_theme_changed') self.override = {} else: # replace the background background = self.imageManager. \ - getImageBytes(self.override[u'image']) + getImageBytes(self.override[u'image'], self.imageManager.imageSource.ImagePlugin) self.setTransparency(self.serviceItem.themedata.background_type == BackgroundType.to_string(BackgroundType.Transparent)) if self.serviceItem.themedata.background_filename: self.serviceItem.bg_image_bytes = self.imageManager. \ - getImageBytes(self.serviceItem.themedata.theme_name) - if image: - image_bytes = self.imageManager.getImageBytes(image) + getImageBytes(self.serviceItem.themedata.background_filename, self.imageManager.imageSource.Theme) + if image_path: + image_bytes = self.imageManager.getImageBytes(image_path, self.imageManager.imageSource.ImagePlugin) else: image_bytes = None html = build_html(self.serviceItem, self.screen, self.isLive, diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 2b919094d..1453bee1a 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -861,8 +861,10 @@ class SlideController(Controller): # If current slide set background to image if framenumber == slideno: self.serviceItem.bg_image_bytes = \ - self.imageManager.getImageBytes(frame[u'title']) - image = self.imageManager.getImage(frame[u'title']) + self.imageManager.getImageBytes(frame[u'path'], + self.imageManager.imageSource.ImagePlugin) + image = self.imageManager.getImage(frame[u'path'], + self.imageManager.imageSource.ImagePlugin) label.setPixmap(QtGui.QPixmap.fromImage(image)) self.previewListWidget.setCellWidget(framenumber, 0, label) slideHeight = width * (1 / self.ratio) @@ -1092,14 +1094,14 @@ class SlideController(Controller): u'%s_slide' % self.serviceItem.name.lower(), [self.serviceItem, self.isLive, row]) else: - toDisplay = self.serviceItem.get_rendered_frame(row) + to_display = self.serviceItem.get_rendered_frame(row) if self.serviceItem.is_text(): - self.display.text(toDisplay) + self.display.text(to_display) else: if start: - self.display.buildHtml(self.serviceItem, toDisplay) + self.display.buildHtml(self.serviceItem, to_display) else: - self.display.image(toDisplay) + self.display.image(to_display) # reset the store used to display first image self.serviceItem.bg_image_bytes = None self.updatePreview() diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 4e9fa6c8f..8d202ee81 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -669,8 +669,9 @@ class ThemeManager(QtGui.QWidget): self._writeTheme(theme, image_from, image_to) if theme.background_type == \ BackgroundType.to_string(BackgroundType.Image): - self.mainwindow.imageManager.updateImageBorder(theme.theme_name, - u'theme', QtGui.QColor(theme.background_border_color)) + self.mainwindow.imageManager.updateImageBorder( + theme.background_filename, + self.mainwindow.imageManager.imageSource.Theme, QtGui.QColor(theme.background_border_color)) self.mainwindow.imageManager.processUpdates() self.loadThemes() diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index fbd3916c6..b615d3078 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -99,4 +99,4 @@ class ImagePlugin(Plugin): background = QtGui.QColor(Settings().value(self.settingsSection + u'/background color', QtCore.QVariant(u'#000000'))) self.liveController.imageManager.updateImagesBorder( - u'image', background) + self.liveController.imageManager.imageSource.ImagePlugin, background) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 30ef9067a..0fdb1537c 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -229,8 +229,7 @@ class ImageMediaItem(MediaManagerItem): bitem = self.listView.item(item.row()) filename = unicode(bitem.data(QtCore.Qt.UserRole).toString()) if os.path.exists(filename): - name = os.path.split(filename)[1] - if self.plugin.liveController.display.directImage(name, + if self.plugin.liveController.display.directImage( filename, background): self.resetAction.setVisible(True) else: diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index 19ffa8a31..cb8f7b7b8 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -278,8 +278,7 @@ class MessageListener(object): item = message[0] log.debug(u'Startup called with message %s' % message) hide_mode = message[2] - file = os.path.join(item.get_frame_path(), - item.get_frame_title()) + file = os.path.join(item.get_frame_path(), item.get_frame_title()) self.handler = item.title if self.handler == self.mediaitem.Automatic: self.handler = self.mediaitem.findControllerByType(file) From bc3173966a5c9c904b51a12a7fbab9dc7201661b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 1 Jul 2012 20:41:59 +0200 Subject: [PATCH 4/6] clean ups --- openlp/core/lib/__init__.py | 11 ++++++++++- openlp/core/lib/imagemanager.py | 12 +----------- openlp/core/lib/renderer.py | 6 +++--- openlp/core/lib/serviceitem.py | 8 ++++---- openlp/core/ui/maindisplay.py | 21 ++++++++++++--------- openlp/core/ui/slidecontroller.py | 6 +++--- openlp/core/ui/thememanager.py | 4 ++-- openlp/plugins/images/imageplugin.py | 4 ++-- 8 files changed, 37 insertions(+), 35 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index e0d185cd7..fa6458354 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -36,6 +36,16 @@ from PyQt4 import QtCore, QtGui, Qt log = logging.getLogger(__name__) + +class ImageSource(object): + """ + This enumeration class represents different image sources. An image sources + states where an image is used. + """ + ImagePlugin = 1 + Theme = 2 + + class MediaType(object): """ An enumeration class for types of media. @@ -265,7 +275,6 @@ def resize_image(image_path, width, height, background=u'#000000'): if image_ratio == resize_ratio: # We neither need to centre the image nor add "bars" to the image. return preview - #FIXME: change variables to real_width and real_height realw = preview.width() realh = preview.height() # and move it to the centre of the preview space diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index 265f3b3cd..0028cc50b 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -96,15 +96,6 @@ class Priority(object): Urgent = 0 -class ImageSource(object): - """ - This enumeration class represents different image sources. An image sources - states where an image is used. - """ - ImagePlugin = 1 - Theme = 2 - - class Image(object): """ This class represents an image. To mark an image as *dirty* call the @@ -131,10 +122,10 @@ class Image(object): self.path = path self.image = None self.image_bytes = None + self.priority = Priority.Normal self.source = source self.background = background self.timestamp = os.stat(path).st_mtime - self.priority = Priority.Normal self.secondary_priority = Image.secondary_priority Image.secondary_priority += 1 @@ -196,7 +187,6 @@ class ImageManager(QtCore.QObject): self.imageThread = ImageThread(self) self._conversionQueue = PriorityQueue() self.stopManager = False - self.imageSource = ImageSource() QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.processUpdates) diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index c7b697fb1..ae9803a7f 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -32,7 +32,7 @@ from PyQt4 import QtGui, QtCore, QtWebKit from openlp.core.lib import ServiceItem, expand_tags, \ build_lyrics_format_css, build_lyrics_outline_css, Receiver, \ - ItemCapabilities, FormattingTags + ItemCapabilities, FormattingTags, ImageSource from openlp.core.lib.theme import ThemeLevel from openlp.core.ui import MainDisplay, ScreenList @@ -138,7 +138,7 @@ class Renderer(object): # if No file do not update cache if theme_data.background_filename: self.image_manager.addImage(theme_data.background_filename, - self.image_manager.imageSource.Theme, + ImageSource.Theme, QtGui.QColor(theme_data.background_border_color)) def pre_render(self, override_theme_data=None): @@ -243,7 +243,7 @@ class Renderer(object): # if No file do not update cache if theme_data.background_filename: self.image_manager.addImage(theme_data.background_filename, - self.image_manager.imageSource.Theme, + ImageSource.Theme, QtGui.QColor(theme_data.background_border_color)) theme_data, main, footer = self.pre_render(theme_data) serviceItem.themedata = theme_data diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index d0622a130..76b731307 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -36,7 +36,8 @@ import logging import os import uuid -from openlp.core.lib import build_icon, clean_tags, expand_tags, translate +from openlp.core.lib import build_icon, clean_tags, expand_tags, translate, \ + ImageSource log = logging.getLogger(__name__) @@ -217,9 +218,8 @@ class ServiceItem(object): self.image_border = background self.service_item_type = ServiceItemType.Image self._raw_frames.append({u'title': title, u'path': path}) - self.renderer.image_manager.addImage(path, - self.renderer.image_manager.imageSource.ImagePlugin, - self.image_border) + self.renderer.image_manager.addImage( + path, ImageSource.ImagePlugin, self.image_border) self._new_item() def add_from_text(self, raw_slide, verse_tag=None): diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 48f9aaa8e..17a933a55 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -37,7 +37,7 @@ from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL from PyQt4.phonon import Phonon from openlp.core.lib import Receiver, build_html, ServiceItem, image_to_byte, \ - translate, PluginManager, expand_tags + translate, PluginManager, expand_tags, ImageSource from openlp.core.lib.theme import BackgroundType from openlp.core.lib.settings import Settings @@ -278,7 +278,7 @@ class MainDisplay(Display): """ API for replacement backgrounds so Images are added directly to cache. """ - self.imageManager.addImage(path, self.imageManager.imageSource.ImagePlugin, background) + self.imageManager.addImage(path, ImageSource.ImagePlugin, background) if not hasattr(self, u'serviceItem'): return False self.override[u'image'] = path @@ -300,7 +300,7 @@ class MainDisplay(Display): re-added to the image manager. """ log.debug(u'image to display') - image = self.imageManager.getImageBytes(path, self.imageManager.imageSource.ImagePlugin) + image = self.imageManager.getImageBytes(path, ImageSource.ImagePlugin) self.controller.mediaController.video_reset(self.controller) self.displayImage(image) @@ -379,20 +379,23 @@ class MainDisplay(Display): Receiver.send_message(u'video_background_replaced') self.override = {} # We have a different theme. - elif self.override[u'theme'] != serviceItem.themedata.background_filename: + elif self.override[u'theme'] != \ + serviceItem.themedata.background_filename: Receiver.send_message(u'live_theme_changed') self.override = {} else: # replace the background - background = self.imageManager. \ - getImageBytes(self.override[u'image'], self.imageManager.imageSource.ImagePlugin) + background = self.imageManager.getImageBytes( + self.override[u'image'], ImageSource.ImagePlugin) self.setTransparency(self.serviceItem.themedata.background_type == BackgroundType.to_string(BackgroundType.Transparent)) if self.serviceItem.themedata.background_filename: - self.serviceItem.bg_image_bytes = self.imageManager. \ - getImageBytes(self.serviceItem.themedata.background_filename, self.imageManager.imageSource.Theme) + self.serviceItem.bg_image_bytes = self.imageManager.getImageBytes( + self.serviceItem.themedata.background_filename, + ImageSource.Theme) if image_path: - image_bytes = self.imageManager.getImageBytes(image_path, self.imageManager.imageSource.ImagePlugin) + image_bytes = self.imageManager.getImageBytes( + image_path, ImageSource.ImagePlugin) else: image_bytes = None html = build_html(self.serviceItem, self.screen, self.isLive, diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 1453bee1a..c59ea9afe 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -34,7 +34,7 @@ from collections import deque from PyQt4 import QtCore, QtGui from openlp.core.lib import OpenLPToolbar, Receiver, ItemCapabilities, \ - translate, build_icon, build_html, PluginManager, ServiceItem + translate, build_icon, build_html, PluginManager, ServiceItem, ImageSource from openlp.core.lib.ui import UiStrings, create_action from openlp.core.lib.settings import Settings from openlp.core.lib import SlideLimits, ServiceItemAction @@ -862,9 +862,9 @@ class SlideController(Controller): if framenumber == slideno: self.serviceItem.bg_image_bytes = \ self.imageManager.getImageBytes(frame[u'path'], - self.imageManager.imageSource.ImagePlugin) + ImageSource.ImagePlugin) image = self.imageManager.getImage(frame[u'path'], - self.imageManager.imageSource.ImagePlugin) + ImageSource.ImagePlugin) label.setPixmap(QtGui.QPixmap.fromImage(image)) self.previewListWidget.setCellWidget(framenumber, 0, label) slideHeight = width * (1 / self.ratio) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 8d202ee81..e63b9e615 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -38,7 +38,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import OpenLPToolbar, get_text_file_string, build_icon, \ Receiver, SettingsManager, translate, check_item_selected, \ - check_directory_exists, create_thumb, validate_thumb + check_directory_exists, create_thumb, validate_thumb, ImageSource from openlp.core.lib.theme import ThemeXML, BackgroundType, VerticalType, \ BackgroundGradientType from openlp.core.lib.settings import Settings @@ -671,7 +671,7 @@ class ThemeManager(QtGui.QWidget): BackgroundType.to_string(BackgroundType.Image): self.mainwindow.imageManager.updateImageBorder( theme.background_filename, - self.mainwindow.imageManager.imageSource.Theme, QtGui.QColor(theme.background_border_color)) + ImageSource.Theme, QtGui.QColor(theme.background_border_color)) self.mainwindow.imageManager.processUpdates() self.loadThemes() diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index b615d3078..97ce850f4 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -31,7 +31,7 @@ from PyQt4 import QtCore, QtGui import logging from openlp.core.lib import Plugin, StringContent, build_icon, translate, \ - Receiver + Receiver, ImageSource from openlp.core.lib.settings import Settings from openlp.plugins.images.lib import ImageMediaItem, ImageTab @@ -99,4 +99,4 @@ class ImagePlugin(Plugin): background = QtGui.QColor(Settings().value(self.settingsSection + u'/background color', QtCore.QVariant(u'#000000'))) self.liveController.imageManager.updateImagesBorder( - self.liveController.imageManager.imageSource.ImagePlugin, background) + ImageSource.ImagePlugin, background) From 584aedb3085b4204840da271f3eb83d06fefd9ce Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 1 Jul 2012 21:22:10 +0200 Subject: [PATCH 5/6] fixed doc --- openlp/core/lib/imagemanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index 0028cc50b..8ad388674 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -113,7 +113,7 @@ class Image(object): ``source`` The source describes the image's origin. Possible values are - ``image`` and ``theme``. + described in the :class:`~openlp.core.lib.ImageSource` class. ``background`` A ``QtGui.QColor`` object specifying the colour to be used to fill From 6869ea41f6ebc801b59b0e8ffce98f33dd9b5a3a Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 1 Jul 2012 21:41:12 +0200 Subject: [PATCH 6/6] updated doc --- openlp/core/lib/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index fa6458354..0591d397c 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -40,7 +40,14 @@ log = logging.getLogger(__name__) class ImageSource(object): """ This enumeration class represents different image sources. An image sources - states where an image is used. + states where an image is used. This enumeration class is need in the context + of the :class:~openlp.core.lib.imagemanager`. + + ``ImagePlugin`` + This states that an image is being used by the image plugin. + + ``Theme`` + This says, that the image is used by a theme. """ ImagePlugin = 1 Theme = 2