Skip to content

Commit 02affaa

Browse files
committed
Added delay after opening image with xdg-open
1 parent ca0b585 commit 02affaa

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/PIL/ImageShow.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,20 @@ def show_image(self, image, **options):
105105
return self.show_file(self.save_image(image), **options)
106106

107107
def show_file(self, file, **options):
108-
"""Display the given file."""
108+
"""Display given file"""
109109
os.system(self.get_command(file, **options))
110110
return 1
111111

112+
def _remove_file_after_delay(self, file):
113+
subprocess.Popen(
114+
[
115+
sys.executable,
116+
"-c",
117+
"import os, sys, time; time.sleep(20); os.remove(sys.argv[1])",
118+
file,
119+
]
120+
)
121+
112122

113123
# --------------------------------------------------------------------
114124

@@ -147,14 +157,7 @@ def get_command(self, file, **options):
147157
def show_file(self, file, **options):
148158
"""Display given file"""
149159
subprocess.call(["open", "-a", "Preview.app", file])
150-
subprocess.Popen(
151-
[
152-
sys.executable,
153-
"-c",
154-
"import os, sys, time; time.sleep(20); os.remove(sys.argv[1])",
155-
file,
156-
]
157-
)
160+
self._remove_file_after_delay(file)
158161
return 1
159162

160163

@@ -181,8 +184,9 @@ def get_command_ex(self, file, **options):
181184
return command, executable
182185

183186
def show_file(self, file, **options):
187+
"""Display given file"""
184188
subprocess.Popen(["xdg-open", file])
185-
os.remove(file)
189+
self._remove_file_after_delay(file)
186190
return 1
187191

188192

@@ -199,6 +203,7 @@ def get_command_ex(self, file, title=None, **options):
199203
return command, executable
200204

201205
def show_file(self, file, **options):
206+
"""Display given file"""
202207
args = ["display"]
203208
if "title" in options:
204209
args += ["-name", options["title"]]
@@ -218,6 +223,7 @@ def get_command_ex(self, file, **options):
218223
return command, executable
219224

220225
def show_file(self, file, **options):
226+
"""Display given file"""
221227
subprocess.Popen(["gm", "display", file])
222228
os.remove(file)
223229
return 1
@@ -232,6 +238,7 @@ def get_command_ex(self, file, **options):
232238
return command, executable
233239

234240
def show_file(self, file, **options):
241+
"""Display given file"""
235242
subprocess.Popen(["eog", "-n", file])
236243
os.remove(file)
237244
return 1
@@ -252,6 +259,7 @@ def get_command_ex(self, file, title=None, **options):
252259
return command, executable
253260

254261
def show_file(self, file, **options):
262+
"""Display given file"""
255263
args = ["xv"]
256264
if "title" in options:
257265
args += ["-name", options["title"]]

0 commit comments

Comments
 (0)