drawing lines

On Tue, 11 Jul 2006 16:15:45 +0100, "Gabriel Murray"
<gabriel.murray@gmail.com> wroite:

As a follow-up on this, I've changed the code slighly here, but am
still not able to get lines drawn to the screen. Am I using the wrong
type of dc? I've not tried to draw lines with wxPython before, so am
really not sure.

###########

class SketchWindow(wx.Window):
    def __init__(self, parent, ID):
        wx.Window.__init__(self, parent, ID, size=(250,500))
        self.SetBackgroundColour("Red")
        self.color = "White"
        self.thickness = 1
        self.pen = wx.Pen(self.color, self.thickness, wx.SOLID)
        size = self.GetClientSize()
        self.buffer = wx.EmptyBitmap(size.width, size.height)
        dc = wx.BufferedDC(None, self.buffer)
        self.PrepareDC(dc)
        dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
        dc.Clear()
        dc.BeginDrawing()
        coords = [(12,13,12,14), (12,14,12,15), (12,15,12,16),
(13,16,13,17), (14,17,14,18)]
        dc.SetPen(self.pen)
        dc.DrawText('hello world', 60,65)
        for eachcoord in coords:
            dc.DrawLine(*eachcoord)
        dc.EndDrawing()

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

There are two problems. First, you're doing the drawing in the
constructor, which runs before the window is drawn. After the
constructor runs, the "erase background" message comes in and blasts red
across the whole screen, including your changes. After the "self.pen"
creation, insert a couple of lines:

        ...
        self.pen = wx.Pen( self.color, self.thickness, wx.SOLID)
        self.Bind( wx.EVT_PAINT, self.OnPaint )

    def OnPaint( self, evt ):
        size = self.GetClientSize()
        self.buffer = wx.EmptyBitmap(size.width, size.height)
        dc = wx.BufferedPaintDC( self, self.buffer ) # note two
changes on this line
        ....

Next, those "lines" are actually pixels -- exactly one dot each. Is
that really what you intended?

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.