Learning other timer uses

Another way to use the timer, preferable in the case where there's no obvious event target for the timer event, is to subclass wx.Timer. In your subclass you can override the method Notify(). That method is automatically called every time the timer interval passes—in the parent class, it's the Notify() method that triggers the timer event. Your subclass is under no obligation to trigger a timer event, however, and you can do anything you want in the Notify() method to respond to the timer's interval.

To trigger one specific action at some time in the future, there's a shortcut class called wx.FutureCall. Just about the only thing you need to know about wx.FutureCall is in this constructor.

wx.FutureCall(interval, callable, *args, **kwargs)

Once created, the wx.FutureCall instance waits an interval number of milliseconds, then calls the callable object passed to callable using any other positional or keyword arguments, which are passed to the callable using normal Python rules for argument passing. The interval is only triggered once, which is similar to a wx.Timer with oneShot=True. Once you've created the future call instance, you are done. Unless you plan to use the instance again, you don't need to keep a reference to it.

Was this article helpful?

0 0

Post a comment