Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Importing pyplot steals focus on macOS #12724

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

Closed
asmeurer opened this issue Nov 2, 2018 · 3 comments
Closed

Importing pyplot steals focus on macOS #12724

asmeurer opened this issue Nov 2, 2018 · 3 comments

Comments

@asmeurer
Copy link

asmeurer commented Nov 2, 2018

Bug report

Bug summary

I really don't know if this is a but with the conda python.app package or with matplotlib.

When you run python.app/pythonw on Mac OS X and import pyplot, it launches the python.app app to the foreground, which steals the keyboard focus from the terminal. You can also reproduce this in IPython, which uses python.app (at least the conda version does).

Obviously I want any plot calls to call the plot to the foreground, but that it does this simply by importing pyplot is quite annoying (for instance, it often does it when I am running some tests).

Weirdly, I tried debugging the import with pudb, and it seems the app gets launched when the close function is defined

def close(fig=None):
. That doesn't make any sense to me, but it does it consistently.

Also weirdly, when I tried to reproduce the bug with the git version, it didn't reproduce, even when I used the v3.0.0 version tag. My only guess is that somehow things compiled differently for me than they did for the conda package.

Code for reproduction

On macOS, run

pythonw

then run

import matplotlib.pyplot

Actual outcome

The python.app launches and steals the keyboard focus.

Expected outcome

Either the app doesn't launch until a plot or show call is made, or it launches in the background (but an actual show call should launch it to the foreground and steal focus).

Matplotlib version

  • Operating system: macOS 10.12.6 (I also reproduced on Mojave)
  • Matplotlib version: 3.0.0 (conda-forge)
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.5
  • Jupyter version (if applicable):
  • Other libraries:

The conda-forge python.app.

@dstansby
Copy link
Member

dstansby commented Nov 5, 2018

I can confirm this on the current master branch, using the macosx backend. I suspect it will be non-trivial to solve, but thanks for reporting!

@dstansby
Copy link
Member

dstansby commented Nov 5, 2018

Actually, I have just properly updated my installation of Matplotlib, and the issue seems to be fixed for me, so I suspect #12603 fixed it. Upgrading to version 3.0.1 should fix it - if it doesn't leave a comment here and we can re-open the bug 😄

@dstansby dstansby closed this as completed Nov 5, 2018
@dstansby dstansby added this to the v3.0.x milestone Nov 5, 2018
@asmeurer
Copy link
Author

asmeurer commented Nov 5, 2018

Great. It does seem to be fixed in 3.0.1. I'll report back if it happens again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants