Floatcanvas docs and test updates from Werner

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73979 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2013-05-14 02:53:56 +00:00
parent 16fdd105fa
commit a9f3859f3e
4 changed files with 1024 additions and 294 deletions

View File

@@ -0,0 +1,166 @@
import imp_unittest, unittest
import wtc
import wx
import wx.lib.floatcanvas.FloatCanvas as fc
import wx.lib.floatcanvas.NavCanvas as nc
#---------------------------------------------------------------------------
class lib_floatcanvas_floatcanvas_Tests(wtc.WidgetTestCase):
def test_lib_floatcanvas_floatcanvasCtor(self):
fccanvas = fc.FloatCanvas(self.frame)
def test_lib_floatcanvas_navcanvasCtor(self):
self.navcanvas = nc.NavCanvas(self.frame)
def test_lib_floatcanvas_fc_arc(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.Arc((10, 10), (20, 20), (5, 5))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_arrow(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.Arrow((10, 10), 10, 10)
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_arrowline(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.ArrowLine((10, 10))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_bitmap(self):
fccanvas = fc.FloatCanvas(self.frame)
bmp = wx.Bitmap()
obj = fc.Bitmap(bmp, (2, 2))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_circle(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.Circle((2, 2), 2)
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_line(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.Line((2, 2))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_point(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.Point((2, 2))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_pointset(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.PointSet((2, 2))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_polygon(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.Polygon((2, 2))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_rectangle(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.Rectangle((2, 2), (2, 2))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_recteclips(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.RectEllipse((2, 2), (2, 2))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_scaledbitmap(self):
fccanvas = fc.FloatCanvas(self.frame)
bmp = wx.Bitmap('smile.png')
obj = fc.ScaledBitmap(bmp, (2, 2), 100)
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_scaledbitmap2(self):
fccanvas = fc.FloatCanvas(self.frame)
bmp = wx.Bitmap('smile.png')
obj = fc.ScaledBitmap2(bmp, (2, 2), 100)
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_scaledtext(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.ScaledText("some text", (2, 2), 100)
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_scaledtextbox(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.ScaledTextBox("some text", (2, 2), 100)
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_spline(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.Spline((2, 2))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_squarepoint(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.SquarePoint((2, 2))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_fc_text(self):
fccanvas = fc.FloatCanvas(self.frame)
obj = fc.Text("some text", (2, 2))
fccanvas.AddObject(obj)
def test_lib_floatcanvas_floatcanvasEvents(self):
fc.EVT_ENTER_WINDOW
fc.EVT_FC_LEAVE_WINDOW
fc.EVT_FC_LEFT_DOWN
fc.EVT_FC_LEFT_UP
fc.EVT_FC_LEFT_DCLICK
fc.EVT_FC_MIDDLE_DOWN
fc.EVT_FC_MIDDLE_UP
fc.EVT_FC_MIDDLE_DCLICK
fc.EVT_FC_RIGHT_DOWN
fc.EVT_FC_RIGHT_UP
fc.EVT_FC_RIGHT_DCLICK
fc.EVT_FC_MOTION
fc.EVT_FC_MOUSEWHEEL
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,10 @@
#!/usr/bin/env python
"""
A Panel that includes the FloatCanvas and Navigation controls
Combines :class:`~lib.floatcanvas.FloatCanvas.FloatCanvas` with Navigation
controls onto a :class:`Panel`
Tags: phoenix-port, documented, unittest
"""
import wx
@@ -8,18 +12,25 @@ import FloatCanvas, Resources, GUIMode
class NavCanvas(wx.Panel):
"""
NavCanvas.py
This is a high level window that encloses the FloatCanvas in a panel
and adds a Navigation toolbar.
:class:`~lib.floatcanvas.FloatCanvas.NavCanvas` encloses a
:class:`~lib.floatcanvas.FloatCanvas.FloatCanvas` in a :class:`Panel` and
adds a Navigation toolbar.
"""
def __init__(self,
parent,
id = wx.ID_ANY,
size = wx.DefaultSize,
**kwargs): # The rest just get passed into FloatCanvas
parent,
id = wx.ID_ANY,
size = wx.DefaultSize,
**kwargs):
"""
Default class constructor.
:param Window `parent`: parent window. Must not be ``None``;
:param integer `id`: window identifier. A value of -1 indicates a default value;
:param `size`: a tuple or :class:`Size`
:param `**kwargs`: will be passed on to :class:`~lib.floatcanvas.FloatCanvas.FloatCanvas`
"""
wx.Panel.__init__(self, parent, id, size=size)
self.Modes = [("Pointer", GUIMode.GUIMouse(), Resources.getPointerBitmap()),
@@ -46,7 +57,8 @@ class NavCanvas(wx.Panel):
def BuildToolbar(self):
"""
This is here so it can be over-ridden in a ssubclass, to add extra tools, etc
Build the default tool bar, can be over-ridden in a subclass to add
extra tools etc.
"""
tb = wx.ToolBar(self)
self.ToolBar = tb
@@ -58,6 +70,13 @@ class NavCanvas(wx.Panel):
#wx.CallAfter(self.HideShowHack) # this required on wxPython 2.8.3 on OS-X
def AddToolbarModeButtons(self, tb, Modes):
"""
Add the mode buttons to the tool bar.
:param ToolBar `tb`: the toolbar instance
:param list `Modes`: a list of modes to add ??? what is valid ???
"""
self.ModesDict = {}
for Mode in Modes:
tool = tb.AddTool(wx.ID_ANY, label=Mode[0],
@@ -69,6 +88,12 @@ class NavCanvas(wx.Panel):
#self.Bind(wx.EVT_TOOL, lambda evt : self.SetMode(Mode=self.GUIZoomOut), self.ZoomOutTool)
def AddToolbarZoomButton(self, tb):
"""
Add the zoom button to the tool bar.
:param ToolBar `tb`: the toolbar instance
"""
tb.AddSeparator()
self.ZoomButton = wx.Button(tb, label="Zoom To Fit")
@@ -86,10 +111,12 @@ class NavCanvas(wx.Panel):
self.ZoomButton.Show()
def SetMode(self, event):
"""Event handler to set the mode."""
Mode = self.ModesDict[event.GetId()]
self.Canvas.SetMode(Mode)
def ZoomToFit(self,Event):
def ZoomToFit(self, event):
"""Event handler to zoom to fit."""
self.Canvas.ZoomToBB()
self.Canvas.SetFocus() # Otherwise the focus stays on the Button, and wheel events are lost.

View File

@@ -1,9 +1,13 @@
"""
This is the floatcanvas package. It provides two primary modules, and a
support module.
This is the floatcanvas package, the main classes are
:class:`~lib.floatcanvas.FloatCanvas` and
:class:`~lib.floatcanvas.NavCanvas`, in each class documentation there
is at least one sample on how to use them and many more samples are provided
in `wxPhoenix/samples` folder.
FloatCanvas.py contains the main FloatCanvas class, and its supporting
classes. NavCanvas.py contains a wrapper for the FloatCanvas that
FloatCanvas.py contains the main :class:`~lib.floatcanvas.FloatCanvas`
class, and its supporting classes. NavCanvas.py contains the
:class:`~lib.floatcanvas.NavCanvas` 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)
@@ -17,6 +21,7 @@ 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
@@ -28,8 +33,8 @@ 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
properly) and convenience.
It relies on `NumPy <http://www.numpy.org/>`_, which is needed for speed
(maybe, I haven't profiled properly) and convenience.
Bugs and Limitations: Lots: patches, fixes welcome
@@ -44,10 +49,10 @@ 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,
one thing I have done is used `NumPy <http://www.numpy.org/>`_ 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
@@ -64,7 +69,7 @@ Mouse Events:
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.
`NumPy <http://www.numpy.org/>`_ vector of Floats.
There are also a full set of bindings to mouse events on objects, so
that you can specify a given function be called when an object is
@@ -76,21 +81,31 @@ Copyright: Christopher Barker
License: Same as the version of wxPython you are using it with.
TRAC site for some docs and updates:
http://trac.paulmcnett.com/floatcanvas
Mailing List:
http://mail.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
The latest code is in the main wx SVN:
For classic:
http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/
For Phoenix:
http://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk/wx/lib/floatcanvas
Check for updates or answers to questions, send me an email.
Please let me know if you're using this!!!
Contact me at:
Chris.Barker@noaa.gov
Tags: phoenix-port, documented
"""
__version__ = "0.9.18"