]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/floatcanvas/NavCanvas.py
   2 A Panel that includes the FloatCanvas and Navigation controls 
   8 import FloatCanvas
, Resources
 
  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() 
  17 #--------------------------------------------------------------------------- 
  19 class NavCanvas(wx
.Panel
): 
  23     This is a high level window that encloses the FloatCanvas in a panel 
  24     and adds a Navigation toolbar. 
  26     Copyright: wxWindows Software Foundation (Assigned by: Christopher Barker) 
  28     License: Same as the version of wxPython you are using it with 
  30     Please let me know if you're using this!!! 
  38     def __init__(self
, parent
, id = -1, 
  39                  size 
= wx
.DefaultSize
, 
  40                  **kwargs
): # The rest just get passed into FloatCanvas 
  42         wx
.Panel
.__init
__( self
, parent
, id, wx
.DefaultPosition
, size
) 
  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) 
  48         self
.Canvas 
= FloatCanvas
.FloatCanvas( self
, wx
.NewId(), 
  49                                    size 
= wx
.DefaultSize
, 
  51         box
.Add(self
.Canvas
,1,wx
.GROW
) 
  56         # default to Mouse mode 
  57         self
.ToolBar
.ToggleTool(ID_POINTER_BUTTON
,1) 
  58         self
.Canvas
.SetMode("Mouse") 
  62     def __getattr__(self
, name
): 
  64         Delegate all extra methods to the Canvas 
  66         attrib 
= getattr(self
.Canvas
, name
) 
  67         ## add the attribute to this module's dict for future calls 
  68         self
.__dict
__[name
] = attrib
 
  71     def BuildToolbar(self
): 
  72         tb 
= wx
.ToolBar(self
,-1) 
  75         tb
.SetToolBitmapSize((23,23)) 
  77         tb
.AddTool(ID_POINTER_BUTTON
, Resources
.GetPointerBitmap(), isToggle
=True, shortHelpString 
= "Pointer") 
  78         wx
.EVT_TOOL(self
, ID_POINTER_BUTTON
, self
.SetToolMode
) 
  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
) 
  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
) 
  86         tb
.AddTool(ID_MOVE_MODE_BUTTON
, Resources
.GetHandBitmap(), isToggle
=True, shortHelpString 
= "Move") 
  87         wx
.EVT_TOOL(self
, ID_MOVE_MODE_BUTTON
, self
.SetToolMode
) 
  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
) 
  96         tb
.SetSizeHints(S
[0],S
[1]) 
  99     def SetToolMode(self
,event
): 
 100         for id in [ID_ZOOM_IN_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") 
 116     def ZoomToFit(self
,Event
): 
 117         self
.Canvas
.ZoomToBB()