FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Starting pylab or creating new figures steals focus · Issue #8246 · matplotlib/matplotlib · GitHub

Repository navigation

Starting pylab or creating new figures steals focus #8246

Closed

Description

I'm using matplotlib 2.0.0 installed via anaconda with ipython 4.2.0 on mac os x 10.9.5. Since upgrading to matplotlib 2.0.0, whenever I start a matplotlib-enabled session (e.g., ipython --matplotlib) or a new window is created, it steals focus from the OS. I'm using the TkAgg backend, though the same thing happens with Qt5.

This is particularly a problem for some test codes that create a large number of windows while running; I effectively cannot access the OS at all when the tests are running, even the terminal, so I can't kill the thread.

Any suggestions on what might have happened with this latest upgrade? Since this was anaconda-installed, I can't rule out a change in the backends rather than with matplotlib, but I think the relevant expertise is likelier to be here.

Activity

  1. eas342 commented on Jun 14, 2017

    Using the Agg backend seems to stop stealing focus for my python 2.7, Mac OS X 10.10.5. This bug is annoying me too. Unfortunately, Agg is only a bandaid solution.

  2. tacaswell commented on Jun 14, 2017

    Member

    #6384 #6378 and #596

    This was likely intentional, but I am not sure exactly what change caused it.

    For running tests and background tasks using a non-interactive backend is the right thing to do any way (or to not use plt.show + plt.ion()).

  3. added this to the milestone on Aug 13, 2017
  4. added
    API: changesChanges to the public API, typically requiring deprecation.
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    and removed
    API: changesChanges to the public API, typically requiring deprecation.
    on Aug 13, 2017
  5. tacaswell commented on Aug 13, 2017

    Member

    Flagging this a critical to make sure we talk about it.

  6. removed
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Sep 1, 2017
  7. modified the milestones: , on Sep 1, 2017
  8. modified the milestones: , on Sep 24, 2017
  9. StefanD986 commented on Oct 31, 2018

    Edit: Nevermind, I just found the discussion around #12188 which (hopefully) will also fix #8246 in the next release. Fingers crossed.🍀

    Has anyone looked at this? This behaviour is especially annoying if working in a jupyter notebook because after matplotlib stole the focus the user needs to use the mouse to select the notebook to have the focus again before being able to execute the next cell.

    What I found a bit surprising is that even if I select the inline or notebook backend the focus is stolen (although these two backends do not even create a window to plot).

    I am on OSX 10.14,
    Python 3.7
    matplotlib 3.0.0

  10. patnr commented on Jun 25, 2019

    Is there any solution or hack to address this?

    Although bring-to-front is nice, I really want to avoid loosing the focus from the terminal.

    Tested with:

    • Python 3.7
    • matplotlib 3.1.0
    • MacOS 10.12 with backend Qt5Agg
    • Windows 10 with backend TkAgg
    • Windows 10 with backend Qt5Agg

    In the last case, the focus is not stolen for window creation until I've created and closed some figures to begin with.

  11. m-a-r-o-u commented on Nov 28, 2021

    This is still a problem for:

    • OSX Monterey 12.0.1
    • Python 3.9.9
    • Qt5Agg

    At least for ipython --pylab start up

  12. pag commented on Dec 2, 2021

    This was annoying me enough that I tracked it down. It's an IPython thing and nothing to do with matplotlib per se. The cause is that as soon as you start processing events on a QApplication the MacOS dock entry is created and the application is activated. I couldn't find a way to stop the application being immediately activated (or to easily deactivate it once it's first activated), so my fix is to not process any Qt events in the IPython event hook until a window has been created, e.g. a matplotlib figure is shown.

    https://gist.github.com/pag/f7d1ebbd1b14fe9058bf68d73a52bc84

    It's working nicely. The only downside is that people using the IPython/Qt event loop integration for things other than plotting (via %gui qt) might notice the change in behaviour because Qt timers etc won't fire until they create a QWidget somewhere. Realistically I think that's a tiny edge case, but to solve it properly would require %pylab/matplotlib.pyplot to set a flag that %gui qt wouldn't and then make the patch behaviour be conditional on that flag. I don't have time to do that now or shepherd through the resulting PR so I'm including the patch here for what it's worth.

  13. tacaswell commented on Dec 2, 2021

    Member

    The only downside is that people using the IPython/Qt event loop integration for things other than plotting

    I think it is a little worse, if people were sloppy and relied on IPython to create the qapplication from them, the first attempt at creating a a QWidget would abort their process.

    That said, @pag can you open a PR to IPython with that patch (and ping me, I can help review / shepherd it through there). A slightly simpler change may be to only process events if someone else has created a QAppliaction and never have IPython create one. I have in the past had the opposite view on this, but am starting to change my mind.


    This is also rcParams['figure.raise_window']

    #figure.raise_window : True    # Raise the GUI window to front when show() is called.
    

    which will prevent new windows from stealing focus.

  14. pag commented on Dec 3, 2021

    @tacaswell with the patch a QApplication is still created at the moment of GUI loop integration (i.e. the moment that you run %gui qt or %pylab qt) but no events are processed until a top-level QWidget exists, so nothing will crash here that didn't crash before. The dock icon is created at the point of QApplication creation, but it only steals focus when the event loop begins.

  15. tacaswell commented on Dec 6, 2021

    Member

    @pag 🐑 Sorry, I did not read the diff correctly, sorry about that.

    I still think you should consider opening this as a PR to IPython (if you have not done so already and the notification is just lost in my inbox).

  16. choucavalier commented on Feb 1, 2022

    hey! was a PR opened for that in IPython? if so, what's the link?

  17. tacaswell commented on Apr 30, 2022

    Member

    There is at least an issue on the IPython side to track this ipython/ipython#13617

  18. tacaswell commented on Apr 30, 2022

    Member

    I am going to close this because:

    1. the root cause of the recently discussed issue is how IPython manages the Qt event loop integration
    2. we now have an rcparam to control if showing a figure takes focus or not
    3. Further defer backend selection #22005 further defers when we do any GUI framework importing which should also help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL