mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Supply filename through stdin instead of inline in Mac and Unix ImageShow viewers
This commit is contained in:
parent
a0be7b09cc
commit
fea3dafd05
|
@ -17,6 +17,8 @@ from __future__ import print_function
|
|||
from PIL import Image
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
if sys.version_info.major >= 3:
|
||||
from shlex import quote
|
||||
|
@ -128,6 +130,21 @@ elif sys.platform == "darwin":
|
|||
quote(file))
|
||||
return command
|
||||
|
||||
def show_file(self, file, **options):
|
||||
"""Display given file"""
|
||||
f, path = tempfile.mkstemp()
|
||||
f.write(file)
|
||||
f.close()
|
||||
with open(path, "r") as f:
|
||||
subprocess.Popen([
|
||||
'im=$(cat);'
|
||||
'open -a /Applications/Preview.app $im;'
|
||||
'sleep 20;'
|
||||
'rm -f $im'
|
||||
], shell=True, stdin=f)
|
||||
os.remove(path)
|
||||
return 1
|
||||
|
||||
register(MacViewer)
|
||||
|
||||
else:
|
||||
|
@ -152,6 +169,21 @@ else:
|
|||
command = self.get_command_ex(file, **options)[0]
|
||||
return "(%s %s; rm -f %s)&" % (command, quote(file), quote(file))
|
||||
|
||||
def show_file(self, file, **options):
|
||||
"""Display given file"""
|
||||
f, path = tempfile.mkstemp()
|
||||
f.write(file)
|
||||
f.close()
|
||||
with open(path, "r") as f:
|
||||
command = self.get_command_ex(file, **options)[0]
|
||||
subprocess.Popen([
|
||||
'im=$(cat);' +
|
||||
command+' $im;'
|
||||
'rm -f $im'
|
||||
], shell=True, stdin=f)
|
||||
os.remove(path)
|
||||
return 1
|
||||
|
||||
# implementations
|
||||
|
||||
class DisplayViewer(UnixViewer):
|
||||
|
|
Loading…
Reference in New Issue
Block a user