madhura wrote:
1) How do I decide if the user has clicked within the figure for
different figures rect/square/line?
> 2) What if there are more than one figures on screen? How do I decide
> which one is selected
There are lots of ways, but I think the easiest and most robust is some version of drawing the figures, each in a different color, and then checking the color of the pixel where clicked -- or, on the click, just draw each figure to a small off-screen bitmap, and see if the pixel in consideration changes color. (you can do a bounding box check first, so that you don't draw everything, or even better, use a spatial index, such as an rtree)
An alternative is to use math (coordinate geometry), but this gets difficult really fast if your figures are complex.
3) Do I have to use pyOpenGl for all this?
Not at all -- unless you want really fast rendering of lots of data -- but it's much harder to use than DCs or GraphicsContext.
Is there any other method?
unless you are doing this primarily as a learning exercise (and even if you are...), don't do it all from scratch. See:
wx.lib.floatcanvas
or the new version (FloatCanvas2)in SVN:
http://svn.wxwidgets.org/svn/wx/wxPython/3rdParty/branches/FloatCanvas/SOC2008_FloatCanvas/floatcanvas2/
or PySketch, the simple drawing demo that comes with wxPython:
http://svn.wxwidgets.org/svn/wx/wxPython/trunk/samples/pySketch/
or this nifty project from Steve sproat:
https://launchpad.net/whyteboard
-Chris
···
--
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
Chris.Barker@noaa.gov