]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _timer.i | |
3 | // Purpose: SWIG interface definitions wxTimer | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 18-June-1999 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | %newgroup | |
18 | ||
19 | enum { | |
20 | // generate notifications periodically until the timer is stopped (default) | |
21 | wxTIMER_CONTINUOUS, | |
22 | ||
23 | // only send the notification once and then stop the timer | |
24 | wxTIMER_ONE_SHOT, | |
25 | }; | |
26 | ||
27 | // Timer event type | |
28 | %constant wxEventType wxEVT_TIMER; | |
66065839 | 29 | |
d14a1e28 RD |
30 | |
31 | //--------------------------------------------------------------------------- | |
32 | ||
33 | ||
34 | %{ | |
a7a01418 | 35 | IMP_PYCALLBACK__(wxPyTimer, wxTimer, Notify); |
66065839 | 36 | |
313feadc | 37 | IMPLEMENT_ABSTRACT_CLASS(wxPyTimer, wxTimer); |
94fd5e4d RD |
38 | |
39 | wxPyTimer::wxPyTimer(wxEvtHandler *owner, int id) | |
40 | : wxTimer(owner, id) | |
41 | { | |
0e859e32 DS |
42 | if (owner == NULL) |
43 | SetOwner(this); | |
94fd5e4d | 44 | } |
d14a1e28 RD |
45 | %} |
46 | ||
47 | ||
ab1f7d2a RD |
48 | MustHaveApp(wxPyTimer); |
49 | ||
1b8c7ba6 RD |
50 | %rename(Timer) wxPyTimer; |
51 | class wxPyTimer : public wxEvtHandler | |
d14a1e28 RD |
52 | { |
53 | public: | |
94fd5e4d RD |
54 | // Don't let the OOR or callback info hold references to the object so |
55 | // there won't be a reference cycle and it can clean itself up via normal | |
56 | // Python refcounting | |
57 | %pythonAppend wxPyTimer | |
c25f90f6 | 58 | "self._setOORInfo(self, 0);" setCallbackInfo(Timer); |
66065839 | 59 | |
0e859e32 DS |
60 | // if you don't call SetOwner() or provide an owner in the ctor |
61 | // then you must override Notify() in order to receive the timer | |
d14a1e28 RD |
62 | // notification. If the owner is set then it will get the timer |
63 | // notifications which can be handled with EVT_TIMER. | |
0e859e32 | 64 | wxPyTimer(wxEvtHandler *owner = NULL, int id = wxID_ANY); |
94fd5e4d RD |
65 | |
66 | // Destructor. | |
d14a1e28 RD |
67 | virtual ~wxPyTimer(); |
68 | ||
c25f90f6 | 69 | void _setCallbackInfo(PyObject* self, PyObject* _class, int incref = 0); |
7722248d | 70 | |
0e859e32 DS |
71 | // Set the owner instance that will receive the EVT_TIMER events |
72 | // using the given id. | |
73 | void SetOwner(wxEvtHandler *owner, int id = wxID_ANY); | |
313feadc | 74 | wxEvtHandler* GetOwner(); |
d14a1e28 RD |
75 | |
76 | // start the timer: if milliseconds == -1, use the same value as for the | |
77 | // last Start() | |
78 | // | |
79 | // it is now valid to call Start() multiple times: this just restarts the | |
80 | // timer if it is already running | |
a72f4631 | 81 | virtual bool Start(int milliseconds = -1, bool oneShot = false); |
d14a1e28 RD |
82 | |
83 | // stop the timer | |
84 | virtual void Stop(); | |
85 | ||
0e859e32 DS |
86 | // override this in your wxTimer-derived class if you need to process timer |
87 | // messages in it; otherwise, use non-default ctor or call SetOwner() | |
a7a01418 | 88 | virtual void Notify(); |
d14a1e28 | 89 | |
dd9f7fea | 90 | // return True if the timer is running |
d14a1e28 RD |
91 | virtual bool IsRunning() const; |
92 | ||
0e859e32 | 93 | // get the (last) timer interval in milliseconds |
d14a1e28 RD |
94 | int GetInterval() const; |
95 | ||
0bdc5dd6 RD |
96 | // return the timer ID |
97 | int GetId() const; | |
66065839 | 98 | |
0e859e32 DS |
99 | // return True if the timer is one shot |
100 | bool IsOneShot() const; | |
101 | ||
94fd5e4d | 102 | %pythoncode { |
4bbf373b | 103 | def Destroy(self): |
0e859e32 | 104 | """NO-OP: Timers must be destroyed by normal reference counting""" |
94fd5e4d RD |
105 | pass |
106 | } | |
994453b8 RD |
107 | |
108 | %property(Id, GetId, doc="See `GetId`"); | |
109 | %property(Interval, GetInterval, doc="See `GetInterval`"); | |
110 | %property(Owner, GetOwner, SetOwner, doc="See `GetOwner` and `SetOwner`"); | |
d14a1e28 RD |
111 | }; |
112 | ||
113 | ||
66065839 | 114 | %pythoncode { |
d14a1e28 RD |
115 | %# For backwards compatibility with 2.4 |
116 | class PyTimer(Timer): | |
117 | def __init__(self, notify): | |
118 | Timer.__init__(self) | |
119 | self.notify = notify | |
120 | ||
121 | def Notify(self): | |
122 | if self.notify: | |
123 | self.notify() | |
124 | ||
125 | ||
126 | EVT_TIMER = wx.PyEventBinder( wxEVT_TIMER, 1 ) | |
66065839 | 127 | |
d14a1e28 RD |
128 | }; |
129 | ||
130 | ||
131 | ||
132 | class wxTimerEvent : public wxEvent | |
133 | { | |
134 | public: | |
135 | wxTimerEvent(int timerid = 0, int interval = 0); | |
136 | int GetInterval() const; | |
994453b8 RD |
137 | |
138 | %property(Interval, GetInterval, doc="See `GetInterval`"); | |
d14a1e28 RD |
139 | }; |
140 | ||
141 | ||
142 | ||
143 | // wxTimerRunner: starts the timer in its ctor, stops in the dtor | |
ab1f7d2a | 144 | MustHaveApp(wxTimerRunner); |
d14a1e28 RD |
145 | class wxTimerRunner |
146 | { | |
147 | public: | |
148 | %nokwargs wxTimerRunner; | |
149 | wxTimerRunner(wxTimer& timer); | |
a72f4631 | 150 | wxTimerRunner(wxTimer& timer, int milli, bool oneShot = false); |
d14a1e28 RD |
151 | ~wxTimerRunner(); |
152 | ||
a72f4631 | 153 | void Start(int milli, bool oneShot = false); |
d14a1e28 RD |
154 | }; |
155 | ||
156 | ||
157 | //--------------------------------------------------------------------------- | |
313feadc RD |
158 | %init %{ |
159 | wxPyPtrTypeMap_Add("wxTimer", "wxPyTimer"); | |
160 | %} | |
161 | //--------------------------------------------------------------------------- |