Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open figures using the associated application on Windows #952

Merged
merged 2 commits into from
Feb 23, 2021

Conversation

seisman
Copy link
Member

@seisman seisman commented Feb 22, 2021

Description of proposed changes

This PR improves the launch_external_viewer function to open images
using the associated application (just like double-click the images) on
Windows.

The implementation is done by calling the
os.startfile function.

os.startfile is only available on Windows, so need to disable the pylint
error no-member.

The code was originally written in #528 by @leouieda, re-used in #529,
but I'd like to open this PR separately so that changes in #529 can be
smaller.

BTW, the function is not tested at all because we can't open GUI programs
in CI machines.

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

This PR improves the `launch_external_viewer` function to open images
using the associated application (just like double-click the images) on
Windows.

The implemention is done by calling the
[`os.startfile`](https://docs.python.org/3/library/os.html#os.startfile)
function.

`os.startfile` is only available on Windows, so need to disable the pylint
error `no-member`.

The code was originall written in #269 by @leouieda, re-used in #529.
@seisman seisman added the enhancement Improving an existing feature label Feb 22, 2021
@seisman seisman added this to the 0.3.1 milestone Feb 22, 2021
@seisman seisman marked this pull request as ready for review February 22, 2021 06:30
Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should get a Windows user to test this (or login to Windows myself), but I think os.startfile should work.

@weiji14 weiji14 changed the title Open images using the associated application on Windows Open figures using the associated application on Windows Feb 22, 2021
@seisman
Copy link
Member Author

seisman commented Feb 22, 2021

Do we have any Windows developers who can try it? @GenericMappingTools/python @GenericMappingTools/python-maintainers

Just to make it clear, when Windows users run the following codes in a Python (or IPython) console:

import pygmt
fig = pygmt.Figure()
fig.basemap(projection="X10c", region=[0, 10, 0, 10], frame=True)
fig.show(method="external")

the old behavior (using the master branch) is opening the figure in a web browser, the new behavior (using this branch) is opening the figure using the default image viewer.

@seisman seisman merged commit 30befaf into master Feb 23, 2021
@seisman seisman deleted the improve-launch_external_viewer branch February 23, 2021 20:23
@seisman seisman added bug Something isn't working and removed enhancement Improving an existing feature labels Feb 24, 2021
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
…ingTools#952)

This PR improves the `launch_external_viewer` function to open images
using the associated application (just like double-click the images) on
Windows.

The implemention is done by calling the
[`os.startfile`](https://docs.python.org/3/library/os.html#os.startfile)
function.

`os.startfile` is only available on Windows, so need to disable the pylint
error `no-member`.

The code was originall written in GenericMappingTools#269 by @leouieda, re-used in GenericMappingTools#529.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants