Ok, thanks to Toni Ruza,
I have a solution to my problem, which could have been stated better. Here is some code that works for me with wxPython 2.8, Python 2.6 on Windows Vista (32-bit).
Best regards.
"""
A simple sample of using a wx.Overlay to recover a bitmap in a window
Suggested by: Toni Ruza
Modifications: V. Stokes
"""
import wx
print wx.version()
class TestPanel(wx.Panel):
def __init__(self, *args, **kw):
wx.Panel.__init__(self, *args, **kw)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.startPos = None
self.overlay = wx.Overlay()
def OnPaint(self, evt):
# Just some simple stuff to paint in the window for an example
dc = wx.PaintDC(self)
dc.SetBackground(wx.Brush("sky blue"))
dc.Clear()
# Draw the first polygon (cyan filled - red border)
dc.SetPen(wx.Pen("red", 2))
dc.SetBrush(wx.CYAN_BRUSH)
coords = ((40,40),(200,220),(210,120),(120,300))
dc.DrawPolygon(coords)
dc.DrawLabel("Left mouse button down -- new polygon\n"+
"release -- erase new polygon",(100, 20, -1, -1))
def OnLeftDown(self, evt):
# Capture the mouse and save the starting posiiton for the
dc = wx.ClientDC(self)
odc = wx.DCOverlay(self.overlay, dc)
odc.Clear()
# Draw the second polygon (green filled - white border)
dc.SetPen(wx.Pen("white", 2))
dc.SetBrush(wx.GREEN_BRUSH)
coords = ((10,50),(100,180),(210,55),(100,280))
dc.DrawPolygon(coords)
def OnLeftUp(self, evt):
# When the mouse is released we reset the overlay and it
# restores the former content to the window.
dc = wx.ClientDC(self)
odc = wx.DCOverlay(self.overlay, dc)
odc.Clear()
del odc
# The following repaints with the bit-map before left mouse button pressed
self.overlay.Reset()
app = wx.App(redirect=False)
frm = wx.Frame(None, title="wx.Overlay Test", size=(450,450))
pnl = TestPanel(frm)
frm.Show()
app.MainLoop()
···
On 03-Feb-2012 01:03, Virgil Stokes wrote:
I have drawn some lines (all of the same color) on a panel with dc.DrawLine(...) that already contains some rectangles, etc. with colors that are different from the color used for the lines. How can I remove these lines and recover the filled rectangles, etc.?
Note, I am very new to wxPython and am using wxPython 2.8 with Python 2.6 on Windows 7 and Windows Vista.