8000 added a quit shortcut key for gui backends and fixed "toggle full scr… · matplotlib/matplotlib@ed4d338 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed4d338

Browse files
Phil Elsonpelson
Phil Elson
authored andcommitted
added a quit shortcut key for gui backends and fixed "toggle full screen" shortcut key which was broken.
1 parent 5970bde commit ed4d338

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,9 +2274,6 @@ def key_press_handler(event, canvas, toolbar=None):
22742274
22752275
"""
22762276
# these bindings happen whether you are over an axes or not
2277-
#if event.key == 'q':
2278-
# self.destroy() # how cruel to have to destroy oneself!
2279-
# return
22802277

22812278
if event.key is None:
22822279
return
@@ -2289,6 +2286,7 @@ def key_press_handler(event, canvas, toolbar=None):
22892286
pan_keys = rcParams['keymap.pan']
22902287
zoom_keys = rcParams['keymap.zoom']
22912288
save_keys = rcParams['keymap.save']
2289+
quit_keys = rcParams['keymap.quit']
22922290
grid_keys = rcParams['keymap.grid']
22932291
toggle_yscale_keys = rcParams['keymap.yscale']
22942292
toggle_xscale_keys = rcParams['keymap.xscale']
@@ -2298,6 +2296,10 @@ def key_press_handler(event, canvas, toolbar=None):
22982296
if event.key in fullscreen_keys:
22992297
canvas.manager.full_screen_toggle()
23002298

2299+
# quit the figure (defaut key 'q')
2300+
if event.key in quit_keys:
2301+
Gcf.destroy_fig(canvas.figure)
2302+
23012303
if toolbar is not None:
23022304
# home or reset mnemonic (default key 'h', 'home' and 'r')
23032305
if event.key in home_keys:
@@ -2322,7 +2324,8 @@ def key_press_handler(event, canvas, toolbar=None):
23222324
if event.inaxes is None:
23232325
return
23242326

2325-
# the mouse has to be over an axes to trigger these
2327+
# these bindings require the mouse to be over an axes to trigger
2328+
23262329
# switching on/off a grid in current axes (default key 'g')
23272330
if event.key in grid_keys:
23282331
event.inaxes.grid()
@@ -2387,7 +2390,7 @@ def __init__(self, canvas, num):
23872390
def destroy(self):
23882391
pass
23892392

2390-
def full_screen_toggle (self):
2393+
def full_screen_toggle(self):
23912394
pass
23922395

23932396
def resize(self, w, h):

lib/matplotlib/backends/backend_gtk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def show(self):
592592
# show the figure window
593593
self.window.show()
594594

595-
def full_screen_toggle (self):
595+
def full_screen_toggle(self):
596596
self._full_screen_flag = not self._full_screen_flag
597597
if self._full_screen_flag:
598598
self.window.fullscreen()

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def __init__(self, canvas, num, window):
457457
self.window.wm_title("Figure %d" % num)
458458
self.canvas = canvas
459459
self._num = num
460-
t1,t2,w,h = canvas.figure.bbox.bounds
460+
_, _, w, h = canvas.figure.bbox.bounds
461461
w, h = int(w), int(h)
462462
self.window.minsize(int(w*3/4),int(h*3/4))
463463
if matplotlib.rcParams['toolbar']=='classic':
< 8000 div class="diff-text-inner color-fg-muted">@@ -476,12 +476,9 @@ def notify_axes_change(fig):
476476
if self.toolbar != None: self.toolbar.update()
477477
self.canvas.figure.add_axobserver(notify_axes_change)
478478

479-
480-
481479
# attach a show method to the figure for pylab ease of use
482480
self.canvas.figure.show = lambda *args: self.show()
483481

484-
485482
def resize(self, width, height=None):
486483
# before 09-12-22, the resize method takes a single *event*
487484
# parameter. On the other hand, the resize method of other
@@ -499,7 +496,6 @@ def resize(self, width, height=None):
499496

500497
self.toolbar.configure(width=width)
501498

502-
503499
def show(self):
504500
"""
505501
this function doesn't segfault but causes the
@@ -518,7 +514,6 @@ def destroy(*args):
518514
self.canvas.draw_idle()
519515
self._shown = True
520516

521-
522517
def destroy(self, *args):
523518
if self.window is not None:
524519
#self.toolbar.destroy()
@@ -533,6 +528,12 @@ def destroy(self, *args):
533528
def set_window_title(self, title):
534529
self.window.wm_title(title)
535530

531+
def full_screen_toggle(self):
532+
# cross platform way of maximizing a tk window
533+
# http://devourer09.blogspot.co.uk/2009/07/maximizing-tkinter-app.html
534+
self.window.attributes('-zoomed', '1')
535+
536+
536537
class AxisMenu:
537538
def __init__(self, master, naxes):
538539
self._master = master
@@ -597,7 +598,7 @@ def select_all(self):
597598

598599
class NavigationToolbar(Tk.Frame):
599600
"""
600-
Public attriubutes
601+
Public attributes
601602
602603
canvas - the FigureCanvas (gtk.DrawingArea)
603604
win - the gtk.Window
@@ -722,7 +723,7 @@ def update(self):
722723

723724
class NavigationToolbar2TkAgg(NavigationToolbar2, Tk.Frame):
724725
"""
725-
Public attriubutes
726+
Public attributes
726727
727728
canvas - the FigureCanvas (gtk.DrawingArea)
728729
win - the gtk.Window

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ def __call__(self, s):
582582
'keymap.pan' : ['p', validate_stringlist],
583583
'keymap.zoom' : ['o', validate_stringlist],
584584
'keymap.save' : ['s', validate_stringlist],
585+
'keymap.quit' : ['q', validate_stringlist],
585586
'keymap.grid' : ['g', validate_stringlist],
586587
'keymap.yscale' : ['l', validate_stringlist],
587588
'keymap.xscale' : [['k', 'L'], validate_stringlist],

matplotlibrc.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
410410
#keymap.pan : p # pan mnemonic
411411
#keymap.zoom : o # zoom mnemonic
412412
#keymap.save : s # saving current figure
413+
#keymap.quit : q # close the current figure
413414
#keymap.grid : g # switching on/off a grid in current axes
414415
#keymap.yscale : l # toggle scaling of y-axes ('log'/'linear')
415416
#keymap.xscale : L, k # toggle scaling of x-axes ('log'/'linear')

0 commit comments

Comments
 (0)
0