Skip to content

Commit

Permalink
pygmt.set_display: Fix a bug when setting method=None, add type hin…
Browse files Browse the repository at this point in the history
…ts and refactor
  • Loading branch information
seisman committed Aug 13, 2024
1 parent 2409284 commit 6bd742e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,22 +568,20 @@ def _repr_html_(self):
)


def set_display(method=None):
def set_display(method: Literal["external", "notebook", "none", None] = None):
"""
Set the display method when calling :meth:`pygmt.Figure.show`.
Parameters
----------
method : str or None
method
The method to display an image preview. Choose from:
- ``"external"``: External PDF preview using the default PDF viewer
- ``"notebook"``: Inline PNG preview in the current notebook
- ``"none"``: Disable image preview
- ``None``: Reset to the default display method
The default display method is ``"external"`` in Python consoles or
``"notebook"`` in Jupyter notebooks.
- ``None``: Reset to the default display method, which is either ``"external"``
in Python consoles or ``"notebook"`` in Jupyter notebooks.
Examples
--------
Expand All @@ -606,10 +604,13 @@ def set_display(method=None):
>>> pygmt.set_display(method=None)
>>> fig.show() # again, will show a PNG image in the current notebook
"""
if method in {"notebook", "external", "none"}:
SHOW_CONFIG["method"] = method
elif method is not None:
raise GMTInvalidInput(
f"Invalid display mode '{method}', "
"should be either 'notebook', 'external', 'none' or None."
)
match method:
case "external" | "notebook" | "none":
SHOW_CONFIG["method"] = method
case None:
SHOW_CONFIG["method"] = _get_default_display_method()
case _:
raise GMTInvalidInput(
f"Invalid display method '{method}'. Valid values are 'external',"
"'notebook', 'none' or None."
)

0 comments on commit 6bd742e

Please sign in to comment.