-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support changing images in ImageEditor for all IImage subclasses #1810
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8d80241
Support changing images in ImageEditor for all IImage subclasses.
corranwebster 7412f11
Fix class names and docstrings.
corranwebster 6a50d09
Add changelog entry.
corranwebster e76e8b5
Fix tests; handle None values correctly.
corranwebster 003ec96
Exclude null toolkit from tests.
corranwebster b323e07
Add pillow as an optional editor dependency.
corranwebster 68fb97e
Add also check for ImageQt in PIL tests.
corranwebster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix issue with ImageEditor not updating for all IImage implementations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# (C) Copyright 2004-2022 Enthought, Inc., Austin, TX | ||
# All rights reserved. | ||
# | ||
# This software is provided without warranty under the terms of the BSD | ||
# license included in LICENSE.txt and may be redistributed only under | ||
# the conditions described in the aforementioned license. The license | ||
# is also available online at http://www.enthought.com/licenses/BSD.txt | ||
# | ||
# Thanks for using Enthought open source! | ||
|
||
""" Tests pertaining to the ImageEditor | ||
""" | ||
|
||
import unittest | ||
|
||
import pkg_resources | ||
|
||
from pyface.api import Image, ImageResource | ||
from traits.api import File, HasTraits | ||
from traitsui.api import ImageEditor, Item, View | ||
from traitsui.tests._tools import ( | ||
BaseTestMixin, | ||
create_ui, | ||
requires_toolkit, | ||
ToolkitName, | ||
) | ||
|
||
|
||
filename1 = pkg_resources.resource_filename( | ||
"traitsui", "examples/demo/Extras/images/e-logo-rev.png" | ||
) | ||
filename2 = pkg_resources.resource_filename( | ||
"traitsui", "examples/demo/Extras/images/info.png" | ||
) | ||
|
||
|
||
class ImageDisplay(HasTraits): | ||
|
||
image = Image() | ||
|
||
|
||
@requires_toolkit([ToolkitName.wx]) | ||
class TestImageEditor(BaseTestMixin, unittest.TestCase): | ||
|
||
def test_image_editor_static(self): | ||
obj1 = ImageDisplay() | ||
view = View( | ||
Item( | ||
'image', | ||
editor=ImageEditor( | ||
image=ImageResource(absolute_path=filename1), | ||
), | ||
) | ||
) | ||
|
||
# This should not fail. | ||
with create_ui(obj1, dict(view=view)) as ui: | ||
pass | ||
|
||
def test_image_editor_resource(self): | ||
obj1 = ImageDisplay( | ||
image=ImageResource(absolute_path=filename1) | ||
) | ||
view = View( | ||
Item( | ||
'image', | ||
editor=ImageEditor() | ||
) | ||
) | ||
|
||
# This should not fail. | ||
with create_ui(obj1, dict(view=view)) as ui: | ||
obj1.image = ImageResource(absolute_path=filename2) | ||
|
||
def test_image_editor_array(self): | ||
try: | ||
import numpy as np | ||
from pyface.api import ArrayImage | ||
except ImportError: | ||
self.skipTest("NumPy is not available") | ||
|
||
gradient1 = np.empty(shape=(256, 256, 3), dtype='uint8') | ||
gradient1[:, :, 0] = np.arange(256).reshape(256, 1) | ||
gradient1[:, :, 1] = np.arange(256).reshape(1, 256) | ||
gradient1[:, :, 2] = np.arange(255, -1, -1).reshape(1, 256) | ||
|
||
gradient2 = np.empty(shape=(256, 256, 3), dtype='uint8') | ||
gradient2[:, :, 0] = np.arange(255, -1, -1).reshape(256, 1) | ||
gradient2[:, :, 1] = np.arange(256).reshape(1, 256) | ||
gradient2[:, :, 2] = np.arange(255, -1, -1).reshape(1, 256) | ||
|
||
obj1 = ImageDisplay( | ||
image=ArrayImage(data=gradient1) | ||
) | ||
view = View( | ||
Item( | ||
'image', | ||
editor=ImageEditor() | ||
) | ||
) | ||
|
||
# This should not fail. | ||
with create_ui(obj1, dict(view=view)) as ui: | ||
obj1.image = ArrayImage(data=gradient2) | ||
|
||
def test_image_editor_pillow(self): | ||
try: | ||
import PIL.Image | ||
from pyface.api import PILImage | ||
except ImportError: | ||
self.skipTest("Pillow is not available") | ||
|
||
pil_image_1 = PIL.Image.open(filename1) | ||
pil_image_2 = PIL.Image.open(filename2) | ||
|
||
obj1 = ImageDisplay( | ||
image=PILImage(image=pil_image_1) | ||
) | ||
view = View( | ||
Item( | ||
'image', | ||
editor=ImageEditor() | ||
) | ||
) | ||
|
||
# This should not fail. | ||
with create_ui(obj1, dict(view=view)) as ui: | ||
obj1.image = PILImage(image=pil_image_2) | ||
|
||
def test_image_editor_none(self): | ||
|
||
obj1 = ImageDisplay() | ||
view = View( | ||
Item( | ||
'image', | ||
editor=ImageEditor() | ||
) | ||
) | ||
|
||
# This should not fail. | ||
with create_ui(obj1, dict(view=view)) as ui: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why can't these be run on Qt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI currently only runs on Qt.
Locally I ran
python etstool.py install --toolkit=wx
,edm shell -e traitsui-test-3.6-wx
andpython -m unittest traitsui.tests.editors.test_image_editor
and I see the following test failures:running with pyside2 I see the same failures. In
pyface.i_image_resource.MImageResource
the__init__
method is overridden and doesn't call super.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should now be resolved. The
absolute_path
was me misremembering the API, not a bug in Pyface.