Thanks for this example. It worked perfectly except I had to keep track
of the position of the point but not which point is near the cursor.
Anyway, thanks again
Christopher Barker wrote:
Astan Chee wrote:
I have a fc with PointSets and Lines added using AddPointSet and AddLine.
What I'm trying to do is whenever the mouse comes close (about 1-2
units) to a particular point, print it.
I'm not sure how to do this as the fc is docked in a wxPanel and most of
the code and events are caught in the wx-derived classes.
you can bind to the objects themselves, so it doesn't matter where the
canvas in parented.
I can't find any examples on detecting pointset data.
I've enclosed an example, though I needed to fix a bug to get it to
work, so you need the latest SVN version for this to work. A few notes:
When you bind to a PointSet Object:
Points = Canvas.AddPointSet(Pts, Diameter=3, Color="Red")
if you want to get a hot when the mouse is close, rather than right on
top of a point, you need to set the HitLIneWidth to something larger
Points.HitLineWidth = 10
then you can bind whatever events you want:
Points.Bind(FloatCanvas.EVT_FC_ENTER_OBJECT, self.OnOverPoints)
Points.Bind(FloatCanvas.EVT_FC_LEAVE_OBJECT, self.OnLeavePoints)
Points.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.OnLeftDown)
When you get a get a hit, you will get the PointSetObject in the callback:
def OnOverPoints(self, obj):
but you don't know which point was hit. To find that out, you call the
object's FindClosestPoint() method:
print "Mouse over point: ", obj.FindClosestPoint(obj.HitCoords)
This shows the bug -- for the ENTER and LEAVE events, I hadn't added the
HitCoords, so you couldn't do that (LEFT_UP, LEFT_DOWN, etc events
worked fine). It will work right with SVN head.
If you don't want to update FloatCanvas, you could probably get the
mouse coordinates in pixcel coords another way, then call the Canvas
PixelToWorld to get the world coords, and call FindClosestPoint() with that.
Hope this helps,
-Chris
PS: this example is now in SVN
_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas