WxInter
Christopher Barker
Chris.Barker at noaa.gov
Tue Sep 14 20:05:05 EDT 2004
Brian Elmegaard wrote:
> Eric Brunel <eric_brunel at despammed.com> writes:
>>quite far from it: I didn't see any means to move canvas items
>>individually, or group them with tags, or knowing which items are at a
>>given position, all things a tk canvas can do very easily...
>
> You can. Have a look at pySketch which comes with wx as one of the
> sample apps.
Well, pySketch does a lot of that, but it wasn't easy, and I don't thin
the code was written in a way that it would be easy to just use it in
your own app.
>>canvas item is just a bunch of points. In tk, it remains a whole item
>>which can be manipulated as a whole. Basically, in tk, canvases are
>>for vector drawing; in other toolkits, they're more for bitmap
>>drawing. And this makes quite a difference...
Check out my FloatCanvas for wxPython:
http://home.comcast.net/~chrishbarker/FloatCanvas/
It's also in the wxPython lib and demo in recent versions.
Sorry I don't have a nifty page describing it, but there is a demo that
comes with it. It does do most of what that TK canvas does, with a few
exceptions:
1) no tags, but you can put a bunch of FloatCanvas DrawObjects in a
list, and manipulate them that way. I really haven't seen that tags are
that useful, but if you think so, I'll accept a patch.
2) As the name implies, it works with arbitrary floating point
coordinates, scaling them to pixels for you. It then provides full
zooming and scrolling. I like this, as I use it to draw data, which is
never in pixel coords to begin with.
3) It provides a simple flat-earth projection for map data.
4) the event binding is different, perhaps a little more complex, but
also quite powerful. Here's a version of most of your example. wxPython
requires a bit more overhead in terms of creating Frame objects, etc,
but you'd do that anyway in any but a trivial app:
#!/usr/bin/env python2.3
import wx
import fixdc
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
class DrawFrame(wx.Frame):
"""
A frame used for the FloatCanvas Demo
"""
def __init__(self,parent, id,title,position,size):
wx.Frame.__init__(self,parent, id,title,position, size)
# Add the Canvas
Canvas = NavCanvas.NavCanvas(self,-1,(500,500),
ProjectionFun = None,
Debug = 0,
BackgroundColor = "DARK SLATE
BLUE",
)
self.Canvas = Canvas
self.circle1 = Canvas.AddCircle(10, 10, 20, FillColor='red')
# Event binding on a single item
self.circle1.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.bindingA)
# or to the right button:
self.circle1.Bind(FloatCanvas.EVT_FC_RIGHT_DOWN, self.bindingB)
## A group of objects in a list:
self.ObjectsList = []
self.ObjectsList.append(Canvas.AddRectangle(30, 30, 30, 20,
FillColor = "Blue"))
self.ObjectsList.append(Canvas.AddPolygon(((70,40),(80,60),(90,70),(65,80)),
FillColor = "Purple"))
self.BindAll()
self.Show(True)
self.Canvas.ZoomToBB()
return None
def BindAll(self):
for object in self.ObjectsList:
object.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.bindingC)
def bindingA(self, event):
print "I'm circle1!"
def bindingB(self, event):
print "I'm circle1 with the right button!"
def bindingC(self, event):
print "I'm an object in the list!"
app = wx.PySimpleApp()
DrawFrame(None, -1, "FloatCanvas Demo App", wx.DefaultPosition, (700,700) )
app.MainLoop()
Be sure to let me know if you' re using it, I may have fixed bugs since
the last release.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the Python-list
mailing list