@@ -613,16 +613,29 @@ class _FigureCanvasWxBase(FigureCanvasBase, wx.Panel):
613
613
wx .WXK_NUMPAD_DELETE : 'delete' ,
614
614
}
615
615
616
- def __init__ (self , parent , id , figure ):
616
+ def __init__ (self , * args ):
617
617
"""
618
- Initialise a FigureWx instance.
618
+ Initialize a FigureWx instance.
619
619
620
- - Initialise the FigureCanvasBase and wxPanel parents.
621
- - Set event handlers for:
622
- EVT_SIZE (Resize event)
623
- EVT_PAINT (Paint event)
620
+ Initialize the FigureCanvasBase and wxPanel parents and set event
621
+ handlers.
622
+
623
+ Note that the canvas parent is set to the top window
624
+ (``wx.App().GetTopWindow()``) and it is the responsibility of the
625
+ caller to ``Reparent`` the canvas.
624
626
"""
625
627
628
+ if len (args ) == 3 :
629
+ # Legacy signature.
630
+ cbook .warn_deprecated (
631
+ "3.0" , "Passing a parent and id to the FigureCanvasWx "
632
+ "constructor is deprecated; use 'SetId' and 'Reparent' if "
633
+ "needed." )
634
+ parent , id , figure = args
635
+ else :
636
+ parent = wx .GetApp ().GetTopWindow ()
637
+ id = wx .ID_ANY
638
+ figure , = args
626
639
FigureCanvasBase .__init__ (self , figure )
627
640
# Set preferred window size hint - helps the sizer (if one is
628
641
# connected)
@@ -1227,7 +1240,9 @@ def _get_toolbar(self, statbar):
1227
1240
return toolbar
1228
1241
1229
1242
def get_canvas (self , fig ):
1230
- return FigureCanvasWx (self , - 1 , fig )
1243
+ canvas = FigureCanvasWx (fig )
1244
+ canvas .Reparent (self )
1245
+ return canvas
1231
1246
1232
1247
def get_figure_manager (self ):
1233
1248
DEBUG_MSG ("get_figure_manager()" , 1 , self )
@@ -1279,18 +1294,25 @@ class FigureManagerWx(FigureManagerBase):
1279
1294
def __init__ (self , canvas , num , frame ):
1280
1295
DEBUG_MSG ("__init__()" , 1 , self )
1281
1296
FigureManagerBase .__init__ (self , canvas , num )
1282
- self .frame = frame
1283
1297
self .window = frame
1284
-
1285
- self .tb = frame .GetToolBar ()
1286
- self .toolbar = self .tb # consistent with other backends
1298
+ self .toolbar = frame .GetToolBar ()
1287
1299
1288
1300
def notify_axes_change (fig ):
1289
1301
'this will be called whenever the current axes is changed'
1290
- if self .tb is not None :
1291
- self .tb .update ()
1302
+ if self .toolbar is not None :
1303
+ self .toolbar .update ()
1292
1304
self .canvas .figure .add_axobserver (notify_axes_change )
1293
1305
1306
+ @property
1307
+ @cbook .deprecated ("3.0" )
1308
+ def frame (self ):
1309
+ return self .window
1310
+
1311
+ @property
1312
+ @cbook .deprecated ("3.0" )
1313
+ def tb (self ):
1314
+ return self .toolbar
1315
+
1294
1316
def show (self ):
1295
1317
self .frame .Show ()
1296
1318
self .canvas .draw ()
@@ -1477,7 +1499,8 @@ def __init__(self, targetfig):
1477
1499
wx .Frame .__init__ (self , None , - 1 , "Configure subplots" )
1478
1500
1479
1501
toolfig = Figure ((6 , 3 ))
1480
- canvas = FigureCanvasWx (self , - 1 , toolfig )
1502
+ canvas = FigureCanvasWx (toolfig )
1503
+ canvas .Reparent (self )
1481
1504
1482
1505
# Create a figure manager to manage things
1483
1506
figmgr = FigureManager (canvas , 1 , self )
@@ -1493,7 +1516,7 @@ def __init__(self, targetfig):
1493
1516
1494
1517
class NavigationToolbar2Wx (NavigationToolbar2 , wx .ToolBar ):
1495
1518
def __init__ (self , canvas ):
1496
- wx .ToolBar .__init__ (self , canvas .GetParent (), - 1 )
1519
+ wx .ToolBar .__init__ (self , canvas .GetParent ())
1497
1520
NavigationToolbar2 .__init__ (self , canvas )
1498
1521
self .canvas = canvas
1499
1522
self ._idle = True
@@ -1506,7 +1529,9 @@ def __init__(self, canvas):
1506
1529
self .retinaFix = 'wxMac' in wx .PlatformInfo
1507
1530
1508
1531
def get_canvas (self , frame , fig ):
1509
- return type (self .canvas )(frame , - 1 , fig )
1532
+ canvas = type (self .canvas )(fig )
1533
+ canvas .Reparent (frame )
1534
+ return canvas
1510
1535
1511
1536
def _init_toolbar (self ):
1512
1537
DEBUG_MSG ("_init_toolbar" , 1 , self )
@@ -1537,7 +1562,7 @@ def pan(self, *args):
1537
1562
NavigationToolbar2 .pan (self , * args )
1538
1563
1539
1564
def configure_subplots (self , evt ):
1540
- frame = wx .Frame (None , - 1 , "Configure subplots" )
1565
+ frame = wx .Frame (None , title = "Configure subplots" )
1541
1566
1542
1567
toolfig = Figure ((6 , 3 ))
1543
1568
canvas = self .get_canvas (frame , toolfig )
@@ -1710,7 +1735,7 @@ class StatusBarWx(wx.StatusBar):
1710
1735
"""
1711
1736
1712
1737
def __init__ (self , parent ):
1713
- wx .StatusBar .__init__ (self , parent , - 1 )
1738
+ wx .StatusBar .__init__ (self , parent )
1714
1739
self .SetFieldsCount (2 )
1715
1740
self .SetStatusText ("None" , 1 )
1716
1741
# self.SetStatusText("Measurement: None", 2)
0 commit comments