Having problems with wxPython - HELP!!

Marlin Rowley marlin_rowley at hotmail.com
Fri Apr 25 17:38:13 CEST 2008

I'm desperately spending too much time trying to understand wxPython and it's leading me nowhere.

I'm trying to make a script that will create a window, and then immediately fill this window with a background color.  I also want to be able to fill this window with a background color anytime I need to, therefore I put it in a function called "InitBuffer()".  

Problem 1:  Python doesn't clear the window with "Grey" (my background color) when it is initially created.  Why?  
Problem 2: OnPaint() seems to always get called for whatever reason.  Fine.  But I only want it to refresh the contents of the window.  So, if I draw to the Client window a series of rectangles, the ONLY thing I want OnPaint() to do is refresh what has already been draw to the screen.  The ONLY time it should clear the screen is when I call InitBuffer().  How do I do this?

Here's my code:

# Mental Ray Thread
class runMentalRayThread(threading.Thread):
    def __init__(self,sFile,renderWindow):
        self.filename = sFile
        self.threadID = os.getpid()
        self.renderBuffer = renderWindow
    # poll the file using yet another thread.  When that returns,
    # capture the mental ray stream and render to the canvas.
    def run(self):
        self.portInfo = queryMentalRay(self.filename) 
        scanMR(self.portInfo[0], self.portInfo[1], self)    
# Render Window
class RenderWindow(wx.Window):
    def __init__(self,parent,ID,pos,size):
        self.renderThread = runMentalRayThread(filename,self)
        self.Bind(wx.EVT_IDLE, self.OnIdle)
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
    # Our initial buffer must be set and background cleared.   
    def InitBuffer(self):
        print 'InitBuffer() called...'
    # Idle function.  Wait for a render
    def OnIdle(self,event):
        if not self.renderThread.isAlive():
            print 'Starting thread to poll Mental Ray...'
            self.renderThread = runMentalRayThread(filename,self)
    # Refreshes the window.     
    def OnPaint(self,event):
        print 'OnPaint() called...'
        dc = wx.PaintDC(self)

    # Closing the render window, we need to 
    # kill the thread attached to Mental Ray.     
    def OnClose(self,event):
        if self.renderThread.isAlive():
            # kill the thread
            os.popen("kill -9 "+str(self.renderThread.threadID))

Spell a grand slam in this game where word skill meets World Series. Get in the game.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080425/5370daf9/attachment.html>

More information about the Python-list mailing list