wxPython fast and slow

Mike Driscoll kyosohma at gmail.com
Sun Mar 8 09:22:22 EDT 2009


On Mar 8, 3:52 am, iu2 <isra... at elbit.co.il> wrote:
> On Mar 6, 6:52 pm, Mike Driscoll <kyoso... at gmail.com> wrote:
>
> > ...
> > Can you post a sample application so we can try to figure out what's
> > wrong? You might also cross-post this to thewxPythonmailing list.
> > They might know.
>
> > Mike- Hide quoted text -
>
> > - Show quoted text -
>
> Hi, thanks for your reply
>
> Here is a sample application:
>
> ----------------------------------------------------------
>
> import wx
> import time
>
> class My_frame(wx.Frame):
>     def __init__(self):
>         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))
>         self.square.Bind(wx.EVT_PAINT, self.on_paint_square)
>
>         btn_move = wx.Button(p, -1, 'Move panel', pos=(0, 0))
>         self.Bind(wx.EVT_BUTTON, self.move_panel, btn_move)
>
>         self.Fit()
>
>     def move_panel(self, evt):
>         def gen():
>             for x in range(200):
>                 yield x
>             for x in range(200, 0, -1):
>                 yield x
>         for x in gen():
>             self.square.SetPosition((x, 30))
>             time.sleep(0.005)
>
>     def on_paint_square(self, evt):
>         square = evt.GetEventObject()
>         dc = wx.BufferedPaintDC(square)
>         dc.Pen = wx.Pen('blakc', 2)
>         dc.Brush = wx.Brush('light blue')
>         dc.DrawRectangle(0, 0, *square.GetSize())
>
> app = wx.PySimpleApp()
> My_frame().Show()
> app.MainLoop()
>
> ----------------------------------------------------------
>
> Press the button and the panel moves to the right and then back to the
> left.
> While PyScripter is running the panel moves at a certain speed. You
> can run the application from the Windows explorer with the same speed.
> You don't need to run it from PyScripter.
> When PyScripter is closed, the application runs much less quickly.
> I experienced this on two PC-s.
> Maybe this behavior is not even related to wxPython but to the sleep
> command. I don't know...
>
> Thanks
> iu2

You probably want to use wx.Timer rather than using time.sleep. You
could use wx.Sleep() too. I don't really understand why you're doing
what you're doing though. Did you re-post to the wxPython group?

Mike



More information about the Python-list mailing list