first:
Trying to draw rectangle with mouse on top of StaticBitmap.
main flow:
mouse left click - set start coordinates
mouse move - draw new rectangle on top of static bitmap, current code:
dc = MemoryDC()
bitmap = self.bitmap
bitmap = bitmap.GetSubBitmap(Rect(0,0, bitmap.GetWidth(),
bitmap.GetHeight()))
you're getting a sub-bit map that is the whole thing?
I'd probably do:
bitmap = wx.EmptyBitmap( self.bitmap.GetWidth(), self.bitmap.GetHeight()
bdc.SelectObject( bitmap)
bdc.DrawBitmap(self.bitmap)
...
It's not surprising that it's laggy -- you're doing a hell of a lot of work
there in response to each mouse move message, and those can happen hundreds
of times per second. A better solution would be to have your mouse move
handler just remember that the coordinates changed, and do the drawing
somewhere else.
you may want to use a wx.Overlay for this sort of thing (see enclosed
for a sample)
But I'm still surprised that this is slow -- is this a really big bitmap?
A hint -- StaticBitmap is generally used for what it sounds like,
bitmaps that don't change, and ar generally small, icons and the like.
If you are working with somethign that manipulates bitmaps, etc, I
suspect you would be better off with a custom wx.Window that renders
the bitmap, and does whatever else.
What is your use-case?
-Chris
Overlaytest2.py (2.99 KB)
···
Do you really need the rectangle stored in a static bitmap? Can't you just
refresh the bitmap and draw the rectangle directly on the screen?
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
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