]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_timer.i
mention wxLogInterposer(Temp)
[wxWidgets.git] / wxPython / src / _timer.i
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;
29
30
31 //---------------------------------------------------------------------------
32
33
34 %{
35 IMP_PYCALLBACK__(wxPyTimer, wxTimer, Notify);
36
37 IMPLEMENT_ABSTRACT_CLASS(wxPyTimer, wxTimer);
38
39 wxPyTimer::wxPyTimer(wxEvtHandler *owner, int id)
40 : wxTimer(owner, id)
41 {
42 if (owner == NULL)
43 SetOwner(this);
44 }
45
46 wxPyTimer::~wxPyTimer()
47 {
48 // printf("-=* ~wxPyTimer\n");
49 }
50
51 %}
52
53
54 MustHaveApp(wxPyTimer);
55
56 %rename(Timer) wxPyTimer;
57 class wxPyTimer : public wxEvtHandler
58 {
59 public:
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
64 "self._setOORInfo(self,0); self.this.own(True); " setCallbackInfo(Timer);
65
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
68 // notification. If the owner is set then it will get the timer
69 // notifications which can be handled with EVT_TIMER.
70 wxPyTimer(wxEvtHandler *owner = NULL, int id = wxID_ANY);
71
72 // Destructor.
73 virtual ~wxPyTimer();
74
75 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref = 0);
76
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);
80 wxEvtHandler* GetOwner();
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
87 virtual bool Start(int milliseconds = -1, bool oneShot = false);
88
89 // stop the timer
90 virtual void Stop();
91
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()
94 virtual void Notify();
95
96 // return True if the timer is running
97 virtual bool IsRunning() const;
98
99 // get the (last) timer interval in milliseconds
100 int GetInterval() const;
101
102 // return the timer ID
103 int GetId() const;
104
105 // return True if the timer is one shot
106 bool IsOneShot() const;
107
108 %pythoncode {
109 def Destroy(self):
110 """NO-OP: Timers must be destroyed by normal reference counting"""
111 pass
112 }
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`");
117 };
118
119
120 %pythoncode {
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 )
133
134 };
135
136
137
138 class wxTimerEvent : public wxEvent
139 {
140 public:
141 wxTimerEvent(int timerid = 0, int interval = 0);
142 int GetInterval() const;
143 wxTimer& GetTimer() const;
144
145 %property(Interval, GetInterval, doc="See `GetInterval`");
146 %property(Timer, GetTimer);
147 };
148
149
150
151 // wxTimerRunner: starts the timer in its ctor, stops in the dtor
152 MustHaveApp(wxTimerRunner);
153 class wxTimerRunner
154 {
155 public:
156 %nokwargs wxTimerRunner;
157 wxTimerRunner(wxTimer& timer);
158 wxTimerRunner(wxTimer& timer, int milli, bool oneShot = false);
159 ~wxTimerRunner();
160
161 void Start(int milli, bool oneShot = false);
162 };
163
164
165 //---------------------------------------------------------------------------
166 %init %{
167 wxPyPtrTypeMap_Add("wxTimer", "wxPyTimer");
168 %}
169 //---------------------------------------------------------------------------