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