On Wed, Dec 9, 2009 at 10:21 PM, Frank Millman <span dir="ltr"><<a href="mailto:frank@chagford.com">frank@chagford.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">Wanderer wrote:<br>
<br>
>I have a wxPython program which does some calculations and displays<br>
> the results. During these calculations if I click the mouse inside the<br>
> dialog the program locks up. If I leave the dialog alone the process<br>
> completes fine. I have tried running the function from a separate<br>
> dialog with Show Modal and I have tried using SetEvtHandlerEnabled all<br>
> to no avail. The program is long and occupies several files so I won't<br>
> show the whole thing but here is the calculation part. How do I block<br>
> events?<br>
><br>
<br>
</div>I also need to block events in my wxPython app, though the time duration is<br>
very short. I have a separate thread that sends notification of gui events<br>
to a server, and waits for a response. I do not want the user to do anything<br>
until the response is received.<br>
<br></blockquote><div><br></div><div>I don't think "blocking" events is the right way to think about this.</div><div><br></div><div>If you need to halt new input for some reason (bearing in mind that its best to run such things in a background task, but yes, sometimes blocking the UI is important), then there's a couple ways to go about it. But trying to mess with the event loop isn't it.</div>
<div><br></div><div>First, you always want a visual indicator-- use SetCursor on your top level window to set a busy cursor. You never want any sort of block-ish action to happen without the user being able to see "something is going on"; if its more then a second or so I /really/ think you should throw up a progress indicator dialog, even if its an infinate one.</div>
<div> </div><div>To actually 'block' the events themselves, you can just call wnd.Enable(False). Just be sure to Enable(True) when you want to process stuff again.</div><div><br></div><div>Another approach is to use wnd.CaptureMouse() on a particular control which doesn't really respond to anything. Just be sure to ReleaseMouse() later and follow the instructions in the docs about capturing that cancel-capture event.</div>
<div><br></div><div>HTH,</div></div><div name="mailplane_signature">--S</div>