Skip to content

Commit 01e267c

Browse files
authored
Merge pull request #15440 from immaxchen/add-rcparams-to-control-raise-window-behavior-gh8692
Use rcParams to control default "raise window" behavior (Qt,Gtk,Tk,Wx)
2 parents d65af21 + 1c35ef0 commit 01e267c

File tree

8 files changed

+23
-7
lines changed

8 files changed

+23
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:orphan:
2+
3+
rcParams for controlling default "raise window" behavior
4+
--------------------------------------------------------
5+
The new config option ``rcParams['figure.raise_window']`` allows to disable
6+
raising the plot window when calling ``plt.show`` or ``plt.pause`` methods.
7+
``MacOSX`` backend is currently not supported.
8+

lib/matplotlib/backends/_backend_tk.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,9 @@ def destroy(*args):
475475
self.window.deiconify()
476476
else:
477477
self.canvas.draw_idle()
478-
# Raise the new window.
479-
self.canvas.manager.window.attributes('-topmost', 1)
480-
self.canvas.manager.window.attributes('-topmost', 0)
478+
if matplotlib.rcParams['figure.raise_window']:
479+
self.canvas.manager.window.attributes('-topmost', 1)
480+
self.canvas.manager.window.attributes('-topmost', 0)
481481
self._shown = True
482482

483483
def destroy(self, *args):

lib/matplotlib/backends/backend_gtk3.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ def destroy(self, *args):
409409
def show(self):
410410
# show the figure window
411411
self.window.show()
412-
self.window.present()
412+
self.canvas.draw()
413+
if matplotlib.rcParams['figure.raise_window']:
414+
self.window.present()
413415

414416
def full_screen_toggle(self):
415417
self._full_screen_flag = not self._full_screen_flag

lib/matplotlib/backends/backend_qt5.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,9 @@ def resize(self, width, height):
637637

638638
def show(self):
639639
self.window.show()
640-
self.window.activateWindow()
641-
self.window.raise_()
640+
if matplotlib.rcParams['figure.raise_window']:
641+
self.window.activateWindow()
642+
self.window.raise_()
642643

643644
def destroy(self, *args):
644645
# check for qApp first, as PySide deletes it in its atexit handler

lib/matplotlib/backends/backend_wx.py

+2
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,8 @@ def __init__(self, canvas, num, frame):
10821082
def show(self):
10831083
self.frame.Show()
10841084
self.canvas.draw()
1085+
if matplotlib.rcParams['figure.raise_window']:
1086+
self.frame.Raise()
10851087

10861088
def destroy(self, *args):
10871089
_log.debug("%s - destroy()", type(self))

lib/matplotlib/rcsetup.py

+1
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ def validate_webagg_address(s):
13391339
'figure.frameon': [True, validate_bool],
13401340
'figure.autolayout': [False, validate_bool],
13411341
'figure.max_open_warning': [20, validate_int],
1342+
'figure.raise_window': [True, validate_bool],
13421343

13431344
'figure.subplot.left': [0.125, _range_validators["0 <= x <= 1"]],
13441345
'figure.subplot.right': [0.9, _range_validators["0 <= x <= 1"]],

lib/matplotlib/style/core.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
'interactive', 'backend', 'backend.qt4', 'webagg.port', 'webagg.address',
3939
'webagg.port_retries', 'webagg.open_in_browser', 'backend_fallback',
4040
'toolbar', 'timezone', 'datapath', 'figure.max_open_warning',
41-
'savefig.directory', 'tk.window_focus', 'docstring.hardcopy'}
41+
'figure.raise_window', 'savefig.directory', 'tk.window_focus',
42+
'docstring.hardcopy'}
4243

4344

4445
def _remove_blacklisted_style_params(d, warn=True):

matplotlibrc.template

+1
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@
538538
#figure.max_open_warning : 20 ## The maximum number of figures to open through
539539
## the pyplot interface before emitting a warning.
540540
## If less than one this feature is disabled.
541+
#figure.raise_window : True ## Raise the GUI window to front when show() is called
541542

542543
## The figure subplot parameters. All dimensions are a fraction of the figure width and height.
543544
#figure.subplot.left : 0.125 ## the left side of the subplots of the figure

0 commit comments

Comments
 (0)