diff --git a/pygmt/helpers/utils.py b/pygmt/helpers/utils.py index 92f55feb678..749ebe63e5b 100644 --- a/pygmt/helpers/utils.py +++ b/pygmt/helpers/utils.py @@ -1,6 +1,7 @@ """ Utilities and common tasks for wrapping the GMT modules. """ +import os import shutil import subprocess import sys @@ -195,8 +196,9 @@ def launch_external_viewer(fname): """ Open a file in an external viewer program. - Uses the ``xdg-open`` command on Linux, the ``open`` command on macOS, and - the default web browser on other systems. + Uses the ``xdg-open`` command on Linux, the ``open`` command on macOS, the + associated application on Windows, and the default web browser on other + systems. Parameters ---------- @@ -214,8 +216,10 @@ def launch_external_viewer(fname): subprocess.run(["xdg-open", fname], check=False, **run_args) elif os_name == "darwin": # Darwin is macOS subprocess.run(["open", fname], check=False, **run_args) + elif os_name == "win32": + os.startfile(fname) # pylint: disable=no-member else: - webbrowser.open_new_tab("file://{}".format(fname)) + webbrowser.open_new_tab(f"file://{fname}") def args_in_kwargs(args, kwargs):