openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #27087
[Merge] lp:~trb143/openlp/imagemanager-2_4a into lp:openlp
Tim Bentley has proposed merging lp:~trb143/openlp/imagemanager-2_4a into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~trb143/openlp/imagemanager-2_4a/+merge/262392
This code be a 2.2 or 2.4 but requesting now for review.
Remove the Base64 image from the cache and generate it when needed.
Removes have the cache loading work and removes 4/7's of the cache memory.
Also moved the image delete to the bottom as I was fed up deleting images instead of previewing them!
lp:~trb143/openlp/imagemanager-2_4a (revision 2546)
[SUCCESS] https//ci.openlp.io/job/Branch-01-Pull/1044/
[SUCCESS] https//ci.openlp.io/job/Branch-02-Functional-Tests/967/
[SUCCESS] https//ci.openlp.io/job/Branch-03-Interface-Tests/909/
[SUCCESS] https//ci.openlp.io/job/Branch-04a-Windows_Functional_Tests/796/
[SUCCESS] https//ci.openlp.io/job/Branch-04b-Windows_Interface_Tests/394/
[SUCCESS] https//ci.openlp.io/job/Branch-05a-Code_Analysis/522/
[SUCCESS] https//ci.openlp.io/job/Branch-05b-Test_Coverage/393/
--
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/imagemanager-2_4a into lp:openlp.
=== modified file 'openlp/core/lib/imagemanager.py'
--- openlp/core/lib/imagemanager.py 2015-01-18 13:39:21 +0000
+++ openlp/core/lib/imagemanager.py 2015-06-18 21:26:48 +0000
@@ -113,7 +113,6 @@
"""
self.path = path
self.image = None
- self.image_bytes = None
self.priority = Priority.Normal
self.source = source
self.background = background
@@ -219,10 +218,9 @@
def _reset_image(self, image):
"""
- Mark the given :class:`Image` instance as dirty by setting its ``image`` and ``image_bytes`` attributes to None.
+ Mark the given :class:`Image` instance as dirty by setting its ``image`` attributes to None.
"""
image.image = None
- image.image_bytes = None
self._conversion_queue.modify_priority(image, Priority.Normal)
def process_updates(self):
@@ -246,11 +244,6 @@
while image.image is None:
log.debug('getImage - waiting')
time.sleep(0.1)
- elif image.image_bytes is None:
- # Set the priority to Low, because the image was requested but the byte stream was not generated yet.
- # However, we only need to do this, when the image was generated before it was requested (otherwise this is
- # already taken care of).
- self._conversion_queue.modify_priority(image, Priority.Low)
return image.image
def get_image_bytes(self, path, source, width=-1, height=-1):
@@ -259,14 +252,14 @@
"""
log.debug('get_image_bytes %s' % path)
image = self._cache[(path, source, width, height)]
- if image.image_bytes is None:
+ if image.image is None:
self._conversion_queue.modify_priority(image, Priority.Urgent)
# make sure we are running and if not give it a kick
self.process_updates()
- while image.image_bytes is None:
+ while image.image is None:
log.debug('getImageBytes - waiting')
time.sleep(0.1)
- return image.image_bytes
+ return image_to_byte(image.image)
def add_image(self, path, source, background, width=-1, height=-1):
"""
@@ -317,6 +310,3 @@
elif image.priority == Priority.High:
self._conversion_queue.modify_priority(image, Priority.Low)
return
- # Generate the byte stream for the image.
- if image.image_bytes is None:
- image.image_bytes = image_to_byte(image.image)
=== modified file 'openlp/plugins/images/lib/mediaitem.py'
--- openlp/plugins/images/lib/mediaitem.py 2015-05-16 21:24:57 +0000
+++ openlp/plugins/images/lib/mediaitem.py 2015-06-18 21:26:48 +0000
@@ -119,14 +119,6 @@
icon=':/general/general_edit.png',
triggers=self.on_edit_click)
create_widget_action(self.list_view, separator=True)
- if self.has_delete_icon:
- create_widget_action(
- self.list_view,
- 'listView%s%sItem' % (self.plugin.name.title(), StringContent.Delete.title()),
- text=self.plugin.get_string(StringContent.Delete)['title'],
- icon=':/general/general_delete.png',
- can_shortcuts=True, triggers=self.on_delete_click)
- create_widget_action(self.list_view, separator=True)
create_widget_action(
self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Preview.title()),
@@ -155,6 +147,14 @@
text=translate('OpenLP.MediaManagerItem', '&Add to selected Service Item'),
icon=':/general/general_add.png',
triggers=self.on_add_edit_click)
+ if self.has_delete_icon:
+ create_widget_action(self.list_view, separator=True)
+ create_widget_action(
+ self.list_view,
+ 'listView%s%sItem' % (self.plugin.name.title(), StringContent.Delete.title()),
+ text=self.plugin.get_string(StringContent.Delete)['title'],
+ icon=':/general/general_delete.png',
+ can_shortcuts=True, triggers=self.on_delete_click)
self.add_custom_context_actions()
# Create the context menu and add all actions from the list_view.
self.menu = QtGui.QMenu()
=== modified file 'tests/functional/openlp_core_lib/test_image_manager.py'
--- tests/functional/openlp_core_lib/test_image_manager.py 2015-01-18 13:39:21 +0000
+++ tests/functional/openlp_core_lib/test_image_manager.py 2015-06-18 21:26:48 +0000
@@ -115,59 +115,59 @@
self.image_manager.get_image(full_path, 'church.jpg', 120, 120)
self.assertNotEquals(context.exception, '', 'KeyError exception should have been thrown for missing dimension')
- def process_cache_test(self):
+ @patch('openlp.core.lib.imagemanager.resize_image')
+ @patch('openlp.core.lib.imagemanager.image_to_byte')
+ def process_cache_test(self, mocked_resize_image, mocked_image_to_byte):
"""
Test the process_cache method
"""
- with patch('openlp.core.lib.imagemanager.resize_image') as mocked_resize_image, \
- patch('openlp.core.lib.imagemanager.image_to_byte') as mocked_image_to_byte:
- # GIVEN: Mocked functions
- mocked_resize_image.side_effect = self.mocked_resize_image
- mocked_image_to_byte.side_effect = self.mocked_image_to_byte
- image1 = 'church.jpg'
- image2 = 'church2.jpg'
- image3 = 'church3.jpg'
- image4 = 'church4.jpg'
-
- # WHEN: Add the images. Then get the lock (=queue can not be processed).
- self.lock.acquire()
- self.image_manager.add_image(TEST_PATH, image1, None)
- self.image_manager.add_image(TEST_PATH, image2, None)
-
- # THEN: All images have been added to the queue, and only the first image is not be in the list anymore, but
- # is being processed (see mocked methods/functions).
- # Note: Priority.Normal means, that the resize_image() was not completed yet (because afterwards the #
- # priority is adjusted to Priority.Lowest).
- self.assertEqual(self.get_image_priority(image1), Priority.Normal,
- "image1's priority should be 'Priority.Normal'")
- self.assertEqual(self.get_image_priority(image2), Priority.Normal,
- "image2's priority should be 'Priority.Normal'")
-
- # WHEN: Add more images.
- self.image_manager.add_image(TEST_PATH, image3, None)
- self.image_manager.add_image(TEST_PATH, image4, None)
- # Allow the queue to process.
- self.lock.release()
- # Request some "data".
- image_bytes = self.image_manager.get_image_bytes(TEST_PATH, image4)
- image_object = self.image_manager.get_image(TEST_PATH, image3)
- # Now the mocked methods/functions do not have to sleep anymore.
- self.sleep_time = 0
- # Wait for the queue to finish.
- while not self.image_manager._conversion_queue.empty():
- time.sleep(0.1)
- # Because empty() is not reliable, wait a litte; just to make sure.
+ # GIVEN: Mocked functions
+ mocked_resize_image.side_effect = self.mocked_resize_image
+ mocked_image_to_byte.side_effect = self.mocked_image_to_byte
+ image1 = 'church.jpg'
+ image2 = 'church2.jpg'
+ image3 = 'church3.jpg'
+ image4 = 'church4.jpg'
+
+ # WHEN: Add the images. Then get the lock (=queue can not be processed).
+ self.lock.acquire()
+ self.image_manager.add_image(TEST_PATH, image1, None)
+ self.image_manager.add_image(TEST_PATH, image2, None)
+
+ # THEN: All images have been added to the queue, and only the first image is not be in the list anymore, but
+ # is being processed (see mocked methods/functions).
+ # Note: Priority.Normal means, that the resize_image() was not completed yet (because afterwards the #
+ # priority is adjusted to Priority.Lowest).
+ self.assertEqual(self.get_image_priority(image1), Priority.Normal,
+ "image1's priority should be 'Priority.Normal'")
+ self.assertEqual(self.get_image_priority(image2), Priority.Normal,
+ "image2's priority should be 'Priority.Normal'")
+
+ # WHEN: Add more images.
+ self.image_manager.add_image(TEST_PATH, image3, None)
+ self.image_manager.add_image(TEST_PATH, image4, None)
+ # Allow the queue to process.
+ self.lock.release()
+ # Request some "data".
+ image_bytes = self.image_manager.get_image_bytes(TEST_PATH, image4)
+ image_object = self.image_manager.get_image(TEST_PATH, image3)
+ # Now the mocked methods/functions do not have to sleep anymore.
+ self.sleep_time = 0
+ # Wait for the queue to finish.
+ while not self.image_manager._conversion_queue.empty():
time.sleep(0.1)
- # THEN: The images' priority reflect how they were processed.
- self.assertEqual(self.image_manager._conversion_queue.qsize(), 0, "The queue should be empty.")
- self.assertEqual(self.get_image_priority(image1), Priority.Lowest,
- "The image should have not been requested (=Lowest)")
- self.assertEqual(self.get_image_priority(image2), Priority.Lowest,
- "The image should have not been requested (=Lowest)")
- self.assertEqual(self.get_image_priority(image3), Priority.Low,
- "Only the QImage should have been requested (=Low).")
- self.assertEqual(self.get_image_priority(image4), Priority.Urgent,
- "The image bytes should have been requested (=Urgent).")
+ # Because empty() is not reliable, wait a litte; just to make sure.
+ time.sleep(0.1)
+ # THEN: The images' priority reflect how they were processed.
+ self.assertEqual(self.image_manager._conversion_queue.qsize(), 0, "The queue should be empty.")
+ self.assertEqual(self.get_image_priority(image1), Priority.Lowest,
+ "The image should have not been requested (=Lowest)")
+ self.assertEqual(self.get_image_priority(image2), Priority.Lowest,
+ "The image should have not been requested (=Lowest)")
+ self.assertEqual(self.get_image_priority(image3), Priority.Low,
+ "Only the QImage should have been requested (=Low).")
+ self.assertEqual(self.get_image_priority(image4), Priority.Urgent,
+ "The image bytes should have been requested (=Urgent).")
def get_image_priority(self, image):
"""
=== modified file 'tests/interfaces/openlp_core_ui/test_thememanager.py'
--- tests/interfaces/openlp_core_ui/test_thememanager.py 2015-02-28 09:41:06 +0000
+++ tests/interfaces/openlp_core_ui/test_thememanager.py 2015-06-18 21:26:48 +0000
@@ -25,7 +25,7 @@
from unittest import TestCase
from openlp.core.common import Registry, Settings
-from openlp.core.ui import ThemeManager, ThemeForm, FileRenameForm
+from openlp.core.ui import ThemeManager
from tests.functional import patch, MagicMock
from tests.helpers.testmixin import TestMixin
@@ -122,3 +122,18 @@
# THEN:
self.assertEqual(self.theme_manager.path, self.theme_manager.theme_form.path)
self.assertEqual(1, self.theme_manager.load_themes.call_count, "load_themes should have been called once")
+
+ def push_themes_test(self):
+ """
+ Test the _push theme call triggers the registry call.
+ """
+ # GIVEN: A mocked method call
+ mocked_get_themes = MagicMock()
+ self.theme_manager.get_themes = mocked_get_themes
+ Registry().register_function('theme_update_list', MagicMock())
+
+ # WHEN: I request the themes lists to be updated
+ self.theme_manager._push_themes()
+
+ # THEN: then get_themes should have been called
+ self.assertEqual(1, mocked_get_themes.call_count, "get_themes should have been called once")
Follow ups