@@ -1242,13 +1242,18 @@ def _get_key(self, evt):
12421242 keyval = evt .m_keyCode
12431243 if keyval in self .keyvald :
12441244 key = self .keyvald [keyval ]
1245- elif keyval < 256 :
1245+ elif keyval < 256 :
12461246 key = chr (keyval )
1247+ # wx always returns an uppercase, so make it lowercase if the shift
1248+ # key is not depressed (NOTE: this will not handle Caps Lock)
1249+ if not evt .ShiftDown ():
1250+ key = key .lower ()
12471251 else :
12481252 key = None
12491253
1250- # why is wx upcasing this?
1251- if key is not None : key = key .lower ()
1254+ for meth , prefix in ([evt .ControlDown , 'ctrl' ], [evt .AltDown , 'alt' ], ):
1255+ if meth ():
1256+ key = '{}+{}' .format (prefix , key )
12521257
12531258 return key
12541259
@@ -1476,6 +1481,7 @@ def __init__(self, num, fig):
14761481 self .SetStatusBar (statbar )
14771482 self .canvas = self .get_canvas (fig )
14781483 self .canvas .SetInitialSize (wx .Size (fig .bbox .width , fig .bbox .height ))
1484+ self .canvas .SetFocus ()
14791485 self .sizer = wx .BoxSizer (wx .VERTICAL )
14801486 self .sizer .Add (self .canvas , 1 , wx .TOP | wx .LEFT | wx .EXPAND )
14811487 # By adding toolbar in sizer, we are able to put it at the bottom
@@ -1742,8 +1748,6 @@ def updateButtonText(self, lst):
17421748 self .SetLabel ("Axes: %s" % axis_txt [:- 1 ])
17431749
17441750
1745-
1746-
17471751cursord = {
17481752 cursors .MOVE : wx .CURSOR_HAND ,
17491753 cursors .HAND : wx .CURSOR_HAND ,
@@ -1787,57 +1791,33 @@ def _init_toolbar(self):
17871791 DEBUG_MSG ("_init_toolbar" , 1 , self )
17881792
17891793 self ._parent = self .canvas .GetParent ()
1790- _NTB2_HOME = wx .NewId ()
1791- self ._NTB2_BACK = wx .NewId ()
1792- self ._NTB2_FORWARD = wx .NewId ()
1793- self ._NTB2_PAN = wx .NewId ()
1794- self ._NTB2_ZOOM = wx .NewId ()
1795- _NTB2_SAVE = wx .NewId ()
1796- _NTB2_SUBPLOT = wx .NewId ()
1797-
1798- self .SetToolBitmapSize (wx .Size (24 ,24 ))
1799-
1800- self .AddSimpleTool (_NTB2_HOME , _load_bitmap ('home.png' ),
1801- 'Home' , 'Reset original view' )
1802- self .AddSimpleTool (self ._NTB2_BACK , _load_bitmap ('back.png' ),
1803- 'Back' , 'Back navigation view' )
1804- self .AddSimpleTool (self ._NTB2_FORWARD , _load_bitmap ('forward.png' ),
1805- 'Forward' , 'Forward navigation view' )
1806- # todo: get new bitmap
1807- self .AddCheckTool (self ._NTB2_PAN , _load_bitmap ('move.png' ),
1808- shortHelp = 'Pan' ,
1809- longHelp = 'Pan with left, zoom with right' )
1810- self .AddCheckTool (self ._NTB2_ZOOM , _load_bitmap ('zoom_to_rect.png' ),
1811- shortHelp = 'Zoom' , longHelp = 'Zoom to rectangle' )
18121794
1813- self .AddSeparator ()
1814- self .AddSimpleTool (_NTB2_SUBPLOT , _load_bitmap ('subplots.png' ),
1815- 'Configure subplots' , 'Configure subplot parameters' )
18161795
1817- self .AddSimpleTool (_NTB2_SAVE , _load_bitmap ('filesave.png' ),
1818- 'Save' , 'Save plot contents to file' )
1819-
1820- bind (self , wx .EVT_TOOL , self .home , id = _NTB2_HOME )
1821- bind (self , wx .EVT_TOOL , self .forward , id = self ._NTB2_FORWARD )
1822- bind (self , wx .EVT_TOOL , self .back , id = self ._NTB2_BACK )
1823- bind (self , wx .EVT_TOOL , self .zoom , id = self ._NTB2_ZOOM )
1824- bind (self , wx .EVT_TOOL , self .pan , id = self ._NTB2_PAN )
1825- bind (self , wx .EVT_TOOL , self .configure_subplot , id = _NTB2_SUBPLOT )
1826- bind (self , wx .EVT_TOOL , self .save , id = _NTB2_SAVE )
1796+ self .wx_ids = {}
1797+ for text , tooltip_text , image_file , callback in self .toolitems :
1798+ if text is None :
1799+ self .AddSeparator ()
1800+ continue
1801+ self .wx_ids [text ] = wx .NewId ()
1802+ if text in ['Pan' , 'Zoom' ]:
1803+ self .AddCheckTool (self .wx_ids [text ], _load_bitmap (image_file + '.png' ),
1804+ shortHelp = text , longHelp = tooltip_text )
1805+ else :
1806+ self .AddSimpleTool (self .wx_ids [text ], _load_bitmap (image_file + '.png' ),
1807+ text , tooltip_text )
1808+ bind (self , wx .EVT_TOOL , getattr (self , callback ), id = self .wx_ids [text ])
18271809
18281810 self .Realize ()
18291811
1830-
18311812 def zoom (self , * args ):
1832- self .ToggleTool (self ._NTB2_PAN , False )
1813+ self .ToggleTool (self .wx_ids [ 'Pan' ] , False )
18331814 NavigationToolbar2 .zoom (self , * args )
18341815
18351816 def pan (self , * args ):
1836- self .ToggleTool (self ._NTB2_ZOOM , False )
1817+ self .ToggleTool (self .wx_ids [ 'Zoom' ] , False )
18371818 NavigationToolbar2 .pan (self , * args )
18381819
1839-
1840- def configure_subplot (self , evt ):
1820+ def configure_subplots (self , evt ):
18411821 frame = wx .Frame (None , - 1 , "Configure subplots" )
18421822
18431823 toolfig = Figure ((6 ,3 ))
@@ -1855,7 +1835,7 @@ def configure_subplot(self, evt):
18551835 tool = SubplotTool (self .canvas .figure , toolfig )
18561836 frame .Show ()
18571837
1858- def save (self , evt ):
1838+ def save_figure (self , * args ):
18591839 # Fetch the required filename and file type.
18601840 filetypes , exts , filter_index = self .canvas ._get_imagesave_wildcards ()
18611841 default_file = "image." + self .canvas .get_default_filetype ()
@@ -1881,7 +1861,7 @@ def save(self, evt):
18811861 os .path .join (dirname , filename ), format = format )
18821862 except Exception as e :
18831863 error_msg_wx (str (e ))
1884-
1864+
18851865 def set_cursor (self , cursor ):
18861866 cursor = wx .StockCursor (cursord [cursor ])
18871867 self .canvas .SetCursor ( cursor )
@@ -1948,8 +1928,8 @@ def set_message(self, s):
19481928 def set_history_buttons (self ):
19491929 can_backward = (self ._views ._pos > 0 )
19501930 can_forward = (self ._views ._pos < len (self ._views ._elements ) - 1 )
1951- self .EnableTool (self ._NTB2_BACK , can_backward )
1952- self .EnableTool (self ._NTB2_FORWARD , can_forward )
1931+ self .EnableTool (self .wx_ids [ 'Back' ] , can_backward )
1932+ self .EnableTool (self .wx_ids [ 'Forward' ] , can_forward )
19531933
19541934
19551935class NavigationToolbarWx (wx .ToolBar ):
@@ -2149,13 +2129,12 @@ def _onMouseWheel(self, evt):
21492129 direction = - 1
21502130 self .button_fn (direction )
21512131
2152- _onSave = NavigationToolbar2Wx .save
2132+ _onSave = NavigationToolbar2Wx .save_figure
21532133
21542134 def _onClose (self , evt ):
21552135 self .GetParent ().Destroy ()
21562136
21572137
2158-
21592138class StatusBarWx (wx .StatusBar ):
21602139 """
21612140 A status bar is added to _FigureFrame to allow measurements and the
0 commit comments