From 02affaa491df37117a7562e6ba6ac52c4c871195 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 3 Feb 2022 08:58:12 +1100 Subject: [PATCH] Added delay after opening image with xdg-open --- src/PIL/ImageShow.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/PIL/ImageShow.py b/src/PIL/ImageShow.py index c5b2c4bccd8..c928fc30590 100644 --- a/src/PIL/ImageShow.py +++ b/src/PIL/ImageShow.py @@ -105,10 +105,20 @@ def show_image(self, image, **options): return self.show_file(self.save_image(image), **options) def show_file(self, file, **options): - """Display the given file.""" + """Display given file""" os.system(self.get_command(file, **options)) return 1 + def _remove_file_after_delay(self, file): + subprocess.Popen( + [ + sys.executable, + "-c", + "import os, sys, time; time.sleep(20); os.remove(sys.argv[1])", + file, + ] + ) + # -------------------------------------------------------------------- @@ -147,14 +157,7 @@ def get_command(self, file, **options): def show_file(self, file, **options): """Display given file""" subprocess.call(["open", "-a", "Preview.app", file]) - subprocess.Popen( - [ - sys.executable, - "-c", - "import os, sys, time; time.sleep(20); os.remove(sys.argv[1])", - file, - ] - ) + self._remove_file_after_delay(file) return 1 @@ -181,8 +184,9 @@ def get_command_ex(self, file, **options): return command, executable def show_file(self, file, **options): + """Display given file""" subprocess.Popen(["xdg-open", file]) - os.remove(file) + self._remove_file_after_delay(file) return 1 @@ -199,6 +203,7 @@ def get_command_ex(self, file, title=None, **options): return command, executable def show_file(self, file, **options): + """Display given file""" args = ["display"] if "title" in options: args += ["-name", options["title"]] @@ -218,6 +223,7 @@ def get_command_ex(self, file, **options): return command, executable def show_file(self, file, **options): + """Display given file""" subprocess.Popen(["gm", "display", file]) os.remove(file) return 1 @@ -232,6 +238,7 @@ def get_command_ex(self, file, **options): return command, executable def show_file(self, file, **options): + """Display given file""" subprocess.Popen(["eog", "-n", file]) os.remove(file) return 1 @@ -252,6 +259,7 @@ def get_command_ex(self, file, title=None, **options): return command, executable def show_file(self, file, **options): + """Display given file""" args = ["xv"] if "title" in options: args += ["-name", options["title"]]