wxPython question
joshua solomon
jslm at earthlink.net
Sun Nov 17 14:06:57 EST 2002
Hi, I hope this is the right place for asking this question. I am running
Python 2.2.2 on Windows 2000
Basically I have a loop within the OnPaint handler which I am using for
bouncing a ball around on a screen. The loop works fine and I have no
problems with that. However my next step is to break out of the loop as soon
as someone presses a key or left clicks the mouse. For this I guess I need
to somehow query the message loop, retrieve any pending events, check to see
if a mouse was clicked and then break out of the loop if it was clicked. My
question is how can I query the message loop and retrieve the necesary
object. If I don't do this, the keypress or mouse click handlers would be
called only after the loop terminates. This has me completely stumped. Is
there a better way to handle this? Any help would be greatly appreciated.
Thanks in advance. The loop and the OnPaint handler appears below although I
don't suppose that is important.
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)
t1=time.clock()
while 1:
delt=time.clock()-t1
if delt >=0.1:
break
More information about the Python-list
mailing list