wxPython question
Chris Liechti
cliechti at gmx.net
Sun Nov 17 14:26:44 EST 2002
"joshua solomon" <jslm at earthlink.net> wrote in
news:lNRB9.2743$fY3.294687 at newsread2.prod.itd.earthlink.net:
> Basically I have a loop within the OnPaint handler which I am using
> for bouncing a ball around on a screen.
don't do the loop for the animation in the event handler. do it in a
separate thread nad call Refresh() or us a wxClientDC to draw in that loop
directly.
GUI rule 1: event handlers have to be short (in time)
so no animations and workers. use Threading instead.
> def OnPaint(self,event):
> MyDC=wxPaintDC(self)
>
> MyPen=wxPen('GREEN',1,wxSOLID)
> MyBrush=wxBLUE_BRUSH
>
> MyDC.BeginDrawing()
> MyDC.SetPen(MyPen)
> MyDC.SetBrush(MyBrush)
> if not self.x and not self.y:
> self.x=40
> self.y=40
> MyDC.DrawCircle(self.x,self.y,15)
> self.BounceBall(MyDC)
> MyDC.EndDrawing()
>
> def BounceBall(self,dc):
> import time
> MyPen1=wxPen('GREEN',1,wxSOLID)
> MyBrush1=wxBLUE_BRUSH
> dc.SetPen(MyPen1)
> dc.SetBrush(MyBrush1)
>
> for y in range(1,100):
> dc.SetLogicalFunction(wxCLEAR)
> dc.DrawCircle(self.x,self.y,15)
> self.x+=5
> self.y+=5
> dc.SetLogicalFunction(wxCOPY)
> dc.DrawCircle(self.x,self.y,15)
use time.sleep(0.1) for this:
> t1=time.clock()
> while 1:
> delt=time.clock()-t1
> if delt >=0.1:
> break
what you're doing is heating the CPU with 100% load for nothing but
waiting...
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list