]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/misc.i
Since wxGTK's wxGauge doesn't derive from wxGaugeBase it needs to have
[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/tooltip.h>
18 #include <wx/busyinfo.h>
19 #include <wx/geometry.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 void IncTo(const wxSize& sz);
73 void DecTo(const wxSize& sz);
74
75 %addmethods {
76 PyObject* asTuple() {
77 wxPyBeginBlockThreads();
78 PyObject* tup = PyTuple_New(2);
79 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
80 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
81 wxPyEndBlockThreads();
82 return tup;
83 }
84
85 bool __eq__(PyObject* obj) {
86 wxSize tmp;
87 wxSize* ptr = &tmp;
88 if (obj == Py_None) return FALSE;
89 wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
90 if (! success) return FALSE;
91 return *self == *ptr;
92 }
93 bool __ne__(PyObject* obj) {
94 wxSize tmp;
95 wxSize* ptr = &tmp;
96 if (obj == Py_None) return TRUE;
97 wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
98 if (! success) return TRUE;
99 return *self != *ptr;
100 }
101
102 }
103
104 %pragma(python) addtoclass = "
105 def __str__(self): return str(self.asTuple())
106 def __repr__(self): return 'wxSize'+str(self.asTuple())
107 def __len__(self): return len(self.asTuple())
108 def __getitem__(self, index): return self.asTuple()[index]
109 def __setitem__(self, index, val):
110 if index == 0: self.width = val
111 elif index == 1: self.height = val
112 else: raise IndexError
113 def __nonzero__(self): return self.asTuple() != (0,0)
114 def __getinitargs__(self): return ()
115 def __getstate__(self): return self.asTuple()
116 def __setstate__(self, state): self.Set(*state)
117 "
118
119 };
120
121 //---------------------------------------------------------------------------
122
123 class wxRealPoint {
124 public:
125 double x;
126 double y;
127 wxRealPoint(double x=0.0, double y=0.0);
128 ~wxRealPoint();
129
130 %addmethods {
131 void Set(double x, double y) {
132 self->x = x;
133 self->y = y;
134 }
135 PyObject* asTuple() {
136 wxPyBeginBlockThreads();
137 PyObject* tup = PyTuple_New(2);
138 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
139 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
140 wxPyEndBlockThreads();
141 return tup;
142 }
143
144 wxRealPoint __add__(const wxRealPoint& p) {
145 return *self + p;
146 }
147
148 wxRealPoint __sub__(const wxRealPoint& p) {
149 return *self - p;
150 }
151
152 bool __eq__(PyObject* obj) {
153 wxRealPoint tmp;
154 wxRealPoint* ptr = &tmp;
155 if (obj == Py_None) return FALSE;
156 wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
157 if (! success) return FALSE;
158 return *self == *ptr;
159 }
160 bool __ne__(PyObject* obj) {
161 wxRealPoint tmp;
162 wxRealPoint* ptr = &tmp;
163 if (obj == Py_None) return TRUE;
164 wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
165 if (! success) return TRUE;
166 return *self != *ptr;
167 }
168
169 }
170
171 %pragma(python) addtoclass = "
172 def __str__(self): return str(self.asTuple())
173 def __repr__(self): return 'wxRealPoint'+str(self.asTuple())
174 def __len__(self): return len(self.asTuple())
175 def __getitem__(self, index): return self.asTuple()[index]
176 def __setitem__(self, index, val):
177 if index == 0: self.width = val
178 elif index == 1: self.height = val
179 else: raise IndexError
180 def __nonzero__(self): return self.asTuple() != (0.0, 0.0)
181 def __getinitargs__(self): return ()
182 def __getstate__(self): return self.asTuple()
183 def __setstate__(self, state): self.Set(*state)
184 "
185 };
186
187
188 class wxPoint {
189 public:
190 long x;
191 long y;
192 wxPoint(long x=0, long y=0);
193 ~wxPoint();
194
195 %addmethods {
196 void Set(long x, long y) {
197 self->x = x;
198 self->y = y;
199 }
200 PyObject* asTuple() {
201 wxPyBeginBlockThreads();
202 PyObject* tup = PyTuple_New(2);
203 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
204 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
205 wxPyEndBlockThreads();
206 return tup;
207 }
208
209 wxPoint __add__(const wxPoint& p) {
210 return *self + p;
211 }
212
213 wxPoint __sub__(const wxPoint& p) {
214 return *self - p;
215 }
216
217 bool __eq__(PyObject* obj) {
218 wxPoint tmp;
219 wxPoint* ptr = &tmp;
220 if (obj == Py_None) return FALSE;
221 wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
222 if (! success) return FALSE;
223 return *self == *ptr;
224 }
225 bool __ne__(PyObject* obj) {
226 wxPoint tmp;
227 wxPoint* ptr = &tmp;
228 if (obj == Py_None) return TRUE;
229 wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
230 if (! success) return TRUE;
231 return *self != *ptr;
232 }
233
234 }
235
236 %pragma(python) addtoclass = "
237 def __str__(self): return str(self.asTuple())
238 def __repr__(self): return 'wxPoint'+str(self.asTuple())
239 def __len__(self): return len(self.asTuple())
240 def __getitem__(self, index): return self.asTuple()[index]
241 def __setitem__(self, index, val):
242 if index == 0: self.x = val
243 elif index == 1: self.y = val
244 else: raise IndexError
245 def __nonzero__(self): return self.asTuple() != (0,0)
246 def __getinitargs__(self): return ()
247 def __getstate__(self): return self.asTuple()
248 def __setstate__(self, state): self.Set(*state)
249 "
250 };
251
252 //---------------------------------------------------------------------------
253
254 class wxRect {
255 public:
256 wxRect(int x=0, int y=0, int width=0, int height=0);
257 // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
258 ~wxRect();
259
260 int GetX();
261 void SetX(int X);
262 int GetY();
263 void SetY(int Y);
264 int GetWidth();
265 void SetWidth(int w);
266 int GetHeight();
267 void SetHeight(int h);
268
269
270 wxPoint GetPosition();
271 wxSize GetSize();
272 void SetPosition( const wxPoint &p );
273 void SetSize( const wxSize &s );
274
275 int GetLeft();
276 int GetTop();
277 int GetBottom();
278 int GetRight();
279
280 void SetLeft(int left);
281 void SetRight(int right);
282 void SetTop(int top);
283 void SetBottom(int bottom);
284
285 void Deflate(int dx, int dy);
286 void Inflate(int dx, int dy);
287 %name(InsideXY)bool Inside(int cx, int cy);
288 bool Inside(const wxPoint& pt);
289 bool Intersects(const wxRect& rect);
290 %name(OffsetXY) void Offset(int dx, int dy);
291 void Offset(const wxPoint& pt);
292
293 int x, y, width, height;
294
295 %addmethods {
296 void Set(int x=0, int y=0, int width=0, int height=0) {
297 self->x = x;
298 self->y = y;
299 self->width = width;
300 self->height = height;
301 }
302
303 PyObject* asTuple() {
304 wxPyBeginBlockThreads();
305 PyObject* tup = PyTuple_New(4);
306 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
307 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
308 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
309 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
310 wxPyEndBlockThreads();
311 return tup;
312 }
313
314 wxRect __add__(const wxRect& rect) {
315 return *self + rect;
316 }
317
318 bool __eq__(PyObject* obj) {
319 wxRect tmp;
320 wxRect* ptr = &tmp;
321 if (obj == Py_None) return FALSE;
322 wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
323 if (! success) return FALSE;
324 return *self == *ptr;
325 }
326 bool __ne__(PyObject* obj) {
327 wxRect tmp;
328 wxRect* ptr = &tmp;
329 if (obj == Py_None) return TRUE;
330 wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
331 if (! success) return TRUE;
332 return *self != *ptr;
333 }
334
335 }
336
337 %pragma(python) addtoclass = "
338 def __str__(self): return str(self.asTuple())
339 def __repr__(self): return 'wxRect'+str(self.asTuple())
340 def __len__(self): return len(self.asTuple())
341 def __getitem__(self, index): return self.asTuple()[index]
342 def __setitem__(self, index, val):
343 if index == 0: self.x = val
344 elif index == 1: self.y = val
345 elif index == 2: self.width = val
346 elif index == 3: self.height = val
347 else: raise IndexError
348 def __nonzero__(self): return self.asTuple() != (0,0,0,0)
349 def __getinitargs__(self): return ()
350 def __getstate__(self): return self.asTuple()
351 def __setstate__(self, state): self.Set(*state)
352
353 # override the __getattr__ made by SWIG
354 def __getattr__(self, name):
355 d = {
356 'x' : miscc.wxRect_x_get,
357 'y' : miscc.wxRect_y_get,
358 'width' : miscc.wxRect_width_get,
359 'height' : miscc.wxRect_height_get,
360 'top' : miscc.wxRect_GetTop,
361 'bottom' : miscc.wxRect_GetBottom,
362 'left' : miscc.wxRect_GetLeft,
363 'right' : miscc.wxRect_GetRight,
364 }
365 try:
366 func = d[name]
367 except KeyError:
368 raise AttributeError,name
369 return func(self)
370
371 # and also the __setattr__
372 def __setattr__(self, name, value):
373 d = {
374 'x' : miscc.wxRect_x_set,
375 'y' : miscc.wxRect_y_set,
376 'width' : miscc.wxRect_width_set,
377 'height' : miscc.wxRect_height_set,
378 'top' : miscc.wxRect_SetTop,
379 'bottom' : miscc.wxRect_SetBottom,
380 'left' : miscc.wxRect_SetLeft,
381 'right' : miscc.wxRect_SetRight,
382 }
383 try:
384 func = d[name]
385 except KeyError:
386 self.__dict__[name] = value
387 return
388 func(self, value)
389 "
390
391 };
392
393
394 %inline %{
395 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
396 wxRegion reg1(*r1);
397 wxRegion reg2(*r2);
398 wxRect dest(0,0,0,0);
399 PyObject* obj;
400
401 reg1.Intersect(reg2);
402 dest = reg1.GetBox();
403
404 if (dest != wxRect(0,0,0,0)) {
405 wxPyBeginBlockThreads();
406 wxRect* newRect = new wxRect(dest);
407 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"));
408 PyObject* one = PyInt_FromLong(1);
409 PyObject_SetAttrString(obj, "thisown", one);
410 Py_DECREF(one);
411 wxPyEndBlockThreads();
412 return obj;
413 }
414 Py_INCREF(Py_None);
415 return Py_None;
416 }
417 %}
418
419
420
421 //---------------------------------------------------------------------------
422 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
423
424 class wxPoint2DDouble
425 {
426 public:
427 double m_x;
428 double m_y;
429
430 %name(x)double m_x;
431 %name(y)double m_y;
432
433 wxPoint2DDouble( double x=0 , double y=0 );
434 %name(wxPoint2DDoubleCopy)wxPoint2DDouble( const wxPoint2DDouble &pt );
435 %name(wxPoint2DDoubleFromPoint)wxPoint2DDouble( const wxPoint &pt );
436
437 // two different conversions to integers, floor and rounding
438 void GetFloor( int* OUTPUT , int* OUTPUT ) const;
439 void GetRounded( int* OUTPUT , int* OUTPUT ) const;
440
441 double GetVectorLength() const;
442 double GetVectorAngle() const ;
443 void SetVectorLength( double length );
444 void SetVectorAngle( double degrees );
445 // LinkError: void SetPolarCoordinates( double angle , double length );
446 // LinkError: void Normalize();
447 %pragma(python) addtoclass = "
448 def SetPolarCoordinates(self, angle, length):
449 self.SetVectorLength(length)
450 self.SetVectorAngle(angle)
451 def Normalize(self):
452 self.SetVectorLength(1.0)
453 "
454
455 double GetDistance( const wxPoint2DDouble &pt ) const;
456 double GetDistanceSquare( const wxPoint2DDouble &pt ) const;
457 double GetDotProduct( const wxPoint2DDouble &vec ) const;
458 double GetCrossProduct( const wxPoint2DDouble &vec ) const;
459
460 %addmethods {
461 void Set( double x=0 , double y=0 ) {
462 self->m_x = x;
463 self->m_y = y;
464 }
465
466 // the reflection of this point
467 wxPoint2DDouble __neg__() { return -(*self); }
468
469 wxPoint2DDouble& __iadd__(const wxPoint2DDouble& pt) { return (*self) += pt; }
470 wxPoint2DDouble& __isub__(const wxPoint2DDouble& pt) { return (*self) -= pt; }
471 wxPoint2DDouble& __imul__(const wxPoint2DDouble& pt) { return (*self) *= pt; }
472 wxPoint2DDouble& __idiv__(const wxPoint2DDouble& pt) { return (*self) /= pt; }
473
474 // TODO:
475 //wxPoint2DDouble& operator*=(double n);
476 //wxPoint2DDouble& operator*=(int n);
477 //wxPoint2DDouble& operator/=(double n);
478 //wxPoint2DDouble& operator/=(int n);
479
480 bool __eq__(PyObject* obj) {
481 wxPoint2DDouble tmp;
482 wxPoint2DDouble* ptr = &tmp;
483 if (obj == Py_None) return FALSE;
484 wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
485 if (! success) return FALSE;
486 return *self == *ptr;
487 }
488 bool __ne__(PyObject* obj) {
489 wxPoint2DDouble tmp;
490 wxPoint2DDouble* ptr = &tmp;
491 if (obj == Py_None) return TRUE;
492 wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
493 if (! success) return TRUE;
494 return *self != *ptr;
495 }
496
497
498 PyObject* asTuple() {
499 wxPyBeginBlockThreads();
500 PyObject* tup = PyTuple_New(2);
501 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
502 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
503 wxPyEndBlockThreads();
504 return tup;
505 }
506 }
507
508 %pragma(python) addtoclass = "
509 def __str__(self): return str(self.asTuple())
510 def __repr__(self): return 'wxPoint2DDouble'+str(self.asTuple())
511 def __len__(self): return len(self.asTuple())
512 def __getitem__(self, index): return self.asTuple()[index]
513 def __setitem__(self, index, val):
514 if index == 0: self.m_x = val
515 elif index == 1: self.m_yt = val
516 else: raise IndexError
517 def __nonzero__(self): return self.asTuple() != (0.0, 0.0)
518 def __getinitargs__(self): return ()
519 def __getstate__(self): return self.asTuple()
520 def __setstate__(self, state): self.Set(*state)
521 "
522 };
523
524
525 //---------------------------------------------------------------------------
526 // Miscellaneous functions
527
528 long wxNewId();
529 void wxRegisterId(long id);
530 long wxGetCurrentId();
531
532 void wxBell();
533 void wxEndBusyCursor();
534
535 long wxGetElapsedTime(bool resetTimer = TRUE);
536 #ifdef __WXMSW__
537 long wxGetFreeMemory();
538 #endif
539 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
540 bool wxIsBusy();
541 wxString wxNow();
542 bool wxShell(const wxString& command = wxPyEmptyString);
543 void wxStartTimer();
544 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
545 wxString wxGetOsDescription();
546
547 enum wxShutdownFlags
548 {
549 wxSHUTDOWN_POWEROFF, // power off the computer
550 wxSHUTDOWN_REBOOT // shutdown and reboot
551 };
552
553 // Shutdown or reboot the PC
554 bool wxShutdown(wxShutdownFlags wFlags);
555
556
557 void wxSleep(int secs);
558 void wxUsleep(unsigned long milliseconds);
559 bool wxYield();
560 bool wxYieldIfNeeded();
561 void wxEnableTopLevelWindows(bool enable);
562
563 #ifdef wxUSE_RESOURCES
564 inline %{
565 wxString wxGetResource(const wxString& section, const wxString& entry,
566 const wxString& file = wxPyEmptyString) {
567 wxChar* retval;
568 wxGetResource(section, entry, &retval, file);
569 return retval;
570 }
571 %}
572 #endif
573
574 wxString wxStripMenuCodes(const wxString& in);
575
576
577 wxString wxGetEmailAddress();
578 wxString wxGetHostName();
579 wxString wxGetFullHostName();
580 wxString wxGetUserId();
581 wxString wxGetUserName();
582 wxString wxGetHomeDir();
583 wxString wxGetUserHome(const wxString& user = wxPyEmptyString);
584
585 unsigned long wxGetProcessId();
586
587 // When wxApp gets the virtual method magic then enable this.
588 // bool wxHandleFatalExceptions(bool doIt = TRUE);
589
590 void wxTrap();
591
592 //----------------------------------------------------------------------
593
594 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
595 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
596 enum wxRelationship { wxUnconstrained = 0,
597 wxAsIs,
598 wxPercentOf,
599 wxAbove,
600 wxBelow,
601 wxLeftOf,
602 wxRightOf,
603 wxSameAs,
604 wxAbsolute };
605
606
607 class wxIndividualLayoutConstraint : public wxObject {
608 public:
609 // wxIndividualLayoutConstraint();
610 // ~wxIndividualLayoutConstraint();
611
612 void Above(wxWindow *otherWin, int margin=0);
613 void Absolute(int value);
614 void AsIs();
615 void Below(wxWindow *otherWin, int margin=0);
616 void Unconstrained();
617 void LeftOf(wxWindow *otherWin, int margin=0);
618 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
619 void RightOf(wxWindow *otherWin, int margin=0);
620 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
621 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
622 };
623
624
625 class wxLayoutConstraints : public wxObject {
626 public:
627 wxLayoutConstraints();
628
629 %readonly
630 wxIndividualLayoutConstraint bottom;
631 wxIndividualLayoutConstraint centreX;
632 wxIndividualLayoutConstraint centreY;
633 wxIndividualLayoutConstraint height;
634 wxIndividualLayoutConstraint left;
635 wxIndividualLayoutConstraint right;
636 wxIndividualLayoutConstraint top;
637 wxIndividualLayoutConstraint width;
638 %readwrite
639 }
640
641
642
643 //---------------------------------------------------------------------------
644 // Accelerator Entry and Table
645
646 class wxAcceleratorEntry {
647 public:
648 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
649 ~wxAcceleratorEntry();
650
651 void Set(int flags, int keyCode, int Cmd);
652 int GetFlags();
653 int GetKeyCode();
654 int GetCommand();
655 };
656
657
658 class wxAcceleratorTable : public wxObject {
659 public:
660 // Can also accept a list of 3-tuples
661 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
662 ~wxAcceleratorTable();
663
664 };
665
666 wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
667
668 %readonly
669 %{
670 #if 0 // we want to use the definition from the header, not the
671 // one SWIG will generate.
672 %}
673 // See also wxPy_ReinitStockObjects in helpers.cpp
674 extern wxAcceleratorTable wxNullAcceleratorTable;
675 %{
676 #endif
677 %}
678 %readwrite
679
680 //---------------------------------------------------------------------------
681
682 class wxBusyInfo : public wxObject {
683 public:
684 wxBusyInfo(const wxString& message);
685 ~wxBusyInfo();
686 };
687
688
689 //---------------------------------------------------------------------------
690
691
692