@@ -901,13 +901,9 @@ def __init__(self, num, fig, *, canvas_class=None):
901901
902902 self .figmgr = FigureManagerWx (self .canvas , num , self )
903903
904- self .toolbar = self ._get_toolbar ()
905- if self .figmgr .toolmanager :
906- backend_tools .add_tools_to_manager (self .figmgr .toolmanager )
907- if self .toolbar :
908- backend_tools .add_tools_to_container (self .toolbar )
909- if self .toolbar is not None :
910- self .SetToolBar (self .toolbar )
904+ toolbar = self .canvas .manager .toolbar
905+ if toolbar is not None :
906+ self .SetToolBar (toolbar )
911907
912908 # On Windows, canvas sizing must occur after toolbar addition;
913909 # otherwise the toolbar further resizes the canvas.
@@ -920,18 +916,8 @@ def __init__(self, num, fig, *, canvas_class=None):
920916
921917 self .Bind (wx .EVT_CLOSE , self ._on_close )
922918
923- @property
924- def toolmanager (self ):
925- return self .figmgr .toolmanager
926-
927- def _get_toolbar (self ):
928- if mpl .rcParams ['toolbar' ] == 'toolbar2' :
929- toolbar = NavigationToolbar2Wx (self .canvas )
930- elif mpl .rcParams ['toolbar' ] == 'toolmanager' :
931- toolbar = ToolbarWx (self .toolmanager )
932- else :
933- toolbar = None
934- return toolbar
919+ toolmanager = property (lambda self : self .figmgr .toolmanager )
920+ toolbar = property (lambda self : self .GetToolBar ()) # backcompat
935921
936922 @_api .deprecated (
937923 "3.6" , alternative = "the canvas_class constructor parameter" )
@@ -956,7 +942,7 @@ def _on_close(self, event):
956942
957943 def Destroy (self , * args , ** kwargs ):
958944 try :
959- self .canvas .mpl_disconnect (self .toolbar ._id_drag )
945+ self .canvas .mpl_disconnect (self .canvas . manager . toolbar ._id_drag )
960946 # Rationale for line above: see issue 2941338.
961947 except AttributeError :
962948 pass # classic toolbar lacks the attribute
@@ -965,8 +951,8 @@ def Destroy(self, *args, **kwargs):
965951 # MPLBACKEND=wxagg python -c 'from pylab import *; plot()'.
966952 if self and not self .IsBeingDeleted ():
967953 super ().Destroy (* args , ** kwargs )
968- # self. toolbar.Destroy() should not be necessary if the close event
969- # is allowed to propagate.
954+ # toolbar.Destroy() should not be necessary if the close event is
955+ # allowed to propagate.
970956 return True
971957
972958
@@ -988,20 +974,7 @@ class FigureManagerWx(FigureManagerBase):
988974 def __init__ (self , canvas , num , frame ):
989975 _log .debug ("%s - __init__()" , type (self ))
990976 self .frame = self .window = frame
991- self ._initializing = True
992977 super ().__init__ (canvas , num )
993- self ._initializing = False
994-
995- @property
996- def toolbar (self ):
997- return self .frame .GetToolBar ()
998-
999- @toolbar .setter
1000- def toolbar (self , value ):
1001- # Never allow this, except that base class inits this to None before
1002- # the frame is set up.
1003- if not self ._initializing :
1004- raise AttributeError ("can't set attribute" )
1005978
1006979 def show (self ):
1007980 # docstring inherited
@@ -1373,6 +1346,10 @@ def trigger(self, *args, **kwargs):
13731346 wx .TheClipboard .Close ()
13741347
13751348
1349+ FigureManagerWx ._toolbar2_class = NavigationToolbar2Wx
1350+ FigureManagerWx ._toolmanager_toolbar_class = ToolbarWx
1351+
1352+
13761353@_Backend .export
13771354class _BackendWx (_Backend ):
13781355 FigureCanvas = FigureCanvasWx
0 commit comments