[wxPython-users] buffered dc

Gabriel Murray gabriel.murray at gmail.com
Fri Jul 14 04:31:33 PDT 2006


Ah okay - I realized after looking at doodle.py that I was writing all my
lines in the OnPaint() method rather than in a separate DrawLines() method.
I've tried to alter my code to look like doodle.py's structure, but now am
not getting any output at all. This is supposed to be a small box with a red
background and half of it painted light blue. It seems that the error is
coming from the DrawLines() method but I don't see what it is.
Gabriel

###########
import wx


class MyPanel(wx.Panel):
    def __init__(self,parent,id):
        wx.Panel.__init__(self,parent,id,size=3D(250,500))

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'Global Context', size=3D(250,500=
))
        self.panel =3D MyPanel(self,-1)
        self.SetBackgroundColour("Red")
        self.InitBuffer()
        self.panel.Bind(wx.EVT_PAINT, self.onPaint)


    def InitBuffer(self):
        size =3D self.GetClientSize()
        self.buffer =3D wx.EmptyBitmap(size.width, size.height)
        dc =3D wx.BufferedDC(None, self.buffer)
        dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
        dc.Clear()
        self.DrawLines(dc)
        self.reInitBuffer =3D False

    def DrawLines(self, dc):

        dc.BeginDrawing()

        y =3D 1
        while y < 250:
            self.pen =3D wx.Pen('Light Blue', 3, wx.SOLID)
            dc.SetPen(self.pen)
            x =3D 0
            coords =3D []
            while x < 251:
                coords.append((x,y,x+1,y+1))
                x +=3D 1

            for eachcoord in coords:
                dc.DrawLine(*eachcoord)

            y +=3D 1
        dc.EndDrawing()

    def OnPaint(self,event):
        dc =3D wx.BufferedPaintDC(self, self.buffer)


app =3D wx.PySimpleApp(redirect=3D'True')

frm =3D MyFrame()
frm.SetSize((250,500))
frm.Show()

app.SetTopWindow(frm)
app.MainLoop()

########################
###########################


On 7/13/06, Christopher Barker <Chris.Barker at noaa.gov> wrote:
>
> Robin Dunn wrote:
> > Please look at the
> > doodle sample or items in the demo that use a a buffered DC.
>
> Also take a look at:
>
> http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing
>
> -Chris
>
>
>
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> NOAA/OR&R/HAZMAT         (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker at noaa.gov
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200607=
14/abed61a7/attachment.htm


More information about the wxpython-users mailing list