On Mon, Jul 7, 2014 at 2:48 AM, Farrukh <[email protected]
<mailto:[email protected]>> wrote:
Hi
i am using wxpython 3.0.0 and python version 2.7, i have
modified piechart example to create clickable object of
*FloatCanvas.Rectangle *but failed
How is it "failing" -- it works for me -- when I click on the
rectangles, I get a mesage on the console saying which one got
clicked. What does it do for you?
I just tested it with wxPython 2.9.4, on a Mac.
Maybe an issue with 3.0?
Some comments, below:
here is my code:
import wx
import sys
sys.path.append("..")
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
class DrawFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.CreateStatusBar()
NC = FloatCanvas.FloatCanvas(self, BackgroundColor = (
147, 177, 217 ) )
self.canvas = NC
self.Shape = []
rect = FloatCanvas.Rectangle((30,10),(10, 10), FillColor
= wx.Colour(3, 2, 255, 240), LineColor = wx.Colour(250, 5, 5,
240), LineStyle = "Solid", LineWidth = 2 )
self.canvas.AddObject(rect)
self.Shape.append( rect )
# this is a chance to add an attribute to the rect, so that you can
access it later when it gets hit:
rect.name <http://rect.name> = "the first rect"
rect = FloatCanvas.Rectangle((10,20),(10, 10),
FillColor = wx.Colour(3, 2, 255, 240), LineColor = wx.Colour(250,
5, 5, 240), LineStyle = "Solid", LineWidth = 2 )
self.canvas.AddObject(rect)
self.Shape.append( rect )
and here:
rect.name <http://rect.name> = "the second rect"
rect = FloatCanvas.Rectangle((50,20),(10, 10), FillColor
= wx.Colour(3, 2, 255, 240), LineColor = wx.Colour(250, 5, 5,
240), LineStyle = "Solid", LineWidth = 2 )
self.canvas.AddObject(rect)
self.Shape.append( rect )
and here:
rect.name <http://rect.name> = "the second rect"
for i in range( len(self.Shape) ):
self.Shape[i].Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.PieHit)
FloatCanvas.EVT_MOTION(self.canvas, self.OnMove )
self.Show()
self.Center()
self.canvas.ZoomToBB()
def PieHit(self, obj):
this search is ugly -- but if you added aname attributre, you could
just do:
print obj.name <http://obj.name>, "hit!"
for i in range( len(self.Shape) ):
if obj == self.Shape[i]:
print "Rectangle"+str(i)+" hit!"
self.SetTitle("Rectangle"+str(i)+" hit!")
def OnMove(self, event):
self.SetStatusText("%.2g, %.2g"%tuple(event.Coords))
app = wx.App(False)
F = DrawFrame(None, title="Modified FloatCanvas Demo",
size=(700,700) )
app.MainLoop()
------------------------------------------------------------------------
<http://www.avast.com/>
This email is free from viruses and malware because avast!
Antivirus <http://www.avast.com/> protection is active.
_______________________________________________
FloatCanvas mailing list
[email protected] <mailto:[email protected]>
http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
[email protected] <mailto:[email protected]>
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas