Skip to content

Commit

Permalink
Merge pull request #5897 from m-shinder/main
Browse files Browse the repository at this point in the history
Added ImageShow support for xdg-open
  • Loading branch information
hugovk committed Dec 23, 2021
2 parents 960da06 + d0faeb4 commit 1510efb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/reference/ImageShow.rst
Expand Up @@ -17,6 +17,7 @@ All default viewers convert the image to be shown to PNG format.

The following viewers may be registered on Unix-based systems, if the given command is found:

.. autoclass:: PIL.ImageShow.XDGViewer
.. autoclass:: PIL.ImageShow.DisplayViewer
.. autoclass:: PIL.ImageShow.GmDisplayViewer
.. autoclass:: PIL.ImageShow.EogViewer
Expand Down
12 changes: 12 additions & 0 deletions src/PIL/ImageShow.py
Expand Up @@ -186,6 +186,16 @@ def show_file(self, file, **options):
return 1


class XDGViewer(UnixViewer):
"""
The freedesktop.org ``xdg-open`` command.
"""

def get_command_ex(self, file, **options):
command = executable = "xdg-open"
return command, executable


class DisplayViewer(UnixViewer):
"""
The ImageMagick ``display`` command.
Expand Down Expand Up @@ -233,6 +243,8 @@ def get_command_ex(self, file, title=None, **options):


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

0 comments on commit 1510efb

Please sign in to comment.