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
Conversation
5f1399c
to
34b7edf
Compare
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 be very useful! Even if it takes a while until the changes reach Colab, it is not difficult to upgrade Pillow manually anyway.
src/PIL/ImageShow.py
Outdated
|
||
|
||
try: | ||
from IPython.display import display |
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.
from IPython.display import display | |
from IPython.display import display as _display |
Would it be reasonable to add a prefix to avoid confusion when using code completion tools? ImageShow.show
and ImageShow.display
are very similar and could be confusing to someone using it for the first time.
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.
Okay, sure. I went with ipython_display
, to be even clearer.
except ImportError: | ||
pass | ||
else: | ||
register(IPythonViewer) |
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.
Any reason to put IPythonViewer
before the unix viewers but after the other Windows/macOS ones? I think it would be best to put this at the top (or use register(..., order=0)
) to help consistency in IPython (e.g. when combined with tools that offer PDF exports, etc.).
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.
Yep, no reason. I've moved it up.
try: | ||
viewer.get_command("test.jpg") | ||
except NotImplementedError: | ||
pass |
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.
pass | |
assert viewer.show(hopper()) == 1 |
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
- confirms that the IPythonViewer is present when IPython is available
- runs IPythonViewer even if another Viewer instance has priority
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?
0706f1c
to
55d3d26
Compare
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 comment
The reason will be displayed to describe this comment to others. Learn more.
It is lower in priority than the other default Viewer instances
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 comment
The 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.
Resolves #5286 by adding a new
ImageShow.Viewer
-IPythonViewer
. It calls thedisplay()
method to allowImageShow
to work with IPython... and Google Colab.Here is my demonstration of it working in Google Colab.