Drawing in a bitmap, displaying in EVT_PAINT event

Hi, I'm trying to paint on a panel using a MemoryDC and display the
bitmap using a PaintDC in a EVT_PAINT event handler. My goal is to
have some black lines on the normal panel background color. However,
this code only produces a black panel. I'm sure there's something
simple I'm doing wrong, but I can't find it. I've whipped up this test
class that demonstrates what I'm doing:

# begin WXPaint.py
import wx

class WXPaint:
    def __init__(self):
        self.createGUI()
        self.paintMem()

    def createGUI(self):
        self.app = wx.PySimpleApp()

        self.sizer = wx.GridBagSizer()
        self.frame = wx.Frame(None, -1, 'WXPaint')
        self.panel = wx.Panel(self.frame, 1, size=(301,301))

        self.bitmap = wx.EmptyBitmap(300, 300, 1)
        self.memdc = wx.MemoryDC()
        self.memdc.SelectObject(self.bitmap)
        self.mirdc = wx.MirrorDC(self.memdc, True)

        self.sizer.Add(self.panel, pos=(0,0))

        wx.EVT_PAINT(self.frame, self.onPaint)

        self.frame.SetSizer(self.sizer)
        self.frame.SetAutoLayout(True)
        self.sizer.Fit(self.frame)

        self.frame.Show()

    def paintMem(self):
        coords = (20, 20, 20, 40)
        self.memdc.SetTextForeground('white')
        self.memdc.DrawLine(*coords)
        self.mirdc.DrawLine(*coords)

    def onPaint(self, event=None):
        paintdc = wx.PaintDC(self.panel)
        paintdc.Blit(0, 0, 300, 300, self.memdc, 0, 0, wx.COPY, useMask=False)
        event.Skip()

if __name__ == '__main__':
    gui = WXPaint()
    gui.app.MainLoop()

# end WXPaint.py

Thanks for any help.

Joost Molenaar

Hello Joost:

Yes, the problem is trivial. Just add this one line

       self.memdc.SetTextForeground('white')
       self.memdc.Clear()
       self.memdc.DrawLine(*coords)

···

On 9/29/05, Joost Molenaar <dzjoost@gmail.com> wrote:

Hi, I'm trying to paint on a panel using a MemoryDC and display the
bitmap using a PaintDC in a EVT_PAINT event handler. My goal is to
have some black lines on the normal panel background color. However,
this code only produces a black panel. I'm sure there's something
simple I'm doing wrong, but I can't find it. I've whipped up this test
class that demonstrates what I'm doing:

# begin WXPaint.py
import wx

class WXPaint:
    def __init__(self):
        self.createGUI()
        self.paintMem()

    def createGUI(self):
        self.app = wx.PySimpleApp()

        self.sizer = wx.GridBagSizer()
        self.frame = wx.Frame(None, -1, 'WXPaint')
        self.panel = wx.Panel(self.frame, 1, size=(301,301))

        self.bitmap = wx.EmptyBitmap(300, 300, 1)
        self.memdc = wx.MemoryDC()
        self.memdc.SelectObject(self.bitmap)
        self.mirdc = wx.MirrorDC(self.memdc, True)

        self.sizer.Add(self.panel, pos=(0,0))

        wx.EVT_PAINT(self.frame, self.onPaint)

        self.frame.SetSizer(self.sizer)
        self.frame.SetAutoLayout(True)
        self.sizer.Fit(self.frame)

        self.frame.Show()

    def paintMem(self):
        coords = (20, 20, 20, 40)
        self.memdc.SetTextForeground('white')
        self.memdc.DrawLine(*coords)
        self.mirdc.DrawLine(*coords)

    def onPaint(self, event=None):
        paintdc = wx.PaintDC(self.panel)
        paintdc.Blit(0, 0, 300, 300, self.memdc, 0, 0, wx.COPY, useMask=False)
        event.Skip()

if __name__ == '__main__':
    gui = WXPaint()
    gui.app.MainLoop()

# end WXPaint.py

Thanks for any help.

Joost Molenaar

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

D'oh! Thanks a lot!

Slapping-himself-on-the-forehead-for-not-trying-1-hour-more,
Joost

···

On 9/29/05, Michael Moriarity <*snip*@*snip*.com> wrote:

Hello Joost:

Yes, the problem is trivial. Just add this one line

      self.memdc.SetTextForeground('white')
      self.memdc.Clear()
      self.memdc.DrawLine(*coords)

On 9/29/05, Joost Molenaar <*snip*@*snip*.com> wrote:
> *snip*