A few wxPython questions

Duncan Smith buzzard at urubu.freeserve.co.uk
Fri Feb 15 12:39:40 EST 2002


Hopefully these are relatively straightforward and don't require me to post
too much code (Win 2000, Python 2.0, wxPython 2.2.5):

How can I create a wxBitmap which picks up the background colour of my
panel?  Currently I can (apparently) set it to white by using dc.Clear() as
below, but that's not really what I need.

Before I tried double buffering my drawing would resize on a panel resize
without a problem.  But this no longer happens.  On minimising the panel the
drawing remains the same size, but the lines are much heavier.  (I'm sure
the answer to this is obvious, but I just can't see it.  Should I be
deleting something somewhere?)  Ropy code below.  Thanks in advance.

Duncan Smith


    def OnToolbar1tools2Tool(self, event):
        (x, y) = self.GetClientSizeTuple()
        temp_dc = self.GetDC()
        temp_dc.SetUserScale(x/self.width, y/self.height)
                                                    #original panel height
and width
        *Draws something to temp_dc*
        self.OnDraw(temp_dc)

    def GetDC(self):
        (x, y) = self.GetClientSizeTuple()
        bmp = wxEmptyBitmap(x, y)
        temp_dc = wxMemoryDC()
        temp_dc.SelectObject(bmp)
        temp_dc.Clear()

        return temp_dc

    def OnDraw(self, temp_dc, dc=0):
        if not dc:
            dc = wxClientDC(self.panel1)
        (x, y) = self.GetClientSizeTuple()
        dc.Blit(0,0, x, y, temp_dc, 0,0)






More information about the Python-list mailing list