Skip to content

Commit

Permalink
Added delay after opening image with xdg-open
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Feb 2, 2022
1 parent 1430321 commit 10c4f75
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/PIL/ImageShow.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ def show_file(self, path=None, **options):
os.system(self.get_command(path, **options))
return 1

def _remove_path_after_delay(self, path):
subprocess.Popen(
[
sys.executable,
"-c",
"import os, sys, time; time.sleep(20); os.remove(sys.argv[1])",
path,
]
)


# --------------------------------------------------------------------

Expand Down Expand Up @@ -180,14 +190,7 @@ def show_file(self, path=None, **options):
else:
raise TypeError("Missing required argument: 'path'")
subprocess.call(["open", "-a", "Preview.app", path])
subprocess.Popen(
[
sys.executable,
"-c",
"import os, sys, time; time.sleep(20); os.remove(sys.argv[1])",
path,
]
)
self._remove_path_after_delay(path)
return 1


Expand Down Expand Up @@ -232,7 +235,7 @@ def show_file(self, path=None, **options):
else:
raise TypeError("Missing required argument: 'path'")
subprocess.Popen(["xdg-open", path])
os.remove(path)
self._remove_path_after_delay(path)
return 1


Expand Down

0 comments on commit 10c4f75

Please sign in to comment.