mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-20 12:14:46 +03:00
Viewer class properties: src/PIL/ImageShow.py, Tests/test_imageshow.py files changed:
- Viewer class format property changed to 'PNG', format property removed from child classes. - Viewer class options property changed to {"compress_level": 1}, format property removed from child classes. - IPythonViewer format option set to None, IPythonViewer options set to {}. - Corresponding test Tests/test_imageshow.py::test_viewer changed to meet the changes mentioned above.
This commit is contained in:
parent
71839a7623
commit
b348881de4
|
@ -54,7 +54,7 @@ def test_show():
|
||||||
def test_viewer():
|
def test_viewer():
|
||||||
viewer = ImageShow.Viewer()
|
viewer = ImageShow.Viewer()
|
||||||
|
|
||||||
assert viewer.get_format(None) is None
|
assert viewer.get_format(None) == "PNG"
|
||||||
|
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
viewer.get_command(None)
|
viewer.get_command(None)
|
||||||
|
|
|
@ -61,6 +61,11 @@ def show(image, title=None, **options):
|
||||||
class Viewer:
|
class Viewer:
|
||||||
"""Base class for viewers."""
|
"""Base class for viewers."""
|
||||||
|
|
||||||
|
format = "PNG"
|
||||||
|
"""The format to convert the image into."""
|
||||||
|
options = {"compress_level": 1}
|
||||||
|
"""Additional options used to convert the image."""
|
||||||
|
|
||||||
# main api
|
# main api
|
||||||
|
|
||||||
def show(self, image, **options):
|
def show(self, image, **options):
|
||||||
|
@ -81,11 +86,6 @@ class Viewer:
|
||||||
|
|
||||||
# hook methods
|
# hook methods
|
||||||
|
|
||||||
format = None
|
|
||||||
"""The format to convert the image into."""
|
|
||||||
options = {}
|
|
||||||
"""Additional options used to convert the image."""
|
|
||||||
|
|
||||||
def get_format(self, image):
|
def get_format(self, image):
|
||||||
"""Return format name, or ``None`` to save as PGM/PPM."""
|
"""Return format name, or ``None`` to save as PGM/PPM."""
|
||||||
return self.format
|
return self.format
|
||||||
|
@ -143,9 +143,6 @@ class Viewer:
|
||||||
class WindowsViewer(Viewer):
|
class WindowsViewer(Viewer):
|
||||||
"""The default viewer on Windows is the default system application for PNG files."""
|
"""The default viewer on Windows is the default system application for PNG files."""
|
||||||
|
|
||||||
format = "PNG"
|
|
||||||
options = {"compress_level": 1}
|
|
||||||
|
|
||||||
def get_command(self, file, **options):
|
def get_command(self, file, **options):
|
||||||
return (
|
return (
|
||||||
f'start "Pillow" /WAIT "{file}" '
|
f'start "Pillow" /WAIT "{file}" '
|
||||||
|
@ -161,9 +158,6 @@ if sys.platform == "win32":
|
||||||
class MacViewer(Viewer):
|
class MacViewer(Viewer):
|
||||||
"""The default viewer on macOS using ``Preview.app``."""
|
"""The default viewer on macOS using ``Preview.app``."""
|
||||||
|
|
||||||
format = "PNG"
|
|
||||||
options = {"compress_level": 1}
|
|
||||||
|
|
||||||
def get_command(self, file, **options):
|
def get_command(self, file, **options):
|
||||||
# on darwin open returns immediately resulting in the temp
|
# on darwin open returns immediately resulting in the temp
|
||||||
# file removal while app is opening
|
# file removal while app is opening
|
||||||
|
@ -199,9 +193,6 @@ if sys.platform == "darwin":
|
||||||
|
|
||||||
|
|
||||||
class UnixViewer(Viewer):
|
class UnixViewer(Viewer):
|
||||||
format = "PNG"
|
|
||||||
options = {"compress_level": 1}
|
|
||||||
|
|
||||||
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)}; rm -f {quote(file)})&"
|
||||||
|
@ -395,6 +386,9 @@ if sys.platform not in ("win32", "darwin"): # unixoids
|
||||||
class IPythonViewer(Viewer):
|
class IPythonViewer(Viewer):
|
||||||
"""The viewer for IPython frontends."""
|
"""The viewer for IPython frontends."""
|
||||||
|
|
||||||
|
format = None
|
||||||
|
options = {}
|
||||||
|
|
||||||
def show_image(self, image, **options):
|
def show_image(self, image, **options):
|
||||||
ipython_display(image)
|
ipython_display(image)
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user