-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Added IPythonViewer #5289
Added IPythonViewer #5289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,17 @@ TODO | |
API Additions | ||
============= | ||
|
||
TODO | ||
^^^^ | ||
ImageShow.IPythonViewer | ||
^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
TODO | ||
If IPython is present, this new ``ImageShow.Viewer`` subclass will be | ||
registered. It displays images on all IPython frontends. This will be helpful | ||
to users of Google Colab, allowing ``im.show()`` to display images. | ||
|
||
It is lower in priority than the other default Viewer instances, so it will | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Please correct me if I'm wrong, but this is false. The new viewer has the highest priority AFAICT There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right! Thanks for catching that. However, the documentation correctly states my intention, so I've updated the code to match it. |
||
only be used by ``im.show()`` or ``ImageShow.show()`` if none of the other | ||
viewers are available. This means that the behaviour of ``ImageShow`` will stay | ||
the same for most Pillow users. | ||
|
||
Security | ||
======== | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,6 +225,23 @@ def get_command_ex(self, file, title=None, **options): | |
if shutil.which("xv"): | ||
register(XVViewer) | ||
|
||
|
||
class IPythonViewer(Viewer): | ||
"""The viewer for IPython frontends.""" | ||
|
||
def show_image(self, image, **options): | ||
ipython_display(image) | ||
return 1 | ||
|
||
|
||
try: | ||
from IPython.display import display as ipython_display | ||
except ImportError: | ||
pass | ||
else: | ||
register(IPythonViewer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, no reason. I've moved it up. |
||
|
||
|
||
if __name__ == "__main__": | ||
|
||
if len(sys.argv) < 2: | ||
|
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.
Would remove the need for a separate test.
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 separate test
Also, IPython seems to be a special case, where running its Viewer doesn't disrupt the test process - thinking generically for the sake of the future, just because a Viewer isn't based on a command line instruction doesn't mean that we want it to run in the middle of the test suite?