I would like to point out that in my original posting there was a logical
bug in the code (also in the code posted by Chris).
odd -- it seemed to work fine -- though maybe I didn't know what is
was supposed to do.
I have now corrected this logic error, incorporated some of Chris Barker's
changes, done some minor refactoring, and tried to improve the comments. To
the wx.Python newbie (as I am), I strongly suggest that you experiment with
this code (e.g. uncomment self.overlay.Reset(), add more cells to the cell
grid, etc.)
well, this version crashes on the Mac -- darn! Ideally, that should
never happen, so it is a bug in wxPython -- but there should be a way
for it to work everywhere -- on to the debugging!
1) line 55:
self.dcC = wx.ClientDC(self)
may be the source of the problem -- DCs are not designed to be
persisted -- you create one, draw with it, then delete it (or let
python delete it). So the ClientDC should be created when you need to
draw to the overlay -- i.e. in onMOuseMove.
2) lines 115 - 117:
odc = wx.DCOverlay(self.overlay, self.dcC)
odc.Clear()
del odc # not sure if this is necessary(?)
I think you stil need the DCOverlay here -- in fact, deleting it here
is what's causing the crash on OS-X.
Though I'm confused -- we end up drawing to the wxClientDC - shouldn't
we be drawing to the Overlay? It looks like my mental model is wrong
here. Rather than there being a transparent overlay bitmap -- all
wxOverlay does is cache the Window contents, then you draw to the
ClientDC anyway. However, it's a bit different, as somehow what's been
draw to teh overlay stays there after Paint Events --a t least on The
Mac.
Try this on Windows:
1) re-size the Window to be smaller that the image -- so the edge of
the Window overlaps the right hand box.
2) move the mouse into the right box -- it should get highlighted
3) grab the corner of the window to resize it -- you never left the
box, so it shoujld stay highlighted.
4) the re-size causes Paint Events -- on my machine, the highlight
remains thought the Paint events -- but only on the part of the
rectangle that was exposed with the smaller window -- so the overlay
is persisting.
Is it the same on Windows?
To do this right, you'd need to bind the re-size events, and redraw
the overlay as well -- or, maybe better catch mouse leave event, and
clear the overlay there.
Anyway, I think the cause of the confusion is that Tim's explanation
of the implementation shifted focus away from the intent and API of an
Overlay -- which his really what you should be thinking about. The
intent is to have a surface that "overlays" the window on which you
can draw temporary stuff without having to re-draw the entire window
when that temporary stuff changes -- this is well suited to drawing
stuff that only exists on mouse mouse events, etc. -- your example
isn't quite that -- it is more like drawing the selection indicators
in a GUI -- which makes sense too -- the selection can change quickly,
and you may not want to re-draw the entire background each time.
So I think of an overlay as a clear piece of plastic sitting on top of
the window.
When you want to draw something, do you want to draw to that clear
layer on top, or draw to the main picture underneath? If the layer on
top, you use Overlay, if not then a regular ClientDC.
wx.DCOverlay.clear() does just what you'd think -- clears off that
clear piece of plastic, so you can draw something new on it. The rest
of the regular DC drawing functions draw to the clear piece of
plastic.
Though It seems I still don't have it quite right.
Updated code enclosed does this work on Windows?
-Chris
OverlayTest3.py (5.8 KB)
···
On Fri, Feb 10, 2012 at 2:36 AM, Virgil Stokes <vs@it.uu.se> wrote:
Best regards and thanks for the help/suggestions 
--V
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
--
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