From 7ac3ae990fbd35fed011b50e3d545301e10eb229 Mon Sep 17 00:00:00 2001 From: Mihail Shinder Date: Fri, 19 Nov 2021 10:34:00 +0200 Subject: [PATCH] Add unregistered CommandViewer --- src/PIL/ImageShow.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/PIL/ImageShow.py b/src/PIL/ImageShow.py index cd0737c36..e6ea256f6 100644 --- a/src/PIL/ImageShow.py +++ b/src/PIL/ImageShow.py @@ -258,6 +258,26 @@ except ImportError: else: register(IPythonViewer) +class CommandViewer(Viewer): + """ + The viewer that use commands. + Should be suitable for any OS + """ + + def get_command(self, file, **options): + """ + Substitute ``{}`` specifiers in ``command`` + :param options: kwargs that should have 'command' in it + """ + + if not "command" in options: + raise TypeError("CommandViewer missing required keyword-only argument 'command'") + command = options["command"] + if not isinstance(command, str): + raise TypeError(f"'command' must be 'str' not '{type(command)}'") + values = {'file': file, **options} + return command.format(values) + if __name__ == "__main__":