-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Use rcParams to control default "raise window" behavior (Qt,Gtk,Tk,Wx) #15440
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
Use rcParams to control default "raise window" behavior (Qt,Gtk,Tk,Wx) #15440
Conversation
Struggled with the Gtk3 a bit & now find the right way of doing it, so simple. 😳 |
Also tested on Windows7, working as expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good apart from the what's new message 👍.
Could you sqash your commits if possible? - Otherwise we'll do it before merging.
A new rcParms entry have been added: with the ``figure.raise_window`` option | ||
now it is possible to disable the default "raise GUI window" behavior when | ||
calling ``plt.show`` or ``plt.pause`` methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new config option
rcParams['figure.raise_window']
allows to disable
raising the plot window when callingplt.show
orplt.pause
methods.
Should be sufficient and more straight forward.
… (Qt,Gtk,Tk,Wx) A new rcParms entry have been added: "figure.raise_window" Now it is possible to disable the default "raise GUI window" behavior This change apply to & tested on Qt, Gtk, Tk and Wx backends (CentOS7 & Win7) Has document it in the 'whats new' section
5e76728
to
1b4c4ad
Compare
Great thanks for the help on the message, i'm not a native speaker. 😂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase is correct 👍
What do you mean by: Qt4 "raise window" pop-out "Figure is ready", have to click the notification manually.
@@ -411,7 +411,9 @@ def destroy(self, *args): | |||
def show(self): | |||
# show the figure window | |||
self.window.show() | |||
self.window.present() | |||
self.canvas.draw() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does GTK3 need a draw now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I am testing with Gtk3 and turn off the "raise window", I encountered a strange behavior, that the GUI window is reluctant to update, and the whole program get stuck, loop is not running, until I move/switch the GUI window or moving my mouse cursor on the canvas, it can continue to run/update.
After debug and tracing, I found the program is stuck inside the Gtk.main_iteration()
here:
def flush_events(self):
# docstring inherited
Gdk.threads_enter()
while Gtk.events_pending():
Gtk.main_iteration()
Gdk.flush()
Gdk.threads_leave()
By looking into the doc, it says if there is no event queued, main_iteration
will block until the next event is noticed, but that's very strange since we have already checked with events_pending
, if there is no event it should not go into the while-loop. Nevertheless, I changed using Gtk.gtk_main_iteration_do(False)
which the doc states that it won't block, however, that's not working, the program still get stuck inside gtk_main_iteration_do
. Finally, I come up with a solution: to call window.queue_draw()
right after window.show()
and successfully I don't have to waving my mouse cursor over the canvas any more. And I found that this is exactly what canvas.draw()
is doing, and the same approach is also used in the backend_wx.py
, so I suppose this is the right way to do it? I am not familiar with the GUI stuff so I have no idea what's happening, please feel free to correct me.
This is the full report, HaHa!! Thank you so much for your patience reading this mumbo jumbo!! 😜
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you test with draw_idle
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested, won't update, need stick to draw
So instead of the window, a "Figure 1 is ready" message is popping to the front? |
Yes! and it is exactly the one shown in the top-right corner of my attached image. |
Hm, I don't find any related "... is ready" text in our code base. So who is generating that message? You are seeing this only in Qt4, not Qt5, and you are on master? |
The message is triggered by your window manager, which isn't allowing focus stealing. |
Given that Qt4 is end of life and major distributions are defaulting to Qt5, I wouldn‘t wollt too much if we can‘t get this fixed for Qt4. |
Sure, so is there anything else I need to do? |
I don‘t think so. I still want to take a closer look at the GTK redraw. |
OK, thanks! |
In general this looks nice. |
This looks very helpful (based on a quick scan). One thought occurs to me: would it make sense to have this controlled by an optional keyword argument to plt.show? That way it could be controlled locally instead of only globally. It would require adding the keyword argument to the intermediate Figure.show and each Backend.show as well. I think the setting of the default by rcParam could stay in the backends. |
Thanks for the advice, seems reasonable to me. But they could be discussed & handled in separated issue & PR, IMHO. |
Any update on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should get this in ASAP. I don't see how it can do any real harm, and it is an important feature requiring minimal code.
I think the whatsnew should at least mention that this doesn't work on the macos backend (which is fine); clarifying (as above) the interaction with the tk.window_focus rc would be nice as well. |
@anntzer Good points. If this goes in, will you want to support the rcParam in your mplcairo backend? |
I haven't actually checked, but I'm almost certain mplcairo will work just fine with it because it just inherits the show() methods from the various backend-dependent but renderer-independent base classes (similarly, you can see that here the changes are in qt5.py wx.py etc. and not qt5agg.py/qt5cairo.py wxagg.py/wxcairo.py etc.). |
I think this functionality is not exactly identical to the rcParams["tk.window_focus"]. |
Add this to whatsnew?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conditional on adding a note about OSX not being supported (or explicitly listing the backends that are supported).
done~ |
Thanks @immaxchen |
Is there a fix for OSX? |
Hello, changing rcParams figure.raise_window keyword to False gives inconsistent behavior. Here's a simple example:
When I run the example code in Spyder, the initial run works as intended: the new plot window does not "rise above" the console window. However, subsequent runs of the same code do not behave the same way: the new plot window still rises above the console window, even when the keyword is set to False. Moreover, running the code in the command prompt also does not produce the desired effect: the new plot window always rises above the command prompt window. I am using Windows 10, Python 3.7.6, Matplotlib 3.4.2, and Spyder 5.0.0 I am commenting here in hopes that the original developer(s) of this feature can see this. Thanks. |
PR Summary
Address Issue #8692
A new rcParms entry have been added: "figure.raise_window"
Now it is possible to disable the default "raise GUI window" behavior
This change apply to & tested on Qt4, Qt5, Gtk3, Tk and Wx backends (OS: CentOS7, Win7)
Has document it in the 'whats new' section
Known Issue:
Gtk3 have to use a small trick to force the screen update, better solutions welcomeQt4 "raise window" pop-out "Figure is ready", have to click the notification manually
Side Note:
Wx backend didn't implement the "raise window" behavior before
Don't have a Mac to work on macosx backend
Manually tested with the attached python script
test_raise_window.txt
PR Checklist