开发者

Snapping to pixels in wxpython

I am creating a simple GUI to recor开发者_JAVA百科d points which are clicked on the image, using wxpython. However, i would like the click to be snapped to certain points on the image. Please suggest methods.


The easiest to snap to a fixed scale grid is with something like:

snap_x = scale * round(x / scale)
snap_y = scale * round(y / scale)

where scale is the size of your grid, eg 10 pixels.

If the points are nonuniformly distributed, then find the closest based on the distance (or the square of the distance for efficiency reasons).


You might have a look at wxPython's Object Graphics Library. The documentation's a little sparse but the Diagram class has direct support for snapping to grids; take a look at the wxPython Demo's Miscellaneous->OGL section for some ideas to get started. I'm in the middle of a project w. OGL right now - it's great for what it does but like I said I find the documentation a little thin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜