wxPython fast and slow
Scott David Daniels
Scott.Daniels at Acm.Org
Sun Mar 8 23:44:38 CET 2009
> Here is the timer version. It works even more slowly, even with
> PyScripter active: ...
> I actually tried this one first. Due to the slow speed I changed to
> looping inside the event.
> I don't understand why it takes so long to move that square with
> wx.Timer set to 1 ms interval. Perhaps its minimum interval is
> actually 10 ms (as in Windows) so 100 steps really take 1 second.
> But in that case, I really want to move the square in a tight loop
> inside the wx.EVT_BUTTON event.
> So allow me to rephrase my question:
> Is there a way to move that square quickly and smoothly? Should 400
> one-pixel moves should take so long on a 2.8 GHz core duo?
> There is certainly something wrong in the code I wrote which I need
> your help to figure out.
> Can it be related to recurring paint events? If so how should I change
> the code?
Here is a too-fast version you could fiddle around with:
wx.Frame.__init__(self, None, -1, 'Moving panel')
self.surface = p = wx.Panel(self, size=(300, 130))
self.square = wx.Panel(p, -1, size=(100, 100), pos=(0, 30))
btn_move = wx.Button(p, -1, 'Move panel', pos=(0, 0))
self.Bind(wx.EVT_BUTTON, self.startcalls, btn_move)
def startcalls(self, evt=None):
for x in range(200):
for x in range(200, 0, -1):
self.track = gen().next
def stepcall(self, evt=None):
x = self.track()
def on_paint_square(self, evt):
square = evt.GetEventObject()
dc = wx.BufferedPaintDC(square)
dc.Pen = wx.Pen('black', 2)
dc.Brush = wx.Brush('light blue')
dc.DrawRectangle(0, 0, *square.GetSize())
if __name__ == '__main__':
app = wx.PySimpleApp()
More information about the Python-list