wx.Timer¶
The wx.Timer class allows you to execute code at specified intervals.
Its precision is platform-dependent, but in general will not be better than 1ms nor worse than 1s .
There are three different ways to use this class:
You may derive a new class from wx.Timer and override the
wx.Timer.Notifymember to perform the required action.You may redirect the notifications to any wx.EvtHandler derived object by using the non-default constructor or
wx.Timer.SetOwner. Then use theEVT_TIMERmacro to connect it to the event handler which will receive wx.TimerEvent notifications.You may use a derived class and the
EVT_TIMERmacro to connect it to an event handler defined in the derived class. If the default constructor is used, the timer object will be its own owner object, since it is derived from wx.EvtHandler.
In any case, you must start the timer with wx.Timer.Start after constructing it before it actually starts sending notifications. It can be stopped later with wx.Timer.Stop .
Note
A timer can only be used from the main thread.
See also
Class Hierarchy¶
Methods Summary¶
Default constructor. |
|
Returns the |
|
Returns the current interval for the timer (in milliseconds). |
|
Returns the current owner of the timer. |
|
Returns |
|
Returns |
|
This member should be overridden by the user if the default constructor was used and |
|
Associates the timer with the given owner object. |
|
(Re)starts the timer. |
|
Starts the timer for a once-only notification. |
|
Stops the timer. |
Properties Summary¶
See |
|
See |
|
Class API¶
- class wx.Timer(EvtHandler)¶
Possible constructors:
Timer() -> None Timer(owner, id=-1) -> None
The Timer class allows you to execute code at specified intervals.
Methods¶
- __init__(self, *args, **kw)¶
-
__init__ (self)
Default constructor.
If you use it to construct the object and don’t call
SetOwnerlater, you must overrideNotifymethod to process the notifications.- Return type:
None
__init__ (self, owner, id=-1)
Creates a timer and associates it with owner.
Please see
SetOwnerfor the description of parameters.- Parameters:
owner (wx.EvtHandler)
id (int)
- Return type:
None
- GetId(self)¶
Returns the
IDof the events generated by this timer.- Return type:
int
- GetInterval(self)¶
Returns the current interval for the timer (in milliseconds).
- Return type:
int
- GetOwner(self)¶
Returns the current owner of the timer.
If not
Nonethis is the event handler which will receive the timer events (see wx.TimerEvent) when the timer is running.- Return type:
- IsOneShot(self)¶
Returns
Trueif the timer is one shot, i.e. if it will stop after firing the first notification automatically.- Return type:
bool
- IsRunning(self)¶
Returns
Trueif the timer is running,Falseif it is stopped.- Return type:
bool
- Notify(self)¶
This member should be overridden by the user if the default constructor was used and
SetOwnerwasn’t called.Perform whatever action which is to be taken periodically here.
Notice that throwing exceptions from this method is currently not supported, use event-based timer handling approach if an exception can be thrown while handling timer notifications.
- Return type:
None
- SetOwner(self, owner, id=-1)¶
Associates the timer with the given owner object.
When the timer is running, the owner will receive timer events (see wx.TimerEvent) with
idequal toidspecified here.- Parameters:
owner (wx.EvtHandler)
id (int)
- Return type:
None
- Start(self, milliseconds=-1, oneShot=TIMER_CONTINUOUS)¶
(Re)starts the timer.
If milliseconds parameter is -1 (value by default), the previous value is used. Returns
Falseif the timer could not be started,Trueotherwise (in MS Windows timers are a limited resource).If oneShot is
False(the default), theNotifyfunction will be called repeatedly until the timer is stopped. IfTrue, it will be called only once and the timer will stop automatically.To make your code more readable you may also use the following symbolic constants:
wx.TIMER_CONTINUOUS: Start a normal, continuously running, timerwx.TIMER_ONE_SHOT: Start a one shot timer Alternatively, useStartOnce.
If the timer was already running, it will be stopped by this method before restarting it.
- Parameters:
milliseconds (int)
oneShot (bool)
- Return type:
bool
- StartOnce(self, milliseconds=-1)¶
Starts the timer for a once-only notification.
This is a simple wrapper for
StartwithTIMER_ONE_SHOTparameter.- Parameters:
milliseconds (int)
- Return type:
bool
Added in version 2.9.5.
- Stop(self)¶
Stops the timer.
- Return type:
None
Properties¶
- Interval¶
See
GetInterval
