Skip to content

Commit

Permalink
Added IPythonViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Feb 27, 2021
1 parent a3f34e7 commit f383308
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Tests/test_imageshow.py
Expand Up @@ -62,4 +62,20 @@ def test_viewer():

def test_viewers():
for viewer in ImageShow._viewers:
viewer.get_command("test.jpg")
try:
viewer.get_command("test.jpg")
except NotImplementedError:
pass


def test_ipythonviewer():
pytest.importorskip("IPython", reason="IPython not installed")
for viewer in ImageShow._viewers:
if isinstance(viewer, ImageShow.IPythonViewer):
test_viewer = viewer
break
else:
assert False

im = hopper()
assert test_viewer.show(im) == 1
14 changes: 14 additions & 0 deletions src/PIL/ImageShow.py
Expand Up @@ -114,6 +114,20 @@ def show_file(self, file, **options):
# --------------------------------------------------------------------


class IPythonViewer(Viewer):
def show_image(self, image, **options):
display(image)
return 1


try:
from IPython.display import display
except ImportError:
pass
else:
register(IPythonViewer)


class WindowsViewer(Viewer):
"""The default viewer on Windows is the default system application for PNG files."""

Expand Down

0 comments on commit f383308

Please sign in to comment.