diff --git a/PIL/ImageShow.py b/PIL/ImageShow.py index 6ed913c8d..0d9757f14 100644 --- a/PIL/ImageShow.py +++ b/PIL/ImageShow.py @@ -40,15 +40,25 @@ def register(viewer, order=1): # # @param image An image object. # @param title Optional title. Not all viewers can display the title. +# @param command Optional command. Command to display the image with. # @param **options Additional viewer options. # @return True if a suitable viewer was found, false otherwise. -def show(image, title=None, **options): +def show(image, title=None, command=None, **options): + if command is not None: + return _showWithCommand(image,command,title=title,**options) for viewer in _viewers: if viewer.show(image, title=title, **options): return 1 return 0 +def _showWithCommand(image,command,**options): + viewer = SimpleCommandViewer(command) + #TODO: Should we register these viewers and see if there is already a + #viewer for this command? + viewer.show(image,**options) + return True + ## # Base class for viewers. @@ -108,6 +118,9 @@ if sys.platform == "win32": register(WindowsViewer) + class SimpleCommandViewer(WindowsViewer): + pass + elif sys.platform == "darwin": class MacViewer(Viewer): @@ -121,6 +134,9 @@ elif sys.platform == "darwin": register(MacViewer) + class SimpleCommandViewer(MacViewer): + pass + else: # unixoids @@ -145,6 +161,15 @@ else: # implementations + class SimpleCommandViewer(UnixViewer): + def __init__(self,command): + super(SimpleCommandViewer, self).__init__() + self._command = command + + def get_command_ex(self, file, **options): + command = executable = self._command + return command, executable + class DisplayViewer(UnixViewer): def get_command_ex(self, file, **options): command = executable = "display"