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