> nadili wrote:
>> I’m still a newbie in python (and wxpython),
Welcome.
>> Another thing I wanted to do is to be able to
>> erase some specific point after I have drawn it,
>> menu = wx.Menu()
>> menu.Append(5000, "&New Picture")
...
>> self.Bind(wx.EVT_MENU, self.OnNewPicture, id=5000)
This is just a style thing, but I like to avoid explicit IDs when I can:
item = wx.MenuItem("&New Picture")
menu.Append(item)
self.Bind(wx.EVT_MENU, self.OnNewPicture, item)
For more style suggestions:
http://wiki.wxpython.org/wxPython%20Style%20Guide
>> self.ChildFrame = wx.MDIChildFrame(self, -1, "Child Frame")
and you do:
self.ChildFrame = wx.MDIChildFrame(self, title="Child Frame")
again, just style.
>> image = wx.Image("orion.jpg")
>> self.temp = image.ConvertToBitmap()
>> self.Canvas.AddScaledBitmap(self.temp, (0,0), Height =
>> image.GetSize()[1], Position='tl')
You can pass the wx.Image directly to AddSCaledBitmap:
self.Canvas.AddScaledBitmap(image, (0,0), Height=image.GetSize()[1],
Position='tl')
In fact, it's going to convert the wx.Bitmap back into a wx.Image
internally anyway -- you can scale a wx.Image, but not a wx.Bitmap.
>> self.Bind(wx.EVT_RIGHT_DOWN, self.OnDrawDot)
If you bind to the Canvas, an use the FloatCanvas events, you'll get an
event that already has World coords:
self.Canvas.Bind(FC.EVT_LEFT_DOWN, self.OnDrawDot)
def OnDrawDot(self, evt):
mposcanvas = evt.Coords()
self.frame.statusbar.SetStatusText("Pos: %s"%mposcanvas)
> I think this is what you need:
>
> self.Canvas.Draw(True)
yup -- YOu need to Call Draw, because often you might want to make a
bunch of changes to the Canvas, and you wouldn't want it to re-draw
between each one, but rather wait until you're done with all the changes
you're making at once. Just so you know, the "True" means -- "force a
redraw". Sometimes the Canvas doesn't know there has been a change, so
it won't redraw -- in this case, you've added an Object, so it doesn't
need to be forced. It won't hurt, though.
> Not sure if you will still need the .Show()
nope.
As for erasing points -- if you8 store the point you add somewhere, you
can then delete them (or Hide them):
def OnDrawDot(self, evt):
...
self.dots.append(self.frame.Canvas.AddPoint(mposcanvas, Diameter=9,
Color = "Red"))
Now you can delete one:
self.frame.Canvas.RemoveObject(self.dots[i])
You can also Hide it:
self.dots[i].Hide()
and show it again:
self.dots[i].Show()
you'll need to call Canvas.Draw(Force=True) for those to take effect.
One other style issue. When you use a structure like:
self.frame.Canvas.AddPoint()
You need your App object to know that it has a frame object, and that
that frame has a Canvas, and that Canvas has a AddPoint() method -- this
is a lot of coupling, and will make it hard to re-structure your code in
the future without breaking all sorts of things.
Read up on "The Law of Demeter":
http://en.wikipedia.org/wiki/Law_of_Demeter
In this case, I'd probably have a class derived from wx.Panel that holds
the Canvas (maybe a subclass of NavCanvas). It would have a DrawDot
method. The event binding can happen there too:
self.Canvas.Bind(FC.EVT_LEFT_DOWN, self.OnDrawDot)
Then your OnDrawDot looks like:
def OnDrawDot(self, evt):
...
self.dots.append(self.Canvas.AddPoint(mposcanvas, Diameter=9, Color
= "Red"))
A little cleaner, and also more reusable, this Panel could be put in a
different application structure easily.
-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
[EMAIL PROTECTED]
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas