From 0b5e2f3e7ec36d0caf144e20c50cb2fd3c6684a3 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Sun, 27 Oct 2013 00:28:32 -0600 Subject: [PATCH] Added support for custom commands for show Previously the command option to show had no effect, now, if it is set it will use that command to show the image. We still need to add some checks to the code. --- PIL/ImageShow.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/PIL/ImageShow.py b/PIL/ImageShow.py index 7e3d63ba3..2b1a5af40 100644 --- a/PIL/ImageShow.py +++ b/PIL/ImageShow.py @@ -35,15 +35,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 = CustomCommandViewer(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. @@ -140,6 +150,16 @@ else: # implementations + class CustomCommandViewer(UnixViewer): + + def __init__(self,command): + super(CustomCommandViewer, 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"