[Image-SIG] im.show does not show, and Tkinter isn't displaying my jpg image
Rodrigo Dias Arruda Senra
rsenra at acm.org
Tue Apr 8 04:15:40 CEST 2008
[ Fredrik Lundh ]:
---------------------
>Rodrigo Dias Arruda Senra wrote:
>
>> By the way, I'd like to suggest a solution similar to webbrowser in
>> python's stdlib. We could encapsulate in a module tests for the
>> availability of several image viewers, and im.show() could fallback
>> to what was available (or configured) for the current platform.
>
>good idea.
Glad to hear this!
> I've posted a draft version of such a module here:
>
> http://svn.effbot.org/public/stuff/sandbox/pil/ImageShow.py
>
>to try it out,
Just did, and it worked all fine as expected.
> tweaks and feedback for other platforms are welcome.
I have two small suggestions. Adding "eog" as one of the
viewers, and using the environment variable VIEWER as a way
to boost the priority of a preferred viewer.
A tiny patch follows:
<patch>
===================================================================
--- ImageShow.py (revision 511)
+++ ImageShow.py (working copy)
@@ -154,6 +154,20 @@
register_if_present(DisplayViewer)
+ class EogViewer(UnixViewer):
+ """The Eye of GNOME image viewer is the official image viewer
+ for the GNOME Desktop environment. With it, you can view
+ single image files, as well as large image collections.
+ More info at http://www.gnome.org/projects/eog/
+ """
+ executable = "eog"
+ def get_command(self, file, title=None, **options):
+ command = self.executable
+ # title - AFAICT, unsupported by eog <=2.18.1
+ return command
+
+ register_if_present(EogViewer)
+
class XVViewer(UnixViewer):
executable = "xv"
def get_command(self, file, title=None, **options):
@@ -167,6 +181,16 @@
register_if_present(XVViewer)
+# Boost priority of a viewer if specified in the environment
+preferred_viewer = os.environ.get("VIEWER")
+if preferred_viewer:
+ options = [v.executable for v in _viewers]
+ try:
+ pos = options.index(preferred_viewer)
+ _viewers = [_viewers[pos]] + _viewers[:pos] + _viewers[pos+1:]
+ except ValueError:
+ pass # preferred viewer not registered, sorry ;o)
+
if __name__ == "__main__":
# usage: python ImageShow.py imagefile [title]
print show(Image.open(sys.argv[1]), *sys.argv[2:])
</patch>
best regards,
Rod Senra
More information about the Image-SIG
mailing list