<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'><div style="text-align: left;">I'm desperately spending too much time trying to understand wxPython and it's leading me nowhere.<br><br>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()".  <br><br>Problem 1:  Python doesn't clear the window with "Grey" (my background color) when it is initially created.  Why?  <br>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?<br><br><br>Here's my code:<br><br># Mental Ray Thread<br>class runMentalRayThread(threading.Thread):<br>    def __init__(self,sFile,renderWindow):<br>        threading.Thread.__init__(self)<br>        self.filename = sFile<br>        self.threadID = os.getpid()<br>        self.renderBuffer = renderWindow<br>        <br>    # poll the file using yet another thread.  When that returns,<br>    # capture the mental ray stream and render to the canvas.<br>    def run(self):<br>        self.portInfo = queryMentalRay(self.filename) <br>        self.renderBuffer.InitBuffer()                      <br>        scanMR(self.portInfo[0], self.portInfo[1], self)    <br>        <br># Render Window<br>class RenderWindow(wx.Window):<br>    def __init__(self,parent,ID,pos,size):<br>        wx.Window.__init__(self,parent,ID,pos,size)<br>        self.renderThread = runMentalRayThread(filename,self)<br>        self.SetBackgroundColour("Grey")<br>        self.Bind(wx.EVT_IDLE, self.OnIdle)<br>        self.Bind(wx.EVT_CLOSE, self.OnClose)<br>        self.Bind(wx.EVT_PAINT, self.OnPaint)<br>        self.InitBuffer()<br>     <br>    # Our initial buffer must be set and background cleared.   <br>    def InitBuffer(self):<br>        print 'InitBuffer() called...'<br>        self.ClearBackground()<br>       <br>    # Idle function.  Wait for a render<br>    def OnIdle(self,event):<br>        if not self.renderThread.isAlive():<br>            print 'Starting thread to poll Mental Ray...'<br>            self.renderThread = runMentalRayThread(filename,self)<br>            self.renderThread.start()<br>       <br>    # Refreshes the window.     <br>    def OnPaint(self,event):<br>        print 'OnPaint() called...'<br>        dc = wx.PaintDC(self)<br>        <br><br>    # Closing the render window, we need to <br>    # kill the thread attached to Mental Ray.     <br>    def OnClose(self,event):<br>        if self.renderThread.isAlive():<br>            # kill the thread<br>            os.popen("kill -9 "+str(self.renderThread.threadID))<br></div><br /><hr />Spell a grand slam in this game where word skill meets World Series. <a href='http://club.live.com/word_slugger.aspx?icid=word_slugger_wlhm_admod_april08' target='_new'>Get in the game.</a></body>
</html>