]>
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 | } |
b7681018 VZ |
45 | |
46 | wxPyTimer::~wxPyTimer() | |
47 | { | |
48 | // printf("-=* ~wxPyTimer\n"); | |
49 | } | |
50 | ||
d14a1e28 RD |
51 | %} |
52 | ||
53 | ||
ab1f7d2a RD |
54 | MustHaveApp(wxPyTimer); |
55 | ||
1b8c7ba6 RD |
56 | %rename(Timer) wxPyTimer; |
57 | class wxPyTimer : public wxEvtHandler | |
d14a1e28 RD |
58 | { |
59 | public: | |
94fd5e4d RD |
60 | // Don't let the OOR or callback info hold references to the object so |
61 | // there won't be a reference cycle and it can clean itself up via normal | |
62 | // Python refcounting | |
63 | %pythonAppend wxPyTimer | |
b7681018 | 64 | "self._setOORInfo(self,0); self.this.own(True); " setCallbackInfo(Timer); |
66065839 | 65 | |
0e859e32 DS |
66 | // if you don't call SetOwner() or provide an owner in the ctor |
67 | // then you must override Notify() in order to receive the timer | |
d14a1e28 RD |
68 | // notification. If the owner is set then it will get the timer |
69 | // notifications which can be handled with EVT_TIMER. | |
0e859e32 | 70 | wxPyTimer(wxEvtHandler *owner = NULL, int id = wxID_ANY); |
94fd5e4d RD |
71 | |
72 | // Destructor. | |
d14a1e28 RD |
73 | virtual ~wxPyTimer(); |
74 | ||
c25f90f6 | 75 | void _setCallbackInfo(PyObject* self, PyObject* _class, int incref = 0); |
7722248d | 76 | |
0e859e32 DS |
77 | // Set the owner instance that will receive the EVT_TIMER events |
78 | // using the given id. | |
79 | void SetOwner(wxEvtHandler *owner, int id = wxID_ANY); | |
313feadc | 80 | wxEvtHandler* GetOwner(); |
d14a1e28 RD |
81 | |
82 | // start the timer: if milliseconds == -1, use the same value as for the | |
83 | // last Start() | |
84 | // | |
85 | // it is now valid to call Start() multiple times: this just restarts the | |
86 | // timer if it is already running | |
a72f4631 | 87 | virtual bool Start(int milliseconds = -1, bool oneShot = false); |
d14a1e28 RD |
88 | |
89 | // stop the timer | |
90 | virtual void Stop(); | |
91 | ||
0e859e32 DS |
92 | // override this in your wxTimer-derived class if you need to process timer |
93 | // messages in it; otherwise, use non-default ctor or call SetOwner() | |
a7a01418 | 94 | virtual void Notify(); |
d14a1e28 | 95 | |
dd9f7fea | 96 | // return True if the timer is running |
d14a1e28 RD |
97 | virtual bool IsRunning() const; |
98 | ||
0e859e32 | 99 | // get the (last) timer interval in milliseconds |
d14a1e28 RD |
100 | int GetInterval() const; |
101 | ||
0bdc5dd6 RD |
102 | // return the timer ID |
103 | int GetId() const; | |
66065839 | 104 | |
0e859e32 DS |
105 | // return True if the timer is one shot |
106 | bool IsOneShot() const; | |
107 | ||
94fd5e4d | 108 | %pythoncode { |
4bbf373b | 109 | def Destroy(self): |
0e859e32 | 110 | """NO-OP: Timers must be destroyed by normal reference counting""" |
94fd5e4d RD |
111 | pass |
112 | } | |
994453b8 RD |
113 | |
114 | %property(Id, GetId, doc="See `GetId`"); | |
115 | %property(Interval, GetInterval, doc="See `GetInterval`"); | |
116 | %property(Owner, GetOwner, SetOwner, doc="See `GetOwner` and `SetOwner`"); | |
d14a1e28 RD |
117 | }; |
118 | ||
119 | ||
66065839 | 120 | %pythoncode { |
d14a1e28 RD |
121 | %# For backwards compatibility with 2.4 |
122 | class PyTimer(Timer): | |
123 | def __init__(self, notify): | |
124 | Timer.__init__(self) | |
125 | self.notify = notify | |
126 | ||
127 | def Notify(self): | |
128 | if self.notify: | |
129 | self.notify() | |
130 | ||
131 | ||
132 | EVT_TIMER = wx.PyEventBinder( wxEVT_TIMER, 1 ) | |
66065839 | 133 | |
d14a1e28 RD |
134 | }; |
135 | ||
136 | ||
137 | ||
138 | class wxTimerEvent : public wxEvent | |
139 | { | |
140 | public: | |
141 | wxTimerEvent(int timerid = 0, int interval = 0); | |
142 | int GetInterval() const; | |
994453b8 RD |
143 | |
144 | %property(Interval, GetInterval, doc="See `GetInterval`"); | |
d14a1e28 RD |
145 | }; |
146 | ||
147 | ||
148 | ||
149 | // wxTimerRunner: starts the timer in its ctor, stops in the dtor | |
ab1f7d2a | 150 | MustHaveApp(wxTimerRunner); |
d14a1e28 RD |
151 | class wxTimerRunner |
152 | { | |
153 | public: | |
154 | %nokwargs wxTimerRunner; | |
155 | wxTimerRunner(wxTimer& timer); | |
a72f4631 | 156 | wxTimerRunner(wxTimer& timer, int milli, bool oneShot = false); |
d14a1e28 RD |
157 | ~wxTimerRunner(); |
158 | ||
a72f4631 | 159 | void Start(int milli, bool oneShot = false); |
d14a1e28 RD |
160 | }; |
161 | ||
162 | ||
163 | //--------------------------------------------------------------------------- | |
313feadc RD |
164 | %init %{ |
165 | wxPyPtrTypeMap_Add("wxTimer", "wxPyTimer"); | |
166 | %} | |
167 | //--------------------------------------------------------------------------- |