Supply filename through stdin instead of inline in Mac and Unix ImageShow viewers

This commit is contained in:
Andrew Murray 2018-11-03 14:24:10 +11:00
parent a0be7b09cc
commit fea3dafd05

View File

@ -17,6 +17,8 @@ from __future__ import print_function
from PIL import Image from PIL import Image
import os import os
import sys import sys
import subprocess
import tempfile
if sys.version_info.major >= 3: if sys.version_info.major >= 3:
from shlex import quote from shlex import quote
@ -128,6 +130,21 @@ elif sys.platform == "darwin":
quote(file)) quote(file))
return command 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) register(MacViewer)
else: else:
@ -152,6 +169,21 @@ else:
command = self.get_command_ex(file, **options)[0] command = self.get_command_ex(file, **options)[0]
return "(%s %s; rm -f %s)&" % (command, quote(file), quote(file)) 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 # implementations
class DisplayViewer(UnixViewer): class DisplayViewer(UnixViewer):