44toolbar
55"""
66
7- # Used to guarantee to use at least Wx2.8
8- import wxversion
9- wxversion .ensureMinimal ('2.8' )
7+ # matplotlib requires wxPython 2.8+
8+ # set the wxPython version in lib\site-packages\wx.pth file
9+ # or if you have wxversion installed un-comment the lines below
10+ #import wxversion
11+ #wxversion.ensureMinimal('2.8')
1012
1113from numpy import arange , sin , pi
1214
@@ -34,9 +36,15 @@ def __init__(self, canvas, cankill):
3436
3537 # for simplicity I'm going to reuse a bitmap from wx, you'll
3638 # probably want to add your own.
37- self .AddSimpleTool (self .ON_CUSTOM , _load_bitmap ('stock_left.xpm' ),
38- 'Click me' , 'Activate custom contol' )
39- wx .EVT_TOOL (self , self .ON_CUSTOM , self ._on_custom )
39+ if 'phoenix' in wx .PlatformInfo :
40+ self .AddTool (self .ON_CUSTOM , 'Click me' ,
41+ _load_bitmap ('stock_left.xpm' ),
42+ 'Activate custom contol' )
43+ self .Bind (wx .EVT_TOOL , self ._on_custom , id = self .ON_CUSTOM )
44+ else :
45+ self .AddSimpleTool (self .ON_CUSTOM , _load_bitmap ('stock_left.xpm' ),
46+ 'Click me' , 'Activate custom contol' )
47+ self .Bind (wx .EVT_TOOL , self ._on_custom , id = self .ON_CUSTOM )
4048
4149 def _on_custom (self , evt ):
4250 # add some text to the axes in a random location in axes (0,1)
@@ -62,12 +70,10 @@ def __init__(self):
6270 wx .Frame .__init__ (self , None , - 1 ,
6371 'CanvasFrame' , size = (550 , 350 ))
6472
65- self .SetBackgroundColour (wx .NamedColour ("WHITE" ))
66-
6773 self .figure = Figure (figsize = (5 , 4 ), dpi = 100 )
6874 self .axes = self .figure .add_subplot (111 )
6975 t = arange (0.0 , 3.0 , 0.01 )
70- s = sin (2 * pi * t )
76+ s = sin (2 * pi * t )
7177
7278 self .axes .plot (t , s )
7379
@@ -76,25 +82,13 @@ def __init__(self):
7682 self .sizer = wx .BoxSizer (wx .VERTICAL )
7783 self .sizer .Add (self .canvas , 1 , wx .TOP | wx .LEFT | wx .EXPAND )
7884 # Capture the paint message
79- wx .EVT_PAINT ( self , self .OnPaint )
85+ self . Bind ( wx .EVT_PAINT , self .OnPaint )
8086
8187 self .toolbar = MyNavigationToolbar (self .canvas , True )
8288 self .toolbar .Realize ()
83- if wx .Platform == '__WXMAC__' :
84- # Mac platform (OSX 10.3, MacPython) does not seem to cope with
85- # having a toolbar in a sizer. This work-around gets the buttons
86- # back, but at the expense of having the toolbar at the top
87- self .SetToolBar (self .toolbar )
88- else :
89- # On Windows platform, default window size is incorrect, so set
90- # toolbar width to figure width.
91- tw , th = self .toolbar .GetSizeTuple ()
92- fw , fh = self .canvas .GetSizeTuple ()
93- # By adding toolbar in sizer, we are able to put it at the bottom
94- # of the frame - so appearance is closer to GTK version.
95- # As noted above, doesn't work for Mac.
96- self .toolbar .SetSize (wx .Size (fw , th ))
97- self .sizer .Add (self .toolbar , 0 , wx .LEFT | wx .EXPAND )
89+ # By adding toolbar in sizer, we are able to put it at the bottom
90+ # of the frame - so appearance is closer to GTK version.
91+ self .sizer .Add (self .toolbar , 0 , wx .LEFT | wx .EXPAND )
9892
9993 # update the axes menu on the toolbar
10094 self .toolbar .update ()
0 commit comments