Drawing outside of an event handler wx.EVT_PAINT

ioprst <[email protected]> Wed, 9 Dec 2020 03:30:35 -0800 (PST)
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
I need to draw a grid in the cells of which images will be located 
(wx.Bitmap).

When you click on a cell, the cursor (orange square) should draw above it.

Since the wx.EVT_PAINT handler will need to draw quite a lot, it was 
decided to draw the cursor using wx.ClientDC, when the user selects a cell, 
and through wx.PaintDC, when the full redraw is called (self.DrawCursor(dc) 
in OnPaint).

My problem is that when I draw a new cursor, the old one is not removed 
until the wx.EVT_PAINT handler is called.

Using self.SetDoubleBuffered (True) solves my problem, but it results in 
the wx.EVT_PAINT handler being called every time the cell is clicked, which 
leads to a large extra computational cost, since I only need to redraw the 
cursor (and the function draw cursor is called twice).

If I draw only through wx.ClientDC (that is, self.DrawCursor(None) in 
OnPaint), then I get overlapping cursors when scrolling the window, and the 
old cursor is not deleted when completely redrawn.

Can you please tell me if there is a correct solution to my problem?

Code: https://ideone.com/6jKSnV

-- 
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 [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/077be554-b7d0-4184-af9d-17a2b89588abn%40googlegroups.com.