]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/floatcanvas/NavCanvas.py
2 A Panel that includes the FloatCanvas and Navigation controls
7 import FloatCanvas
, Resources
10 class NavCanvas(wx
.Panel
):
14 This is a high level window that encloses the FloatCanvas in a panel
15 and adds a Navigation toolbar.
22 size
= wx
.DefaultSize
,
23 **kwargs
): # The rest just get passed into FloatCanvas
24 wx
.Panel
.__init
__(self
, parent
, id, size
=size
)
27 ## Create the vertical sizer for the toolbar and Panel
28 box
= wx
.BoxSizer(wx
.VERTICAL
)
29 box
.Add(self
.ToolBar
, 0, wx
.ALL | wx
.ALIGN_LEFT | wx
.GROW
, 4)
31 self
.Canvas
= FloatCanvas
.FloatCanvas(self
, **kwargs
)
32 box
.Add(self
.Canvas
, 1, wx
.GROW
)
34 self
.SetSizerAndFit(box
)
37 import GUIMode
# here so that it doesn't get imported before wx.App()
38 self
.GUIZoomIn
= GUIMode
.GUIZoomIn(self
.Canvas
)
39 self
.GUIZoomOut
= GUIMode
.GUIZoomOut(self
.Canvas
)
40 self
.GUIMove
= GUIMode
.GUIMove(self
.Canvas
)
41 self
.GUIMouse
= GUIMode
.GUIMouse(self
.Canvas
)
43 # default to Mouse mode
44 self
.ToolBar
.ToggleTool(self
.PointerTool
.GetId(), True)
45 self
.Canvas
.SetMode(self
.GUIMouse
)
49 def BuildToolbar(self
):
52 tb
.SetToolBitmapSize((24,24))
54 self
.PointerTool
= tb
.AddRadioTool(wx
.ID_ANY
, bitmap
=Resources
.getPointerBitmap(), shortHelp
= "Pointer")
55 self
.Bind(wx
.EVT_TOOL
, lambda evt
: self
.SetMode(Mode
=self
.GUIMouse
), self
.PointerTool
)
57 self
.ZoomInTool
= tb
.AddRadioTool(wx
.ID_ANY
, bitmap
=Resources
.getMagPlusBitmap(), shortHelp
= "Zoom In")
58 self
.Bind(wx
.EVT_TOOL
, lambda evt
: self
.SetMode(Mode
=self
.GUIZoomIn
), self
.ZoomInTool
)
60 self
.ZoomOutTool
= tb
.AddRadioTool(wx
.ID_ANY
, bitmap
=Resources
.getMagMinusBitmap(), shortHelp
= "Zoom Out")
61 self
.Bind(wx
.EVT_TOOL
, lambda evt
: self
.SetMode(Mode
=self
.GUIZoomOut
), self
.ZoomOutTool
)
63 self
.MoveTool
= tb
.AddRadioTool(wx
.ID_ANY
, bitmap
=Resources
.getHandBitmap(), shortHelp
= "Move")
64 self
.Bind(wx
.EVT_TOOL
, lambda evt
: self
.SetMode(Mode
=self
.GUIMove
), self
.MoveTool
)
68 self
.ZoomButton
= wx
.Button(tb
, label
="Zoom To Fit")
69 tb
.AddControl(self
.ZoomButton
)
70 self
.ZoomButton
.Bind(wx
.EVT_BUTTON
, self
.ZoomToFit
)
73 ## fixme: remove this when the bug is fixed!
74 wx
.CallAfter(self
.HideShowHack
) # this required on wxPython 2.8.3 on OS-X
78 def HideShowHack(self
):
79 ##fixme: remove this when the bug is fixed!
81 Hack to hide and show button on toolbar to get around OS-X bug on
84 self
.ZoomButton
.Hide()
85 self
.ZoomButton
.Show()
87 def SetMode(self
, Mode
):
88 self
.Canvas
.SetMode(Mode
)
90 def ZoomToFit(self
,Event
):
91 self
.Canvas
.ZoomToBB()
92 self
.Canvas
.SetFocus() # Otherwise the focus stays on the Button, and wheel events are lost.