]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: misc.i | |
3 | // Purpose: Definitions of miscelaneous functions and classes | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 7/3/97 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | %module misc | |
14 | ||
15 | %{ | |
16 | #include "helpers.h" | |
17 | #include <wx/resource.h> | |
18 | #include <wx/tooltip.h> | |
19 | #include <wx/busyinfo.h> | |
20 | %} | |
21 | ||
22 | //---------------------------------------------------------------------- | |
23 | ||
24 | %include typemaps.i | |
25 | %include my_typemaps.i | |
26 | ||
27 | // Import some definitions of other classes, etc. | |
28 | %import _defs.i | |
29 | ||
30 | ||
31 | %{ | |
32 | static wxString wxPyEmptyStr(""); | |
33 | %} | |
34 | ||
35 | //--------------------------------------------------------------------------- | |
36 | ||
37 | ||
38 | class wxObject { | |
39 | public: | |
40 | ||
41 | %addmethods { | |
42 | const char* GetClassName() { | |
43 | return self->GetClassInfo()->GetClassName(); | |
44 | } | |
45 | ||
46 | void Destroy() { | |
47 | delete self; | |
48 | } | |
49 | } | |
50 | }; | |
51 | ||
52 | //--------------------------------------------------------------------------- | |
53 | ||
54 | class wxSize { | |
55 | public: | |
56 | long x; | |
57 | long y; | |
58 | %name(width) long x; | |
59 | %name(height)long y; | |
60 | ||
61 | wxSize(long w=0, long h=0); | |
62 | ~wxSize(); | |
63 | void Set(long w, long h); | |
64 | long GetX(); | |
65 | long GetY(); | |
66 | long GetWidth(); | |
67 | long GetHeight(); | |
68 | void SetWidth(long w); | |
69 | void SetHeight(long h); | |
70 | ||
71 | %addmethods { | |
72 | PyObject* asTuple() { | |
73 | PyObject* tup = PyTuple_New(2); | |
74 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
75 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
76 | return tup; | |
77 | } | |
78 | ||
79 | int __cmp__(const wxSize* sz) { | |
80 | if (! sz) return 1; | |
81 | if (*self == *sz) return 0; | |
82 | return -1; | |
83 | } | |
84 | } | |
85 | ||
86 | %pragma(python) addtoclass = " | |
87 | def __str__(self): return str(self.asTuple()) | |
88 | def __repr__(self): return str(self.asTuple()) | |
89 | def __len__(self): return len(self.asTuple()) | |
90 | def __getitem__(self, index): return self.asTuple()[index] | |
91 | def __setitem__(self, index, val): | |
92 | if index == 0: self.width = val | |
93 | elif index == 1: self.height = val | |
94 | else: raise IndexError | |
95 | " | |
96 | ||
97 | }; | |
98 | ||
99 | //--------------------------------------------------------------------------- | |
100 | ||
101 | class wxRealPoint { | |
102 | public: | |
103 | double x; | |
104 | double y; | |
105 | wxRealPoint(double x=0.0, double y=0.0); | |
106 | ~wxRealPoint(); | |
107 | ||
108 | %addmethods { | |
109 | void Set(double x, double y) { | |
110 | self->x = x; | |
111 | self->y = y; | |
112 | } | |
113 | PyObject* asTuple() { | |
114 | PyObject* tup = PyTuple_New(2); | |
115 | PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x)); | |
116 | PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y)); | |
117 | return tup; | |
118 | } | |
119 | ||
120 | wxRealPoint __add__(const wxRealPoint* p) { | |
121 | if (! p) return *self; | |
122 | return *self + *p; | |
123 | } | |
124 | ||
125 | wxRealPoint __sub__(const wxRealPoint* p) { | |
126 | if (! p) return *self; | |
127 | return *self - *p; | |
128 | } | |
129 | ||
130 | int __cmp__(const wxRealPoint* p) { | |
131 | if (! p) return 1; | |
132 | if (*self == *p) return 0; | |
133 | return -1; | |
134 | } | |
135 | } | |
136 | %pragma(python) addtoclass = " | |
137 | def __str__(self): return str(self.asTuple()) | |
138 | def __repr__(self): return str(self.asTuple()) | |
139 | def __len__(self): return len(self.asTuple()) | |
140 | def __getitem__(self, index): return self.asTuple()[index] | |
141 | def __setitem__(self, index, val): | |
142 | if index == 0: self.width = val | |
143 | elif index == 1: self.height = val | |
144 | else: raise IndexError | |
145 | " | |
146 | }; | |
147 | ||
148 | ||
149 | class wxPoint { | |
150 | public: | |
151 | long x; | |
152 | long y; | |
153 | wxPoint(long x=0, long y=0); | |
154 | ~wxPoint(); | |
155 | ||
156 | %addmethods { | |
157 | void Set(long x, long y) { | |
158 | self->x = x; | |
159 | self->y = y; | |
160 | } | |
161 | PyObject* asTuple() { | |
162 | PyObject* tup = PyTuple_New(2); | |
163 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
164 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
165 | return tup; | |
166 | } | |
167 | ||
168 | wxPoint __add__(const wxPoint* p) { | |
169 | if (! p) return *self; | |
170 | return *self + *p; | |
171 | } | |
172 | ||
173 | wxPoint __sub__(const wxPoint* p) { | |
174 | if (! p) return *self; | |
175 | return *self - *p; | |
176 | } | |
177 | ||
178 | int __cmp__(const wxPoint* p) { | |
179 | if (! p) return 1; | |
180 | if (*self == *p) return 0; | |
181 | return -1; | |
182 | } | |
183 | } | |
184 | %pragma(python) addtoclass = " | |
185 | def __str__(self): return str(self.asTuple()) | |
186 | def __repr__(self): return str(self.asTuple()) | |
187 | def __len__(self): return len(self.asTuple()) | |
188 | def __getitem__(self, index): return self.asTuple()[index] | |
189 | def __setitem__(self, index, val): | |
190 | if index == 0: self.x = val | |
191 | elif index == 1: self.y = val | |
192 | else: raise IndexError | |
193 | " | |
194 | }; | |
195 | ||
196 | //--------------------------------------------------------------------------- | |
197 | ||
198 | class wxRect { | |
199 | public: | |
200 | wxRect(int x=0, int y=0, int w=0, int h=0); | |
201 | // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size); | |
202 | ~wxRect(); | |
203 | ||
204 | int GetX(); | |
205 | void SetX(int X); | |
206 | int GetY(); | |
207 | void SetY(int Y); | |
208 | int GetWidth(); | |
209 | void SetWidth(int w); | |
210 | int GetHeight(); | |
211 | void SetHeight(int h); | |
212 | ||
213 | ||
214 | wxPoint GetPosition(); | |
215 | wxSize GetSize(); | |
216 | ||
217 | int GetLeft(); | |
218 | int GetTop(); | |
219 | int GetBottom(); | |
220 | int GetRight(); | |
221 | ||
222 | void SetLeft(int left); | |
223 | void SetRight(int right); | |
224 | void SetTop(int top); | |
225 | void SetBottom(int bottom); | |
226 | ||
227 | void Inflate(int dx, int dy); | |
228 | bool Inside(int cx, int cy); | |
229 | ||
230 | int x, y, width, height; | |
231 | ||
232 | %addmethods { | |
233 | PyObject* asTuple() { | |
234 | PyObject* tup = PyTuple_New(4); | |
235 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); | |
236 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); | |
237 | PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width)); | |
238 | PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height)); | |
239 | return tup; | |
240 | } | |
241 | ||
242 | wxRect __add__(const wxRect* rect) { | |
243 | if (! rect) return *self; | |
244 | return *self + *rect; | |
245 | } | |
246 | ||
247 | int __cmp__(const wxRect* rect) { | |
248 | if (! rect) return 1; | |
249 | if (*self == *rect) return 0; | |
250 | return -1; | |
251 | } | |
252 | } | |
253 | ||
254 | %pragma(python) addtoclass = " | |
255 | def __str__(self): return str(self.asTuple()) | |
256 | def __repr__(self): return str(self.asTuple()) | |
257 | def __len__(self): return len(self.asTuple()) | |
258 | def __getitem__(self, index): return self.asTuple()[index] | |
259 | def __setitem__(self, index, val): | |
260 | if index == 0: self.x = val | |
261 | elif index == 1: self.y = val | |
262 | elif index == 2: self.width = val | |
263 | elif index == 3: self.height = val | |
264 | else: raise IndexError | |
265 | ||
266 | # override the __getattr__ made by SWIG | |
267 | def __getattr__(self, name): | |
268 | d = { | |
269 | 'x' : miscc.wxRect_x_get, | |
270 | 'y' : miscc.wxRect_y_get, | |
271 | 'width' : miscc.wxRect_width_get, | |
272 | 'height' : miscc.wxRect_height_get, | |
273 | 'top' : miscc.wxRect_GetTop, | |
274 | 'bottom' : miscc.wxRect_GetBottom, | |
275 | 'left' : miscc.wxRect_GetLeft, | |
276 | 'right' : miscc.wxRect_GetRight, | |
277 | } | |
278 | try: | |
279 | func = d[name] | |
280 | except KeyError: | |
281 | raise AttributeError,name | |
282 | return func(self) | |
283 | ||
284 | # and also the __setattr__ | |
285 | def __setattr__(self, name, value): | |
286 | d = { | |
287 | 'x' : miscc.wxRect_x_set, | |
288 | 'y' : miscc.wxRect_y_set, | |
289 | 'width' : miscc.wxRect_width_set, | |
290 | 'height' : miscc.wxRect_height_set, | |
291 | 'top' : miscc.wxRect_SetTop, | |
292 | 'bottom' : miscc.wxRect_SetBottom, | |
293 | 'left' : miscc.wxRect_SetLeft, | |
294 | 'right' : miscc.wxRect_SetRight, | |
295 | } | |
296 | try: | |
297 | func = d[name] | |
298 | except KeyError: | |
299 | self.__dict__[name] = value | |
300 | return | |
301 | func(self, value) | |
302 | " | |
303 | ||
304 | }; | |
305 | ||
306 | ||
307 | %inline %{ | |
308 | PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) { | |
309 | wxRegion reg1(*r1); | |
310 | wxRegion reg2(*r2); | |
311 | wxRect dest(0,0,0,0); | |
312 | PyObject* obj; | |
313 | ||
314 | reg1.Intersect(reg2); | |
315 | dest = reg1.GetBox(); | |
316 | ||
317 | if (dest != wxRect(0,0,0,0)) { | |
318 | wxPyTState* state = wxPyBeginBlockThreads(); | |
319 | wxRect* newRect = new wxRect(dest); | |
320 | obj = wxPyConstructObject((void*)newRect, "wxRect"); | |
321 | PyObject* one = PyInt_FromLong(1); | |
322 | PyObject_SetAttrString(obj, "thisown", one); | |
323 | Py_DECREF(one); | |
324 | wxPyEndBlockThreads(state); | |
325 | return obj; | |
326 | } | |
327 | Py_INCREF(Py_None); | |
328 | return Py_None; | |
329 | } | |
330 | %} | |
331 | ||
332 | ||
333 | //--------------------------------------------------------------------------- | |
334 | // Miscellaneous functions | |
335 | ||
336 | long wxNewId(); | |
337 | void wxRegisterId(long id); | |
338 | %name(NewId) long wxNewId(); | |
339 | %name(RegisterId) void wxRegisterId(long id); | |
340 | long wxGetCurrentId(); | |
341 | ||
342 | void wxBell(); | |
343 | void wxEndBusyCursor(); | |
344 | ||
345 | long wxGetElapsedTime(bool resetTimer = TRUE); | |
346 | #ifdef __WXMSW__ | |
347 | long wxGetFreeMemory(); | |
348 | #endif | |
349 | void wxGetMousePosition(int* OUTPUT, int* OUTPUT); | |
350 | bool wxIsBusy(); | |
351 | wxString wxNow(); | |
352 | bool wxShell(const wxString& command = wxPyEmptyStr); | |
353 | void wxStartTimer(); | |
354 | int wxGetOsVersion(int *OUTPUT, int *OUTPUT); | |
355 | wxString wxGetOsDescription(); | |
356 | ||
357 | void wxSleep(int secs); | |
358 | void wxUsleep(unsigned long milliseconds); | |
359 | bool wxYield(); | |
360 | bool wxYieldIfNeeded(); | |
361 | void wxEnableTopLevelWindows(bool enable); | |
362 | ||
363 | %inline %{ | |
364 | char* wxGetResource(char *section, char *entry, char *file = NULL) { | |
365 | char * retval; | |
366 | wxGetResource(section, entry, &retval, file); | |
367 | return retval; | |
368 | } | |
369 | %} | |
370 | ||
371 | wxString wxStripMenuCodes(const wxString& in); | |
372 | ||
373 | ||
374 | wxString wxGetEmailAddress(); | |
375 | wxString wxGetHostName(); | |
376 | wxString wxGetFullHostName(); | |
377 | wxString wxGetUserId(); | |
378 | wxString wxGetUserName(); | |
379 | wxString wxGetHomeDir(); | |
380 | ||
381 | ||
382 | //---------------------------------------------------------------------- | |
383 | ||
384 | enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight, | |
385 | wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY }; | |
386 | enum wxRelationship { wxUnconstrained = 0, | |
387 | wxAsIs, | |
388 | wxPercentOf, | |
389 | wxAbove, | |
390 | wxBelow, | |
391 | wxLeftOf, | |
392 | wxRightOf, | |
393 | wxSameAs, | |
394 | wxAbsolute }; | |
395 | ||
396 | ||
397 | class wxIndividualLayoutConstraint : public wxObject { | |
398 | public: | |
399 | // wxIndividualLayoutConstraint(); | |
400 | // ~wxIndividualLayoutConstraint(); | |
401 | ||
402 | void Above(wxWindow *otherWin, int margin=0); | |
403 | void Absolute(int value); | |
404 | void AsIs(); | |
405 | void Below(wxWindow *otherWin, int margin=0); | |
406 | void Unconstrained(); | |
407 | void LeftOf(wxWindow *otherWin, int margin=0); | |
408 | void PercentOf(wxWindow *otherWin, wxEdge edge, int percent); | |
409 | void RightOf(wxWindow *otherWin, int margin=0); | |
410 | void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0); | |
411 | void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0); | |
412 | }; | |
413 | ||
414 | ||
415 | class wxLayoutConstraints : public wxObject { | |
416 | public: | |
417 | wxLayoutConstraints(); | |
418 | ||
419 | %readonly | |
420 | wxIndividualLayoutConstraint bottom; | |
421 | wxIndividualLayoutConstraint centreX; | |
422 | wxIndividualLayoutConstraint centreY; | |
423 | wxIndividualLayoutConstraint height; | |
424 | wxIndividualLayoutConstraint left; | |
425 | wxIndividualLayoutConstraint right; | |
426 | wxIndividualLayoutConstraint top; | |
427 | wxIndividualLayoutConstraint width; | |
428 | %readwrite | |
429 | } | |
430 | ||
431 | ||
432 | ||
433 | //--------------------------------------------------------------------------- | |
434 | // Accelerator Entry and Table | |
435 | ||
436 | class wxAcceleratorEntry { | |
437 | public: | |
438 | wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0); | |
439 | ~wxAcceleratorEntry(); | |
440 | ||
441 | void Set(int flags, int keyCode, int Cmd); | |
442 | int GetFlags(); | |
443 | int GetKeyCode(); | |
444 | int GetCommand(); | |
445 | }; | |
446 | ||
447 | ||
448 | class wxAcceleratorTable : public wxObject { | |
449 | public: | |
450 | // Can also accept a list of 3-tuples | |
451 | wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices); | |
452 | ~wxAcceleratorTable(); | |
453 | ||
454 | }; | |
455 | ||
456 | wxAcceleratorEntry *wxGetAccelFromString(const wxString& label); | |
457 | ||
458 | %readonly | |
459 | %{ | |
460 | #if 0 // we want to use the definition from the header, not the | |
461 | // one SWIG will generate. | |
462 | %} | |
463 | extern wxAcceleratorTable wxNullAcceleratorTable; | |
464 | %{ | |
465 | #endif | |
466 | %} | |
467 | %readwrite | |
468 | ||
469 | //--------------------------------------------------------------------------- | |
470 | ||
471 | class wxBusyInfo : public wxObject { | |
472 | public: | |
473 | wxBusyInfo(const wxString& message); | |
474 | ~wxBusyInfo(); | |
475 | }; | |
476 | ||
477 | //--------------------------------------------------------------------------- | |
478 | ||
479 | ||
480 |