Added a new version (0.8.3) of FloatCanvas from Chris Barker. It's

now in a subpackage of wx.lib.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27637 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2004-06-04 21:29:41 +00:00
parent d85004c5ae
commit 42463de267
11 changed files with 3337 additions and 1568 deletions

File diff suppressed because it is too large Load Diff

View File

@ -32,6 +32,7 @@ _treeList = [
# new stuff
('Recent Additions and Updates', [
'OGL',
'FloatCanvas',
]),
# managed windows == things with a (optional) caption you can close

View File

@ -72,6 +72,7 @@ wxPython/wx/lib/editor
wxPython/wx/lib/masked
wxPython/wx/lib/mixins
wxPython/wx/lib/ogl
wxPython/wx/lib/floatcanvas
wxPython/wx/py
wxPython/wx/py/tests
wxPython/wxPython

View File

@ -108,6 +108,7 @@ Source: "wx\lib\editor\*.txt"; DestDir: "{app}\wx\lib\editor"; C
Source: "wx\lib\mixins\*.py"; DestDir: "{app}\wx\lib\mixins"; Components: core
Source: "wx\lib\masked\*.py"; DestDir: "{app}\wx\lib\masked"; Components: core
Source: "wx\lib\ogl\*.py"; DestDir: "{app}\wx\lib\ogl"; Components: core
Source: "wx\lib\floatcanvas\*.py"; DestDir: "{app}\wx\lib\floatcanvas"; Components: core
Source: "wx\py\*.py"; DestDir: "{app}\wx\py"; Components: core
Source: "wx\py\*.txt"; DestDir: "{app}\wx\py"; Components: core
Source: "wx\py\*.ico"; DestDir: "{app}\wx\py"; Components: core
@ -278,6 +279,13 @@ Type: files; Name: "{app}\wx\lib\editor\*.pyc";
Type: files; Name: "{app}\wx\lib\editor\*.pyo";
Type: files; Name: "{app}\wx\lib\mixins\*.pyc";
Type: files; Name: "{app}\wx\lib\mixins\*.pyo";
Type: files; Name: "{app}\wx\lib\masked\*.pyc";
Type: files; Name: "{app}\wx\lib\masked\*.pyo";
Type: files; Name: "{app}\wx\lib\ogl\*.pyc";
Type: files; Name: "{app}\wx\lib\ogl\*.pyo";
Type: files; Name: "{app}\wx\lib\floatcanvas\*.pyc";
Type: files; Name: "{app}\wx\lib\floatcanvas\*.pyo";
Type: files; Name: "{app}\wx\py\*.pyc";
Type: files; Name: "{app}\wx\py\*.pyo";
Type: files; Name: "{app}\wx\py\tests\*.pyc";

View File

@ -109,6 +109,9 @@ Removed the deprecated ErrorDialogs and PythonBitmaps modules. If you
were using these in your apps then please join wxPython-dev and assist
with a more modern reimplementation.
Added a new version (0.8.3)of FloatCanvas from Chris Barker. It's now
in a subpackage of wx.lib.

View File

@ -705,6 +705,7 @@ if __name__ == "__main__":
'wx.lib',
'wx.lib.colourchooser',
'wx.lib.editor',
'wx.lib.floatcanvas',
'wx.lib.masked',
'wx.lib.mixins',
'wx.lib.ogl',

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,125 @@
"""
A Panel that includes the FloatCanvas and Navigation controls
"""
#from Numeric import array,Float,cos,pi,sum,minimum,maximum,Int32
#from time import clock, sleep
import wx
#import types
#import os
import FloatCanvas, Resources
ID_ZOOM_IN_BUTTON = wx.NewId()
ID_ZOOM_OUT_BUTTON = wx.NewId()
ID_ZOOM_TO_FIT_BUTTON = wx.NewId()
ID_MOVE_MODE_BUTTON = wx.NewId()
ID_POINTER_BUTTON = wx.NewId()
#---------------------------------------------------------------------------
class NavCanvas(wx.Panel):
"""
NavCanvas.py
This is a high level window that encloses the FloatCanvas in a panel
and adds a Navigation toolbar.
Copyright: wxWindows Software Foundation (Assigned by: Christopher Barker)
License: Same as the version of wxPython you are using it with
Please let me know if you're using this!!!
Contact me at:
Chris.Barker@noaa.gov
"""
def __init__(self, parent, id = -1,
size = wx.DefaultSize,
**kwargs): # The rest just get passed into FloatCanvas
wx.Panel.__init__( self, parent, id, wx.DefaultPosition, size)
## Create the vertical sizer for the toolbar and Panel
box = wx.BoxSizer(wx.VERTICAL)
box.Add(self.BuildToolbar(), 0, wx.ALL | wx.ALIGN_LEFT | wx.GROW, 4)
self.Canvas = FloatCanvas.FloatCanvas( self, wx.NewId(),
size = wx.DefaultSize,
**kwargs)
box.Add(self.Canvas,1,wx.GROW)
box.Fit(self)
self.SetSizer(box)
# default to Mouse mode
self.ToolBar.ToggleTool(ID_POINTER_BUTTON,1)
self.Canvas.SetMode("Mouse")
return None
def __getattr__(self, name):
"""
Delegate all extra methods to the Canvas
"""
attrib = getattr(self.Canvas, name)
## add the attribute to this module's dict for future calls
self.__dict__[name] = attrib
return attrib
def BuildToolbar(self):
tb = wx.ToolBar(self,-1)
self.ToolBar = tb
tb.SetToolBitmapSize((23,23))
tb.AddTool(ID_POINTER_BUTTON, Resources.GetPointerBitmap(), isToggle=True, shortHelpString = "Pointer")
wx.EVT_TOOL(self, ID_POINTER_BUTTON, self.SetToolMode)
tb.AddTool(ID_ZOOM_IN_BUTTON, Resources.GetPlusBitmap(), isToggle=True, shortHelpString = "Zoom In")
wx.EVT_TOOL(self, ID_ZOOM_IN_BUTTON, self.SetToolMode)
tb.AddTool(ID_ZOOM_OUT_BUTTON, Resources.GetMinusBitmap(), isToggle=True, shortHelpString = "Zoom Out")
wx.EVT_TOOL(self, ID_ZOOM_OUT_BUTTON, self.SetToolMode)
tb.AddTool(ID_MOVE_MODE_BUTTON, Resources.GetHandBitmap(), isToggle=True, shortHelpString = "Move")
wx.EVT_TOOL(self, ID_MOVE_MODE_BUTTON, self.SetToolMode)
tb.AddSeparator()
tb.AddControl(wx.Button(tb, ID_ZOOM_TO_FIT_BUTTON, "Zoom To Fit",wx.DefaultPosition, wx.DefaultSize))
wx.EVT_BUTTON(self, ID_ZOOM_TO_FIT_BUTTON, self.ZoomToFit)
tb.Realize()
tb.SetSizeHints(tb.GetSize())
return tb
def SetToolMode(self,event):
for id in [ID_ZOOM_IN_BUTTON,
ID_ZOOM_OUT_BUTTON,
ID_MOVE_MODE_BUTTON,
ID_POINTER_BUTTON]:
self.ToolBar.ToggleTool(id,0)
self.ToolBar.ToggleTool(event.GetId(),1)
if event.GetId() == ID_ZOOM_IN_BUTTON:
self.Canvas.SetMode("ZoomIn")
elif event.GetId() == ID_ZOOM_OUT_BUTTON:
self.Canvas.SetMode("ZoomOut")
elif event.GetId() == ID_MOVE_MODE_BUTTON:
self.Canvas.SetMode("Move")
elif event.GetId() == ID_POINTER_BUTTON:
self.Canvas.SetMode("Mouse")
def ZoomToFit(self,Event):
self.Canvas.ZoomToBB()

View File

@ -0,0 +1,66 @@
"""
Resources.py Various resources needed by the FloatCanvas package
Includes, icons, etc.
"""
### These are some functions for bitmaps of icons.
import wx, cPickle, zlib
def GetHandData():
return cPickle.loads(zlib.decompress(
'x\xda\xd3\xc8)0\xe4\nV72T\x00!\x05Cu\xae\xc4`u=\x85d\x05\xa7\x9c\xc4\xe4l0O\
\x01\xc8S\xb6t\x06A(\x1f\x0b\xa0\xa9\x8c\x9e\x1e6\x19\xa0\xa8\x1e\x88\xd4C\
\x97\xd1\x83\xe8\x80 \x9c2zh\xa6\xc1\x11X\n\xab\x8c\x02\x8a\x0cD!\x92\x12\
\x98\x8c\x1e\x8a\x8b\xd1d\x14\xf4\x90%\x90LC\xf6\xbf\x1e\xba\xab\x91%\xd0\
\xdc\x86C\x06\xd9m\xe8!\xaa\x87S\x86\x1a1\xa7\x07\x00v\x0f[\x17' ))
def GetHandBitmap():
return wx.BitmapFromXPMData(GetHandData())
#----------------------------------------------------------------------
def GetPlusData():
return cPickle.loads(zlib.decompress(
'x\xda\xd3\xc8)0\xe4\nV72T\x00!\x05Cu\xae\xc4`u=\x85d\x05\xa7\x9c\xc4\xe4l0O\
\x01\xc8S\xb6t\x06A(\x1f\x0b RF\x0f\x08\xb0\xc9@D\xe1r\x08\x19\xb8j=l2`\r\
\xe82HF\xe9a\xc8\xe8\xe9A\x9c@\x8a\x0c\x0e\xd3p\xbb\x00\x8f\xab\xe1>\xd5\xd3\
\xc3\x15:P)l!\n\x91\xc2\x1a\xd6`)\xec\xb1\x00\x92\xc2\x11?\xb8e\x88\x8fSt\
\x19=\x00\x82\x16[\xf7' ))
def GetPlusBitmap():
return wx.BitmapFromXPMData(GetPlusData())
#----------------------------------------------------------------------
def GetMinusData():
return cPickle.loads(zlib.decompress(
'x\xda\xd3\xc8)0\xe4\nV72T\x00!\x05Cu\xae\xc4`u=\x85d\x05\xa7\x9c\xc4\xe4l0O\
\x01\xc8S\xb6t\x06A(\x1f\x0b RF\x0f\x08\xb0\xc9@D\xe1r\x08\x19\xb8j=\xa2e\
\x10\x16@\x99\xc82zz\x10\'\x90"\x83\xc34r\xdc\x86\xf0\xa9\x9e\x1e\xae\xd0\
\x81Ja\x0bQ\x88\x14\xd6\xb0\x06Ka\x8f\x05\x90\x14\x8e\xf8\xc1-C|\x9c\xa2\xcb\
\xe8\x01\x00\xed\x0f[\x87' ))
def GetMinusBitmap():
return wx.BitmapFromXPMData(GetMinusData())
## NOTE: this was created using a newer version of img2py than the above
import cStringIO
def GetPointerData():
return zlib.decompress(
'x\xda\xeb\x0c\xf0s\xe7\xe5\x92\xe2b``\xe0\xf5\xf4p\t\x02\xd2\xa2 \xcc\xc1\
\x06$W\x8a/\x9d\x06\xa4X\x8a\x9d<C8\x80\xa0\x86#\xa5\x03\xc8\xcf\xf4tq\x0c\
\xa9\x98s\xf4\x92\xa3\x10\x83 \x0f\x8b\xc3\xea?\xa6\xf9\xb3\xae\xaf\x9b\xbcj\
\xef\x9a3-\x13\xba\x99o\xb1\xf07l\xcfYg5\xdbd\xf3\xdf\x0c\x91\xb2\x8b\x1e\
\x81+fM\xf3[u \xe8\xb7N\xcd{\xbf\xfdG\x97\xf0\xaa~}P\xf0\xdb\xd8\xe2\xa9\xdf\
\xec]\x8c\r\xbb\xdb\xbcN9\x08Y\x1d0\\\xb6\xf7\x9f\xd0\xaam\xbe\x0b\xeb\xdb\
\x97\xfc\xbd\xfc8\xe3\x94\xfd\xdb\x7fs\xa4\xa7\x17\xf0\x9d;\x03\xb4\x94\xc1\
\xd3\xd5\xcfe\x9dSB\x13\x00\xcbEE&' )
def GetPointerBitmap():
return wx.BitmapFromImage(GetPointerImage())
def GetPointerImage():
stream = cStringIO.StringIO(GetPointerData())
return wx.ImageFromStream(stream)

View File

@ -0,0 +1,95 @@
"""
This is the floatcanvas package. It provides two primary modules, and a
support module.
FloatCanvas.py contains the main FloatCanvas class, and it's supporting
classes. NavCanvas.py contains a wrapper for the FloatCanvas that
provides the canvas and a toolbar with tools that allow you to navigate
the canvas (zooming, panning, etc.) Resources.py is a module that
contains a few resources required by the FloatCanvas (icons, etc)
The FloatCanvas is a high level window for drawing maps and anything
else in an arbitrary coordinate system.
The goal is to provide a convenient way to draw stuff on the screen
without having to deal with handling OnPaint events, converting to pixel
coordinates, knowing about wxWindows brushes, pens, and colors, etc. It
also provides virtually unlimited zooming and scrolling
I am using it for two things:
1) general purpose drawing in floating point coordinates
2) displaying map data in Lat-long coordinates
If the projection is set to None, it will draw in general purpose
floating point coordinates. If the projection is set to 'FlatEarth', it
will draw a FlatEarth projection, centered on the part of the map that
you are viewing. You can also pass in your own projection function.
It is double buffered, so re-draws after the window is uncovered by
something else are very quick.
It relies on NumPy, which is needed for speed (maybe, I haven't profiled
it). It will also use numarray, if you don't have Numeric, but it is
slower.
Bugs and Limitations: Lots: patches, fixes welcome
For Map drawing: It ignores the fact that the world is, in fact, a
sphere, so it will do strange things if you are looking at stuff near
the poles or the date line. so far I don't have a need to do that, so I
havn't bothered to add any checks for that yet.
Zooming: I have set no zoom limits. What this means is that if you zoom
in really far, you can get integer overflows, and get weird results. It
doesn't seem to actually cause any problems other than weird output, at
least when I have run it.
Speed: I have done a couple of things to improve speed in this app. The
one thing I have done is used NumPy Arrays to store the coordinates of
the points of the objects. This allowed me to use array oriented
functions when doing transformations, and should provide some speed
improvement for objects with a lot of points (big polygons, polylines,
pointsets).
The real slowdown comes when you have to draw a lot of objects, because
you have to call the wx.DC.DrawSomething call each time. This is plenty
fast for tens of objects, OK for hundreds of objects, but pretty darn
slow for thousands of objects.
If you are zoomed in, it checks the Bounding box of an object before
drawing it. This makes it a great deal faster when there are a lot of
objects and you are zoomed in so that only a few are shown.
One solution is to be able to pass some sort of object set to the DC
directly. I've used DC.DrawPointList(Points), and it helped a lot with
drawing lots of points. However, when zoomed in, the Bounding boxes need
to be checked, so I may some day write C++ code that does the loop and
checks the BBs.
Mouse Events:
At this point, there are a full set of custom mouse events. They are
just like the regular mouse events, but include an extra attribute:
Event.GetCoords(), that returns the (x,y) position in world coordinates,
as a length-2 NumPy vector of Floats.
See the Demo for what it can do, and how to use it.
Copyright: Christopher Barker
License: Same as the version of wxPython you are using it with.
Check for updates at:
http://home.comcast.net/~chrishbarker/FloatCanvas/
Please let me know if you're using this!!!
Contact me at:
Chris.Barker@noaa.gov
"""
__version__ = "0.8.3"