Having problems with wxPython - HELP!!

Marlin Rowley marlin_rowley at hotmail.com
Fri Apr 25 11:38:13 EDT 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):
        threading.Thread.__init__(self)
        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) 
        self.renderBuffer.InitBuffer()                      
        scanMR(self.portInfo[0], self.portInfo[1], self)    
        
# Render Window
class RenderWindow(wx.Window):
    def __init__(self,parent,ID,pos,size):
        wx.Window.__init__(self,parent,ID,pos,size)
        self.renderThread = runMentalRayThread(filename,self)
        self.SetBackgroundColour("Grey")
        self.Bind(wx.EVT_IDLE, self.OnIdle)
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.InitBuffer()
     
    # Our initial buffer must be set and background cleared.   
    def InitBuffer(self):
        print 'InitBuffer() called...'
        self.ClearBackground()
       
    # 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)
            self.renderThread.start()
       
    # 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.
http://club.live.com/word_slugger.aspx?icid=word_slugger_wlhm_admod_april08
-------------- 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