@@ -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 )
@@ -1282,15 +1297,24 @@ def __init__(self, canvas, num, frame):
1282
1297
self .frame = frame
1283
1298
self .window = frame
1284
1299
1285
- self .tb = frame .GetToolBar ()
1286
- self .toolbar = self .tb # consistent with other backends
1300
+ self .toolbar = frame .GetToolBar ()
1287
1301
1288
1302
def notify_axes_change (fig ):
1289
1303
'this will be called whenever the current axes is changed'
1290
- if self .tb is not None :
1291
- self .tb .update ()
1304
+ if self .toolbar is not None :
1305
+ self .toolbar .update ()
1292
1306
self .canvas .figure .add_axobserver (notify_axes_change )
1293
1307
1308
+ @property
1309
+ @cbook .deprecated ("3.0" )
1310
+ def frame (self ):
1311
+ return self .window
1312
+
1313
+ @property
1314
+ @cbook .deprecated ("3.0" )
1315
+ def tb (self ):
1316
+ return self .toolbar
1317
+
1294
1318
def show (self ):
1295
1319
self .frame .Show ()
1296
1320
self .canvas .draw ()
@@ -1477,7 +1501,8 @@ def __init__(self, targetfig):
1477
1501
wx .Frame .__init__ (self , None , - 1 , "Configure subplots" )
1478
1502
1479
1503
toolfig = Figure ((6 , 3 ))
1480
- canvas = FigureCanvasWx (self , - 1 , toolfig )
1504
+ canvas = FigureCanvasWx (toolfig )
1505
+ canvas .Reparent (self )
1481
1506
1482
1507
# Create a figure manager to manage things
1483
1508
figmgr = FigureManager (canvas , 1 , self )
@@ -1493,7 +1518,7 @@ def __init__(self, targetfig):
1493
1518
1494
1519
class NavigationToolbar2Wx (NavigationToolbar2 , wx .ToolBar ):
1495
1520
def __init__ (self , canvas ):
1496
- wx .ToolBar .__init__ (self , canvas .GetParent (), - 1 )
1521
+ wx .ToolBar .__init__ (self , canvas .GetParent ())
1497
1522
NavigationToolbar2 .__init__ (self , canvas )
1498
1523
self .canvas = canvas
1499
1524
self ._idle = True
@@ -1506,7 +1531,9 @@ def __init__(self, canvas):
1506
1531
self .retinaFix = 'wxMac' in wx .PlatformInfo
1507
1532
1508
1533
def get_canvas (self , frame , fig ):
1509
- return type (self .canvas )(frame , - 1 , fig )
1534
+ canvas = type (self .canvas )(fig )
1535
+ canvas .Reparent (frame )
1536
+ return canvas
1510
1537
1511
1538
def _init_toolbar (self ):
1512
1539
DEBUG_MSG ("_init_toolbar" , 1 , self )
@@ -1537,7 +1564,7 @@ def pan(self, *args):
1537
1564
NavigationToolbar2 .pan (self , * args )
1538
1565
1539
1566
def configure_subplots (self , evt ):
1540
- frame = wx .Frame (None , - 1 , "Configure subplots" )
1567
+ frame = wx .Frame (None , title = "Configure subplots" )
1541
1568
1542
1569
toolfig = Figure ((6 , 3 ))
1543
1570
canvas = self .get_canvas (frame , toolfig )
@@ -1710,7 +1737,7 @@ class StatusBarWx(wx.StatusBar):
1710
1737
"""
1711
1738
1712
1739
def __init__ (self , parent ):
1713
- wx .StatusBar .__init__ (self , parent , - 1 )
1740
+ wx .StatusBar .__init__ (self , parent )
1714
1741
self .SetFieldsCount (2 )
1715
1742
self .SetStatusText ("None" , 1 )
1716
1743
# self.SetStatusText("Measurement: None", 2)
0 commit comments