Skip to content

Commit

Permalink
Added IPythonViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Feb 26, 2021
1 parent 585683c commit 34b7edf
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 @@ -218,6 +218,20 @@ def get_command_ex(self, file, title=None, **options):
return command, executable


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)


if sys.platform not in ("win32", "darwin"): # unixoids
if shutil.which("display"):
register(DisplayViewer)
Expand Down

0 comments on commit 34b7edf

Please sign in to comment.