Hi,
I have heard about wx.CallAfter and recently came across FutureCall.
Can someone explain what these functions do, if possible with a
realistic situation where one would use these function calls?
Thanks,
-Kartic
Hi,
I have heard about wx.CallAfter and recently came across FutureCall.
Can someone explain what these functions do, if possible with a
realistic situation where one would use these function calls?
Thanks,
-Kartic
I have heard about wx.CallAfter and recently came across FutureCall.
Can someone explain what these functions do, if possible with a
realistic situation where one would use these function calls?
The docstrings give a description of what they do...:
help(wx.CallAfter)
Help on function CallAfter in module wx._core:
CallAfter(callable, *args, **kw)
Call the specified function after the current and pending event
handlers have been completed. This is also good for making GUI
method calls from non-GUI threads. Any extra positional or
keyword args are passed on to the callable when it is called.
help(wx.FutureCall)
Help on class FutureCall in module wx._core:
class FutureCall
On 29/09/05, Kartic Krish <kartic0@gmail.com> wrote:
> A convenience class for `wx.Timer`, that calls the given callable
> object once after the given amount of milliseconds, passing any
> positional or keyword args. The return value of the callable is
> availbale after it has been run with the `GetResult` method.
>
> If you don't need to get the return value or restart the timer
> then there is no need to hold a reference to this object. It will
> hold a reference to itself while the timer is running (the timer
> has a reference to self.Notify) but the cycle will be broken when
> the timer completes, automatically cleaning up the wx.FutureCall
> object
###########
It's very rarely a good idea to call GUI functions from any thread
other than the thread running the wxApp MainLoop(). wx.CallAfter is
one way to get around this. For example, you might have some
time-consuming task to complete. You don't want to do it from the
main GUI thread, because the GUI will lock up until the task
completes, so you spawn a worker thread to do the job. The worker
thread could do something like wx.CallAfter(wx.MessageDialog,
'Finished', caption='Job done', style=wx.OK) to pop up a message box
reporting completion.
As for FutureCall --- I haven't used it, but in Tkinter, you can use
the GUI to watch something like this:
def checkThing(self):
if self._checkThing():
# do something
self.after(1000, self.checkThing)
Then just call the method from your __init__ method, and it will run
every 1000 milliseconds as part of the GUI event loop. Something
about the docstring suggests to me that this is not the optimal way to
do things in wx, but I imagine you could finangle something similar.
--
John.