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