Chris.Barker at noaa.gov
Wed Sep 15 02:05:05 CEST 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:
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
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:
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
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
self.Canvas = Canvas
self.circle1 = Canvas.AddCircle(10, 10, 20, FillColor='red')
# Event binding on a single item
# or to the right button:
## A group of objects in a list:
self.ObjectsList = 
self.ObjectsList.append(Canvas.AddRectangle(30, 30, 30, 20,
FillColor = "Blue"))
FillColor = "Purple"))
for object in self.ObjectsList:
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) )
Be sure to let me know if you' re using it, I may have fixed bugs since
the last release.
Christopher Barker, Ph.D.
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