| 1 | """ |
| 2 | A Panel that includes the FloatCanvas and Navigation controls |
| 3 | |
| 4 | """ |
| 5 | |
| 6 | import wx |
| 7 | import FloatCanvas, Resources |
| 8 | |
| 9 | |
| 10 | class NavCanvas(wx.Panel): |
| 11 | """ |
| 12 | NavCanvas.py |
| 13 | |
| 14 | This is a high level window that encloses the FloatCanvas in a panel |
| 15 | and adds a Navigation toolbar. |
| 16 | |
| 17 | """ |
| 18 | |
| 19 | def __init__(self, |
| 20 | parent, |
| 21 | id = wx.ID_ANY, |
| 22 | size = wx.DefaultSize, |
| 23 | **kwargs): # The rest just get passed into FloatCanvas |
| 24 | wx.Panel.__init__(self, parent, id, size=size) |
| 25 | |
| 26 | self.BuildToolbar() |
| 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) |
| 30 | |
| 31 | self.Canvas = FloatCanvas.FloatCanvas(self, **kwargs) |
| 32 | box.Add(self.Canvas, 1, wx.GROW) |
| 33 | |
| 34 | self.SetSizerAndFit(box) |
| 35 | |
| 36 | |
| 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) |
| 42 | |
| 43 | # default to Mouse mode |
| 44 | self.ToolBar.ToggleTool(self.PointerTool.GetId(), True) |
| 45 | self.Canvas.SetMode(self.GUIMouse) |
| 46 | |
| 47 | return None |
| 48 | |
| 49 | def BuildToolbar(self): |
| 50 | tb = wx.ToolBar(self) |
| 51 | self.ToolBar = tb |
| 52 | tb.SetToolBitmapSize((24,24)) |
| 53 | |
| 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) |
| 56 | |
| 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) |
| 59 | |
| 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) |
| 62 | |
| 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) |
| 65 | |
| 66 | tb.AddSeparator() |
| 67 | |
| 68 | self.ZoomButton = wx.Button(tb, label="Zoom To Fit") |
| 69 | tb.AddControl(self.ZoomButton) |
| 70 | self.ZoomButton.Bind(wx.EVT_BUTTON, self.ZoomToFit) |
| 71 | |
| 72 | tb.Realize() |
| 73 | ## fixme: remove this when the bug is fixed! |
| 74 | wx.CallAfter(self.HideShowHack) # this required on wxPython 2.8.3 on OS-X |
| 75 | |
| 76 | return tb |
| 77 | |
| 78 | def HideShowHack(self): |
| 79 | ##fixme: remove this when the bug is fixed! |
| 80 | """ |
| 81 | Hack to hide and show button on toolbar to get around OS-X bug on |
| 82 | wxPython2.8 on OS-X |
| 83 | """ |
| 84 | self.ZoomButton.Hide() |
| 85 | self.ZoomButton.Show() |
| 86 | |
| 87 | def SetMode(self, Mode): |
| 88 | self.Canvas.SetMode(Mode) |
| 89 | |
| 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. |
| 93 | |