]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/floatcanvas/NavCanvas.py
2 A Panel that includes the FloatCanvas and Navigation controls
6 #from Numeric import array,Float,cos,pi,sum,minimum,maximum,Int32
8 #from time import clock, sleep
15 import FloatCanvas
, Resources
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()
25 #---------------------------------------------------------------------------
27 class NavCanvas(wx
.Panel
):
31 This is a high level window that encloses the FloatCanvas in a panel
32 and adds a Navigation toolbar.
34 Copyright: wxWindows Software Foundation (Assigned by: Christopher Barker)
36 License: Same as the version of wxPython you are using it with
38 Please let me know if you're using this!!!
46 def __init__(self
, parent
, id = -1,
47 size
= wx
.DefaultSize
,
48 **kwargs
): # The rest just get passed into FloatCanvas
50 wx
.Panel
.__init
__( self
, parent
, id, wx
.DefaultPosition
, size
)
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)
56 self
.Canvas
= FloatCanvas
.FloatCanvas( self
, wx
.NewId(),
57 size
= wx
.DefaultSize
,
59 box
.Add(self
.Canvas
,1,wx
.GROW
)
64 # default to Mouse mode
65 self
.ToolBar
.ToggleTool(ID_POINTER_BUTTON
,1)
66 self
.Canvas
.SetMode("Mouse")
70 def __getattr__(self
, name
):
72 Delegate all extra methods to the Canvas
74 attrib
= getattr(self
.Canvas
, name
)
75 ## add the attribute to this module's dict for future calls
76 self
.__dict
__[name
] = attrib
79 def BuildToolbar(self
):
80 tb
= wx
.ToolBar(self
,-1)
83 tb
.SetToolBitmapSize((23,23))
85 tb
.AddTool(ID_POINTER_BUTTON
, Resources
.GetPointerBitmap(), isToggle
=True, shortHelpString
= "Pointer")
86 wx
.EVT_TOOL(self
, ID_POINTER_BUTTON
, self
.SetToolMode
)
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
)
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
)
94 tb
.AddTool(ID_MOVE_MODE_BUTTON
, Resources
.GetHandBitmap(), isToggle
=True, shortHelpString
= "Move")
95 wx
.EVT_TOOL(self
, ID_MOVE_MODE_BUTTON
, self
.SetToolMode
)
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
)
104 tb
.SetSizeHints(S
[0],S
[1])
107 def SetToolMode(self
,event
):
108 for id in [ID_ZOOM_IN_BUTTON
,
112 self
.ToolBar
.ToggleTool(id,0)
113 self
.ToolBar
.ToggleTool(event
.GetId(),1)
114 if event
.GetId() == ID_ZOOM_IN_BUTTON
:
115 self
.Canvas
.SetMode("ZoomIn")
116 elif event
.GetId() == ID_ZOOM_OUT_BUTTON
:
117 self
.Canvas
.SetMode("ZoomOut")
118 elif event
.GetId() == ID_MOVE_MODE_BUTTON
:
119 self
.Canvas
.SetMode("Move")
120 elif event
.GetId() == ID_POINTER_BUTTON
:
121 self
.Canvas
.SetMode("Mouse")
124 def ZoomToFit(self
,Event
):
125 self
.Canvas
.ZoomToBB()