]>
Commit | Line | Data |
---|---|---|
42463de2 RD |
1 | """ |
2 | A Panel that includes the FloatCanvas and Navigation controls | |
3 | ||
4 | """ | |
5 | ||
42463de2 RD |
6 | import wx |
7 | ||
42463de2 RD |
8 | import FloatCanvas, Resources |
9 | ||
42463de2 RD |
10 | ID_ZOOM_IN_BUTTON = wx.NewId() |
11 | ID_ZOOM_OUT_BUTTON = wx.NewId() | |
12 | ID_ZOOM_TO_FIT_BUTTON = wx.NewId() | |
13 | ID_MOVE_MODE_BUTTON = wx.NewId() | |
14 | ID_POINTER_BUTTON = wx.NewId() | |
15 | ||
16 | ||
17 | #--------------------------------------------------------------------------- | |
18 | ||
19 | class NavCanvas(wx.Panel): | |
20 | """ | |
21 | NavCanvas.py | |
22 | ||
23 | This is a high level window that encloses the FloatCanvas in a panel | |
24 | and adds a Navigation toolbar. | |
25 | ||
26 | Copyright: wxWindows Software Foundation (Assigned by: Christopher Barker) | |
27 | ||
28 | License: Same as the version of wxPython you are using it with | |
29 | ||
30 | Please let me know if you're using this!!! | |
31 | ||
32 | Contact me at: | |
33 | ||
34 | Chris.Barker@noaa.gov | |
35 | ||
36 | """ | |
37 | ||
38 | def __init__(self, parent, id = -1, | |
39 | size = wx.DefaultSize, | |
40 | **kwargs): # The rest just get passed into FloatCanvas | |
41 | ||
42 | wx.Panel.__init__( self, parent, id, wx.DefaultPosition, size) | |
43 | ||
44 | ## Create the vertical sizer for the toolbar and Panel | |
45 | box = wx.BoxSizer(wx.VERTICAL) | |
46 | box.Add(self.BuildToolbar(), 0, wx.ALL | wx.ALIGN_LEFT | wx.GROW, 4) | |
47 | ||
48 | self.Canvas = FloatCanvas.FloatCanvas( self, wx.NewId(), | |
49 | size = wx.DefaultSize, | |
50 | **kwargs) | |
51 | box.Add(self.Canvas,1,wx.GROW) | |
52 | ||
53 | box.Fit(self) | |
54 | self.SetSizer(box) | |
55 | ||
56 | # default to Mouse mode | |
57 | self.ToolBar.ToggleTool(ID_POINTER_BUTTON,1) | |
58 | self.Canvas.SetMode("Mouse") | |
59 | ||
60 | return None | |
61 | ||
62 | def __getattr__(self, name): | |
63 | """ | |
64 | Delegate all extra methods to the Canvas | |
65 | """ | |
66 | attrib = getattr(self.Canvas, name) | |
67 | ## add the attribute to this module's dict for future calls | |
68 | self.__dict__[name] = attrib | |
69 | return attrib | |
70 | ||
71 | def BuildToolbar(self): | |
72 | tb = wx.ToolBar(self,-1) | |
73 | self.ToolBar = tb | |
74 | ||
75 | tb.SetToolBitmapSize((23,23)) | |
76 | ||
77 | tb.AddTool(ID_POINTER_BUTTON, Resources.GetPointerBitmap(), isToggle=True, shortHelpString = "Pointer") | |
78 | wx.EVT_TOOL(self, ID_POINTER_BUTTON, self.SetToolMode) | |
79 | ||
80 | tb.AddTool(ID_ZOOM_IN_BUTTON, Resources.GetPlusBitmap(), isToggle=True, shortHelpString = "Zoom In") | |
81 | wx.EVT_TOOL(self, ID_ZOOM_IN_BUTTON, self.SetToolMode) | |
82 | ||
83 | tb.AddTool(ID_ZOOM_OUT_BUTTON, Resources.GetMinusBitmap(), isToggle=True, shortHelpString = "Zoom Out") | |
84 | wx.EVT_TOOL(self, ID_ZOOM_OUT_BUTTON, self.SetToolMode) | |
85 | ||
86 | tb.AddTool(ID_MOVE_MODE_BUTTON, Resources.GetHandBitmap(), isToggle=True, shortHelpString = "Move") | |
87 | wx.EVT_TOOL(self, ID_MOVE_MODE_BUTTON, self.SetToolMode) | |
88 | ||
89 | tb.AddSeparator() | |
90 | ||
91 | tb.AddControl(wx.Button(tb, ID_ZOOM_TO_FIT_BUTTON, "Zoom To Fit",wx.DefaultPosition, wx.DefaultSize)) | |
92 | wx.EVT_BUTTON(self, ID_ZOOM_TO_FIT_BUTTON, self.ZoomToFit) | |
93 | ||
94 | tb.Realize() | |
5e1796ef RD |
95 | S = tb.GetSize() |
96 | tb.SetSizeHints(S[0],S[1]) | |
42463de2 RD |
97 | return tb |
98 | ||
99 | def SetToolMode(self,event): | |
100 | for id in [ID_ZOOM_IN_BUTTON, | |
101 | ID_ZOOM_OUT_BUTTON, | |
102 | ID_MOVE_MODE_BUTTON, | |
103 | ID_POINTER_BUTTON]: | |
104 | self.ToolBar.ToggleTool(id,0) | |
105 | self.ToolBar.ToggleTool(event.GetId(),1) | |
106 | if event.GetId() == ID_ZOOM_IN_BUTTON: | |
107 | self.Canvas.SetMode("ZoomIn") | |
108 | elif event.GetId() == ID_ZOOM_OUT_BUTTON: | |
109 | self.Canvas.SetMode("ZoomOut") | |
110 | elif event.GetId() == ID_MOVE_MODE_BUTTON: | |
111 | self.Canvas.SetMode("Move") | |
112 | elif event.GetId() == ID_POINTER_BUTTON: | |
113 | self.Canvas.SetMode("Mouse") | |
114 | ||
115 | ||
116 | def ZoomToFit(self,Event): | |
117 | self.Canvas.ZoomToBB() | |
118 |