mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Merge pull request #6045 from radarhere/imageshow
Do not automatically remove temporary ImageShow files on Unix
This commit is contained in:
commit
bfa6da63a4
|
@ -51,6 +51,16 @@ def test_show():
|
||||||
assert ImageShow.show(im)
|
assert ImageShow.show(im)
|
||||||
|
|
||||||
|
|
||||||
|
def test_show_without_viewers():
|
||||||
|
viewers = ImageShow._viewers
|
||||||
|
ImageShow._viewers = []
|
||||||
|
|
||||||
|
im = hopper()
|
||||||
|
assert not ImageShow.show(im)
|
||||||
|
|
||||||
|
ImageShow._viewers = viewers
|
||||||
|
|
||||||
|
|
||||||
def test_viewer():
|
def test_viewer():
|
||||||
viewer = ImageShow.Viewer()
|
viewer = ImageShow.Viewer()
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,13 @@ breaking backwards compatibility.
|
||||||
Other Changes
|
Other Changes
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
ImageShow temporary files on Unix
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
When calling :py:meth:`~PIL.Image.Image.show` or using :py:mod:`~PIL.ImageShow`,
|
||||||
|
a temporary file is created from the image. On Unix, Pillow will no longer delete these
|
||||||
|
files, and instead leave it to the operating system to do so.
|
||||||
|
|
||||||
Image._repr_pretty_
|
Image._repr_pretty_
|
||||||
^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,8 @@ def show(image, title=None, **options):
|
||||||
"""
|
"""
|
||||||
for viewer in _viewers:
|
for viewer in _viewers:
|
||||||
if viewer.show(image, title=title, **options):
|
if viewer.show(image, title=title, **options):
|
||||||
return 1
|
return True
|
||||||
return 0
|
return False
|
||||||
|
|
||||||
|
|
||||||
class Viewer:
|
class Viewer:
|
||||||
|
@ -126,16 +126,6 @@ class Viewer:
|
||||||
os.system(self.get_command(path, **options))
|
os.system(self.get_command(path, **options))
|
||||||
return 1
|
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,
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -190,7 +180,14 @@ class MacViewer(Viewer):
|
||||||
else:
|
else:
|
||||||
raise TypeError("Missing required argument: 'path'")
|
raise TypeError("Missing required argument: 'path'")
|
||||||
subprocess.call(["open", "-a", "Preview.app", path])
|
subprocess.call(["open", "-a", "Preview.app", path])
|
||||||
self._remove_path_after_delay(path)
|
subprocess.Popen(
|
||||||
|
[
|
||||||
|
sys.executable,
|
||||||
|
"-c",
|
||||||
|
"import os, sys, time; time.sleep(20); os.remove(sys.argv[1])",
|
||||||
|
path,
|
||||||
|
]
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,7 +201,7 @@ class UnixViewer(Viewer):
|
||||||
|
|
||||||
def get_command(self, file, **options):
|
def get_command(self, file, **options):
|
||||||
command = self.get_command_ex(file, **options)[0]
|
command = self.get_command_ex(file, **options)[0]
|
||||||
return f"({command} {quote(file)}; rm -f {quote(file)})&"
|
return f"({command} {quote(file)}"
|
||||||
|
|
||||||
|
|
||||||
class XDGViewer(UnixViewer):
|
class XDGViewer(UnixViewer):
|
||||||
|
@ -235,7 +232,6 @@ class XDGViewer(UnixViewer):
|
||||||
else:
|
else:
|
||||||
raise TypeError("Missing required argument: 'path'")
|
raise TypeError("Missing required argument: 'path'")
|
||||||
subprocess.Popen(["xdg-open", path])
|
subprocess.Popen(["xdg-open", path])
|
||||||
self._remove_path_after_delay(path)
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,7 +244,7 @@ class DisplayViewer(UnixViewer):
|
||||||
def get_command_ex(self, file, title=None, **options):
|
def get_command_ex(self, file, title=None, **options):
|
||||||
command = executable = "display"
|
command = executable = "display"
|
||||||
if title:
|
if title:
|
||||||
command += f" -name {quote(title)}"
|
command += f" -title {quote(title)}"
|
||||||
return command, executable
|
return command, executable
|
||||||
|
|
||||||
def show_file(self, path=None, **options):
|
def show_file(self, path=None, **options):
|
||||||
|
@ -270,11 +266,10 @@ class DisplayViewer(UnixViewer):
|
||||||
raise TypeError("Missing required argument: 'path'")
|
raise TypeError("Missing required argument: 'path'")
|
||||||
args = ["display"]
|
args = ["display"]
|
||||||
if "title" in options:
|
if "title" in options:
|
||||||
args += ["-name", options["title"]]
|
args += ["-title", options["title"]]
|
||||||
args.append(path)
|
args.append(path)
|
||||||
|
|
||||||
subprocess.Popen(args)
|
subprocess.Popen(args)
|
||||||
os.remove(path)
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -304,7 +299,6 @@ class GmDisplayViewer(UnixViewer):
|
||||||
else:
|
else:
|
||||||
raise TypeError("Missing required argument: 'path'")
|
raise TypeError("Missing required argument: 'path'")
|
||||||
subprocess.Popen(["gm", "display", path])
|
subprocess.Popen(["gm", "display", path])
|
||||||
os.remove(path)
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -334,7 +328,6 @@ class EogViewer(UnixViewer):
|
||||||
else:
|
else:
|
||||||
raise TypeError("Missing required argument: 'path'")
|
raise TypeError("Missing required argument: 'path'")
|
||||||
subprocess.Popen(["eog", "-n", path])
|
subprocess.Popen(["eog", "-n", path])
|
||||||
os.remove(path)
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -375,7 +368,6 @@ class XVViewer(UnixViewer):
|
||||||
args.append(path)
|
args.append(path)
|
||||||
|
|
||||||
subprocess.Popen(args)
|
subprocess.Popen(args)
|
||||||
os.remove(path)
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user