mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 21:24:31 +03:00
Merge pull request #3450 from radarhere/imageshow
ImageShow improvements
This commit is contained in:
commit
5c16528fdf
|
@ -14,6 +14,9 @@ class TestImageShow(PillowTestCase):
|
||||||
# Test registering a viewer that is not a class
|
# Test registering a viewer that is not a class
|
||||||
ImageShow.register("not a class")
|
ImageShow.register("not a class")
|
||||||
|
|
||||||
|
# Restore original state
|
||||||
|
ImageShow._viewers.pop()
|
||||||
|
|
||||||
def test_show(self):
|
def test_show(self):
|
||||||
class TestViewer:
|
class TestViewer:
|
||||||
methodCalled = False
|
methodCalled = False
|
||||||
|
@ -28,6 +31,9 @@ class TestImageShow(PillowTestCase):
|
||||||
self.assertTrue(ImageShow.show(im))
|
self.assertTrue(ImageShow.show(im))
|
||||||
self.assertTrue(viewer.methodCalled)
|
self.assertTrue(viewer.methodCalled)
|
||||||
|
|
||||||
|
# Restore original state
|
||||||
|
ImageShow._viewers.pop(0)
|
||||||
|
|
||||||
def test_viewer(self):
|
def test_viewer(self):
|
||||||
viewer = ImageShow.Viewer()
|
viewer = ImageShow.Viewer()
|
||||||
|
|
||||||
|
@ -35,6 +41,10 @@ class TestImageShow(PillowTestCase):
|
||||||
|
|
||||||
self.assertRaises(NotImplementedError, viewer.get_command, None)
|
self.assertRaises(NotImplementedError, viewer.get_command, None)
|
||||||
|
|
||||||
|
def test_viewers(self):
|
||||||
|
for viewer in ImageShow._viewers:
|
||||||
|
viewer.get_command('test.jpg')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -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:
|
||||||
|
@ -148,11 +165,23 @@ else:
|
||||||
format = "PNG"
|
format = "PNG"
|
||||||
options = {'compress_level': 1}
|
options = {'compress_level': 1}
|
||||||
|
|
||||||
|
def get_command(self, file, **options):
|
||||||
|
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):
|
def show_file(self, file, **options):
|
||||||
command, executable = self.get_command_ex(file, **options)
|
"""Display given file"""
|
||||||
command = "(%s %s; rm -f %s)&" % (command, quote(file),
|
f, path = tempfile.mkstemp()
|
||||||
quote(file))
|
f.write(file)
|
||||||
os.system(command)
|
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
|
return 1
|
||||||
|
|
||||||
# implementations
|
# implementations
|
||||||
|
|
Loading…
Reference in New Issue
Block a user