]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_timer.i
Tweaks for demos on MacOSX
[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) SetOwner(this);
43 }
44 %}
45
46
47
48 MustHaveApp(wxPyTimer);
49
50 %rename(Timer) wxPyTimer;
51 class wxPyTimer : public wxEvtHandler
52 {
53 public:
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
58 "self._setCallbackInfo(self, Timer, 0); self._setOORInfo(self, 0)"
59
60
61 // if you don't call SetOwner() or provide an owner in the contstructor
62 // then you must override Notify() inorder to receive the timer
63 // notification. If the owner is set then it will get the timer
64 // notifications which can be handled with EVT_TIMER.
65 wxPyTimer(wxEvtHandler *owner=NULL, int id = -1);
66
67 // Destructor.
68 virtual ~wxPyTimer();
69
70 void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=1);
71
72 // Set the owner instance that will receive the EVT_TIMER events using the
73 // given id.
74 void SetOwner(wxEvtHandler *owner, int id = -1);
75 wxEvtHandler* GetOwner();
76
77 // start the timer: if milliseconds == -1, use the same value as for the
78 // last Start()
79 //
80 // it is now valid to call Start() multiple times: this just restarts the
81 // timer if it is already running
82 virtual bool Start(int milliseconds = -1, bool oneShot = false);
83
84 // stop the timer
85 virtual void Stop();
86
87 // override this in your wxTimer-derived class if you want to process timer
88 // messages in it, use non default ctor or SetOwner() otherwise
89 virtual void Notify();
90
91 // return True if the timer is running
92 virtual bool IsRunning() const;
93
94 // get the (last) timer interval in the milliseconds
95 int GetInterval() const;
96
97 // return True if the timer is one shot
98 bool IsOneShot() const;
99
100 // return the timer ID
101 int GetId() const;
102
103 %pythoncode {
104 def Destroy(self):
105 """NO-OP: Timers must be destroyed by normal refrence counting"""
106 pass
107 }
108 };
109
110
111 %pythoncode {
112 %# For backwards compatibility with 2.4
113 class PyTimer(Timer):
114 def __init__(self, notify):
115 Timer.__init__(self)
116 self.notify = notify
117
118 def Notify(self):
119 if self.notify:
120 self.notify()
121
122
123 EVT_TIMER = wx.PyEventBinder( wxEVT_TIMER, 1 )
124
125 };
126
127
128
129 class wxTimerEvent : public wxEvent
130 {
131 public:
132 wxTimerEvent(int timerid = 0, int interval = 0);
133 int GetInterval() const;
134 };
135
136
137
138 // wxTimerRunner: starts the timer in its ctor, stops in the dtor
139 MustHaveApp(wxTimerRunner);
140 class wxTimerRunner
141 {
142 public:
143 %nokwargs wxTimerRunner;
144 wxTimerRunner(wxTimer& timer);
145 wxTimerRunner(wxTimer& timer, int milli, bool oneShot = false);
146 ~wxTimerRunner();
147
148 void Start(int milli, bool oneShot = false);
149 };
150
151
152 //---------------------------------------------------------------------------
153 %init %{
154 wxPyPtrTypeMap_Add("wxTimer", "wxPyTimer");
155 %}
156 //---------------------------------------------------------------------------