@@ -898,37 +898,25 @@ def __init__(self, num, fig, *, canvas_class=None):
898
898
"required after the deprecation period starting in Matplotlib "
899
899
"%(since)s elapses." )
900
900
self .canvas = self .get_canvas (fig )
901
- w , h = map (math .ceil , fig .bbox .size )
902
- self .canvas .SetInitialSize (wx .Size (w , h ))
903
- self .canvas .SetFocus ()
904
- self .sizer = wx .BoxSizer (wx .VERTICAL )
905
- self .sizer .Add (self .canvas , 1 , wx .TOP | wx .LEFT | wx .EXPAND )
906
- # By adding toolbar in sizer, we are able to put it at the bottom
907
- # of the frame - so appearance is closer to GTK version
908
901
909
902
self .figmgr = FigureManagerWx (self .canvas , num , self )
910
903
911
904
self .toolbar = self ._get_toolbar ()
912
-
913
905
if self .figmgr .toolmanager :
914
906
backend_tools .add_tools_to_manager (self .figmgr .toolmanager )
915
907
if self .toolbar :
916
908
backend_tools .add_tools_to_container (self .toolbar )
917
-
918
909
if self .toolbar is not None :
919
- self .toolbar .Realize ()
920
- # On Windows platform, default window size is incorrect, so set
921
- # toolbar width to figure width.
922
- tw , th = self .toolbar .GetSize ()
923
- fw , fh = self .canvas .GetSize ()
924
- # By adding toolbar in sizer, we are able to put it at the bottom
925
- # of the frame - so appearance is closer to GTK version.
926
- self .toolbar .SetSize (wx .Size (fw , th ))
927
- self .sizer .Add (self .toolbar , 0 , wx .LEFT | wx .EXPAND )
928
- self .SetSizer (self .sizer )
929
- self .Fit ()
910
+ self .SetToolBar (self .toolbar )
930
911
912
+ # On Windows, canvas sizing must occur after toolbar addition;
913
+ # otherwise the toolbar further resizes the canvas.
914
+ w , h = map (math .ceil , fig .bbox .size )
915
+ self .canvas .SetInitialSize (wx .Size (w , h ))
931
916
self .canvas .SetMinSize ((2 , 2 ))
917
+ self .canvas .SetFocus ()
918
+
919
+ self .Fit ()
932
920
933
921
self .Bind (wx .EVT_CLOSE , self ._on_close )
934
922
@@ -966,10 +954,6 @@ def _on_close(self, event):
966
954
# Carry on with close event propagation, frame & children destruction
967
955
event .Skip ()
968
956
969
- def GetToolBar (self ):
970
- """Override wxFrame::GetToolBar as we don't have managed toolbar"""
971
- return self .toolbar
972
-
973
957
def Destroy (self , * args , ** kwargs ):
974
958
try :
975
959
self .canvas .mpl_disconnect (self .toolbar ._id_drag )
@@ -1049,9 +1033,9 @@ def set_window_title(self, title):
1049
1033
1050
1034
def resize (self , width , height ):
1051
1035
# docstring inherited
1052
- self . canvas . SetInitialSize (
1053
- wx . Size ( math . ceil ( width ), math . ceil ( height )))
1054
- self . window . GetSizer (). Fit ( self . window )
1036
+ # Directly using SetClientSize doesn't handle the toolbar on Windows.
1037
+ self . window . SetSize ( self . window . ClientToWindowSize ( wx . Size (
1038
+ math . ceil ( width ), math . ceil ( height ))) )
1055
1039
1056
1040
1057
1041
def _load_bitmap (filename ):
@@ -1073,8 +1057,8 @@ def _set_frame_icon(frame):
1073
1057
1074
1058
1075
1059
class NavigationToolbar2Wx (NavigationToolbar2 , wx .ToolBar ):
1076
- def __init__ (self , canvas , coordinates = True ):
1077
- wx .ToolBar .__init__ (self , canvas .GetParent (), - 1 )
1060
+ def __init__ (self , canvas , coordinates = True , * , style = wx . TB_BOTTOM ):
1061
+ wx .ToolBar .__init__ (self , canvas .GetParent (), - 1 , style = style )
1078
1062
1079
1063
if 'wxMac' in wx .PlatformInfo :
1080
1064
self .SetToolBitmapSize ((24 , 24 ))
@@ -1202,7 +1186,7 @@ def set_history_buttons(self):
1202
1186
# tools for matplotlib.backend_managers.ToolManager:
1203
1187
1204
1188
class ToolbarWx (ToolContainerBase , wx .ToolBar ):
1205
- def __init__ (self , toolmanager , parent , style = wx .TB_HORIZONTAL ):
1189
+ def __init__ (self , toolmanager , parent , style = wx .TB_BOTTOM ):
1206
1190
ToolContainerBase .__init__ (self , toolmanager )
1207
1191
wx .ToolBar .__init__ (self , parent , - 1 , style = style )
1208
1192
self ._space = self .AddStretchableSpace ()
0 commit comments