forked from openlp/openlp
resize image in the thread not when adding the image
This commit is contained in:
parent
dbef87021c
commit
11cb39d2dc
@ -53,15 +53,17 @@ class ImageThread(QtCore.QThread):
|
|||||||
"""
|
"""
|
||||||
Run the thread.
|
Run the thread.
|
||||||
"""
|
"""
|
||||||
self.imageManager.process()
|
self.imageManager._process()
|
||||||
|
|
||||||
|
|
||||||
class Image(object):
|
class Image(object):
|
||||||
name = ''
|
def __init__(self, name='', path=''):
|
||||||
path = ''
|
self.name = name
|
||||||
dirty = True
|
self.path = path
|
||||||
image = None
|
self.dirty = True
|
||||||
image_bytes = None
|
self.image = None
|
||||||
|
self.image_bytes = None
|
||||||
|
self.priority = False
|
||||||
|
|
||||||
|
|
||||||
class ImageManager(QtCore.QObject):
|
class ImageManager(QtCore.QObject):
|
||||||
@ -92,7 +94,6 @@ class ImageManager(QtCore.QObject):
|
|||||||
for key in self._cache.keys():
|
for key in self._cache.keys():
|
||||||
image = self._cache[key]
|
image = self._cache[key]
|
||||||
image.dirty = True
|
image.dirty = True
|
||||||
image.image = resize_image(image.path, self.width, self.height)
|
|
||||||
self._cache_dirty = True
|
self._cache_dirty = True
|
||||||
# only one thread please
|
# only one thread please
|
||||||
if not self._thread_running:
|
if not self._thread_running:
|
||||||
@ -103,6 +104,10 @@ class ImageManager(QtCore.QObject):
|
|||||||
Return the Qimage from the cache
|
Return the Qimage from the cache
|
||||||
"""
|
"""
|
||||||
log.debug(u'get_image %s' % name)
|
log.debug(u'get_image %s' % name)
|
||||||
|
if not self._cache[name].image_bytes:
|
||||||
|
while self._cache[name].dirty:
|
||||||
|
log.debug(u'get_image - waiting')
|
||||||
|
time.sleep(0.1)
|
||||||
return self._cache[name].image
|
return self._cache[name].image
|
||||||
|
|
||||||
def get_image_bytes(self, name):
|
def get_image_bytes(self, name):
|
||||||
@ -131,10 +136,7 @@ class ImageManager(QtCore.QObject):
|
|||||||
"""
|
"""
|
||||||
log.debug(u'add_image %s:%s' % (name, path))
|
log.debug(u'add_image %s:%s' % (name, path))
|
||||||
if not name in self._cache:
|
if not name in self._cache:
|
||||||
image = Image()
|
image = Image(name, path)
|
||||||
image.name = name
|
|
||||||
image.path = path
|
|
||||||
image.image = resize_image(path, self.width, self.height)
|
|
||||||
self._cache[name] = image
|
self._cache[name] = image
|
||||||
else:
|
else:
|
||||||
log.debug(u'Image in cache %s:%s' % (name, path))
|
log.debug(u'Image in cache %s:%s' % (name, path))
|
||||||
@ -143,29 +145,30 @@ class ImageManager(QtCore.QObject):
|
|||||||
if not self._thread_running:
|
if not self._thread_running:
|
||||||
self.image_thread.start()
|
self.image_thread.start()
|
||||||
|
|
||||||
def process(self):
|
def _process(self):
|
||||||
"""
|
"""
|
||||||
Controls the processing called from a QThread
|
Controls the processing called from a ``QtCore.QThread``.
|
||||||
"""
|
"""
|
||||||
log.debug(u'process - started')
|
log.debug(u'_process - started')
|
||||||
self._thread_running = True
|
self._thread_running = True
|
||||||
self.clean_cache()
|
self._clean_cache()
|
||||||
# data loaded since we started ?
|
# data loaded since we started ?
|
||||||
while self._cache_dirty:
|
while self._cache_dirty:
|
||||||
log.debug(u'process - recycle')
|
log.debug(u'_process - recycle')
|
||||||
self.clean_cache()
|
self._clean_cache()
|
||||||
self._thread_running = False
|
self._thread_running = False
|
||||||
log.debug(u'process - ended')
|
log.debug(u'_process - ended')
|
||||||
|
|
||||||
def clean_cache(self):
|
def _clean_cache(self):
|
||||||
"""
|
"""
|
||||||
Actually does the work.
|
Actually does the work.
|
||||||
"""
|
"""
|
||||||
log.debug(u'clean_cache')
|
log.debug(u'_clean_cache')
|
||||||
# we will clean the cache now
|
# we will clean the cache now
|
||||||
self._cache_dirty = False
|
self._cache_dirty = False
|
||||||
for key in self._cache.keys():
|
for key in self._cache.keys():
|
||||||
image = self._cache[key]
|
image = self._cache[key]
|
||||||
if image.dirty:
|
if image.dirty:
|
||||||
|
image.image = resize_image(image.path, self.width, self.height)
|
||||||
image.image_bytes = image_to_byte(image.image)
|
image.image_bytes = image_to_byte(image.image)
|
||||||
image.dirty = False
|
image.dirty = False
|
||||||
|
@ -582,6 +582,9 @@ class SlideController(QtGui.QWidget):
|
|||||||
Loads a ServiceItem into the system from ServiceManager
|
Loads a ServiceItem into the system from ServiceManager
|
||||||
Display the slide number passed
|
Display the slide number passed
|
||||||
"""
|
"""
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
|
start = time.time()
|
||||||
log.debug(u'processManagerItem live = %s' % self.isLive)
|
log.debug(u'processManagerItem live = %s' % self.isLive)
|
||||||
self.onStopLoop()
|
self.onStopLoop()
|
||||||
old_item = self.serviceItem
|
old_item = self.serviceItem
|
||||||
@ -631,7 +634,9 @@ class SlideController(QtGui.QWidget):
|
|||||||
if framenumber == slideno:
|
if framenumber == slideno:
|
||||||
self.serviceItem.bg_image_bytes = \
|
self.serviceItem.bg_image_bytes = \
|
||||||
self.imageManager.get_image_bytes(frame[u'title'])
|
self.imageManager.get_image_bytes(frame[u'title'])
|
||||||
|
print u' start', frame[u'title']
|
||||||
image = self.imageManager.get_image(frame[u'title'])
|
image = self.imageManager.get_image(frame[u'title'])
|
||||||
|
print u' end', frame[u'title']
|
||||||
label.setPixmap(QtGui.QPixmap.fromImage(image))
|
label.setPixmap(QtGui.QPixmap.fromImage(image))
|
||||||
self.previewListWidget.setCellWidget(framenumber, 0, label)
|
self.previewListWidget.setCellWidget(framenumber, 0, label)
|
||||||
slideHeight = width * self.parent().renderer.screen_ratio
|
slideHeight = width * self.parent().renderer.screen_ratio
|
||||||
@ -668,6 +673,7 @@ class SlideController(QtGui.QWidget):
|
|||||||
self.onMediaClose()
|
self.onMediaClose()
|
||||||
Receiver.send_message(u'slidecontroller_%s_started' % self.typePrefix,
|
Receiver.send_message(u'slidecontroller_%s_started' % self.typePrefix,
|
||||||
[serviceItem])
|
[serviceItem])
|
||||||
|
print unicode(datetime.timedelta(seconds=time.time() - start))
|
||||||
|
|
||||||
def __updatePreviewSelection(self, slideno):
|
def __updatePreviewSelection(self, slideno):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user