Cédric Boudinet wrote:
>
> I am using custom event in a wxpython gui but I encounter problems
> with unit test.
> Please find enclosed my example codes.
> In my example, when the users clicks on the button, MyWidget posts a
> custom event. This event is caught by the main frame and the label is
> set to 'Event Ok'.
> This works fine, when the script is launched by the user.
>
> However when launched in the unittest (python setup.py test), the
> result is as follows:
> ...
>
> The line test0 (testgui.Tests_GUI) ... event send means that when the
> EVT_COMMAND_BUTTON_CLICKED is processed, OnButton is called and the
> custom event posted.
> However, the fact that the tests fails means that the custom event is
> not caught by the main frame.
No, actually, that's not what it means. The custom event IS being sent,
but you used PostEvent, which puts the message in the message queue, to
be handled by the main loop. But you never give the app a chance to get
back to the main loop, so the event is still in the queue when you check
the label. Your "time.sleep(1) call is just blocking the whole UI --
nothing can happen while you are sleeping
Change the "time.sleep(1)" to a "wx.Yield()" (which allows the main loop
to run), and you'll see it is working just fine.
--
Tim Roberts,
ti...@probo.com
Providenza & Boekelheide, Inc.