@@ -1242,13 +1242,18 @@ def _get_key(self, evt):
1242
1242
keyval = evt .m_keyCode
1243
1243
if keyval in self .keyvald :
1244
1244
key = self .keyvald [keyval ]
1245
- elif keyval < 256 :
1245
+ elif keyval < 256 :
1246
1246
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 ()
1247
1251
else :
1248
1252
key = None
1249
1253
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 )
1252
1257
1253
1258
return key
1254
1259
@@ -1476,6 +1481,7 @@ def __init__(self, num, fig):
1476
1481
self .SetStatusBar (statbar )
1477
1482
self .canvas = self .get_canvas (fig )
1478
1483
self .canvas .SetInitialSize (wx .Size (fig .bbox .width , fig .bbox .height ))
1484
+ self .canvas .SetFocus ()
1479
1485
self .sizer = wx .BoxSizer (wx .VERTICAL )
1480
1486
self .sizer .Add (self .canvas , 1 , wx .TOP | wx .LEFT | wx .EXPAND )
1481
1487
# By adding toolbar in sizer, we are able to put it at the bottom
@@ -1742,8 +1748,6 @@ def updateButtonText(self, lst):
1742
1748
self .SetLabel ("Axes: %s" % axis_txt [:- 1 ])
1743
1749
1744
1750
1745
-
1746
-
1747
1751
cursord = {
1748
1752
cursors .MOVE : wx .CURSOR_HAND ,
1749
1753
cursors .HAND : wx .CURSOR_HAND ,
@@ -1787,57 +1791,33 @@ def _init_toolbar(self):
1787
1791
DEBUG_MSG ("_init_toolbar" , 1 , self )
1788
1792
1789
1793
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' )
1812
1794
1813
- self .AddSeparator ()
1814
- self .AddSimpleTool (_NTB2_SUBPLOT , _load_bitmap ('subplots.png' ),
1815
- 'Configure subplots' , 'Configure subplot parameters' )
1816
1795
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 ])
1827
1809
1828
1810
self .Realize ()
1829
1811
1830
-
1831
1812
def zoom (self , * args ):
1832
- self .ToggleTool (self ._NTB2_PAN , False )
1813
+ self .ToggleTool (self .wx_ids [ 'Pan' ] , False )
1833
1814
NavigationToolbar2 .zoom (self , * args )
1834
1815
1835
1816
def pan (self , * args ):
1836
- self .ToggleTool (self ._NTB2_ZOOM , False )
1817
+ self .ToggleTool (self .wx_ids [ 'Zoom' ] , False )
1837
1818
NavigationToolbar2 .pan (self , * args )
1838
1819
1839
-
1840
- def configure_subplot (self , evt ):
1820
+ def configure_subplots (self , evt ):
1841
1821
frame = wx .Frame (None , - 1 , "Configure subplots" )
1842
1822
1843
1823
toolfig = Figure ((6 ,3 ))
@@ -1855,7 +1835,7 @@ def configure_subplot(self, evt):
1855
1835
tool = SubplotTool (self .canvas .figure , toolfig )
1856
1836
frame .Show ()
1857
1837
1858
- def save (self , evt ):
1838
+ def save_figure (self , * args ):
1859
1839
# Fetch the required filename and file type.
1860
1840
filetypes , exts , filter_index = self .canvas ._get_imagesave_wildcards ()
1861
1841
default_file = "image." + self .canvas .get_default_filetype ()
@@ -1881,7 +1861,7 @@ def save(self, evt):
1881
1861
os .path .join (dirname , filename ), format = format )
1882
1862
except Exception as e :
1883
1863
error_msg_wx (str (e ))
1884
-
1864
+
1885
1865
def set_cursor (self , cursor ):
1886
1866
cursor = wx .StockCursor (cursord [cursor ])
1887
1867
self .canvas .SetCursor ( cursor )
@@ -1948,8 +1928,8 @@ def set_message(self, s):
1948
1928
def set_history_buttons (self ):
1949
1929
can_backward = (self ._views ._pos > 0 )
1950
1930
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 )
1953
1933
1954
1934
1955
1935
class NavigationToolbarWx (wx .ToolBar ):
@@ -2149,13 +2129,12 @@ def _onMouseWheel(self, evt):
2149
2129
direction = - 1
2150
2130
self .button_fn (direction )
2151
2131
2152
- _onSave = NavigationToolbar2Wx .save
2132
+ _onSave = NavigationToolbar2Wx .save_figure
2153
2133
2154
2134
def _onClose (self , evt ):
2155
2135
self .GetParent ().Destroy ()
2156
2136
2157
2137
2158
-
2159
2138
class StatusBarWx (wx .StatusBar ):
2160
2139
"""
2161
2140
A status bar is added to _FigureFrame to allow measurements and the
0 commit comments