]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_gdicmn.i
Add some missing wxPyBeginBlockThreads calls
[wxWidgets.git] / wxPython / src / _gdicmn.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _gdicmn.i
3 // Purpose: SWIG interface for common GDI stuff and misc classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 13-Sept-2003
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
20 enum wxBitmapType
21 {
22 wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
23 wxBITMAP_TYPE_BMP,
24 wxBITMAP_TYPE_ICO,
25 wxBITMAP_TYPE_CUR,
26 wxBITMAP_TYPE_XBM,
27 wxBITMAP_TYPE_XBM_DATA,
28 wxBITMAP_TYPE_XPM,
29 wxBITMAP_TYPE_XPM_DATA,
30 wxBITMAP_TYPE_TIF,
31 wxBITMAP_TYPE_GIF,
32 wxBITMAP_TYPE_PNG,
33 wxBITMAP_TYPE_JPEG,
34 wxBITMAP_TYPE_PNM,
35 wxBITMAP_TYPE_PCX,
36 wxBITMAP_TYPE_PICT,
37 wxBITMAP_TYPE_ICON,
38 wxBITMAP_TYPE_ANI,
39 wxBITMAP_TYPE_IFF,
40 wxBITMAP_TYPE_MACCURSOR,
41
42 // wxBITMAP_TYPE_BMP_RESOURCE,
43 // wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE,
44 // wxBITMAP_TYPE_ICO_RESOURCE,
45 // wxBITMAP_TYPE_CUR_RESOURCE,
46 // wxBITMAP_TYPE_TIF_RESOURCE,
47 // wxBITMAP_TYPE_GIF_RESOURCE,
48 // wxBITMAP_TYPE_PNG_RESOURCE,
49 // wxBITMAP_TYPE_JPEG_RESOURCE,
50 // wxBITMAP_TYPE_PNM_RESOURCE,
51 // wxBITMAP_TYPE_PCX_RESOURCE,
52 // wxBITMAP_TYPE_PICT_RESOURCE,
53 // wxBITMAP_TYPE_ICON_RESOURCE,
54 // wxBITMAP_TYPE_MACCURSOR_RESOURCE,
55
56 wxBITMAP_TYPE_ANY = 50
57 };
58
59 // Standard cursors
60 enum wxStockCursor
61 {
62 wxCURSOR_NONE, // should be 0
63 wxCURSOR_ARROW,
64 wxCURSOR_RIGHT_ARROW,
65 wxCURSOR_BULLSEYE,
66 wxCURSOR_CHAR,
67 wxCURSOR_CROSS,
68 wxCURSOR_HAND,
69 wxCURSOR_IBEAM,
70 wxCURSOR_LEFT_BUTTON,
71 wxCURSOR_MAGNIFIER,
72 wxCURSOR_MIDDLE_BUTTON,
73 wxCURSOR_NO_ENTRY,
74 wxCURSOR_PAINT_BRUSH,
75 wxCURSOR_PENCIL,
76 wxCURSOR_POINT_LEFT,
77 wxCURSOR_POINT_RIGHT,
78 wxCURSOR_QUESTION_ARROW,
79 wxCURSOR_RIGHT_BUTTON,
80 wxCURSOR_SIZENESW,
81 wxCURSOR_SIZENS,
82 wxCURSOR_SIZENWSE,
83 wxCURSOR_SIZEWE,
84 wxCURSOR_SIZING,
85 wxCURSOR_SPRAYCAN,
86 wxCURSOR_WAIT,
87 wxCURSOR_WATCH,
88 wxCURSOR_BLANK,
89 wxCURSOR_DEFAULT, // standard X11 cursor
90 wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow
91
92 // #ifdef __X__
93 // // Not yet implemented for Windows
94 // wxCURSOR_CROSS_REVERSE,
95 // wxCURSOR_DOUBLE_ARROW,
96 // wxCURSOR_BASED_ARROW_UP,
97 // wxCURSOR_BASED_ARROW_DOWN,
98 // #endif // X11
99
100 wxCURSOR_ARROWWAIT,
101
102 wxCURSOR_MAX
103 };
104
105 %{
106 #ifndef __WXMAC__
107 #define wxCURSOR_COPY_ARROW wxCURSOR_ARROW
108 #endif
109 %}
110
111 //---------------------------------------------------------------------------
112 %newgroup
113
114 DocStr( wxSize,
115 "wx.Size is a useful data structure used to represent the size of
116 something. It simply contains integer width and height
117 properties. In most places in wxPython where a wx.Size is
118 expected a (width, height) tuple can be used instead.", "");
119
120 class wxSize
121 {
122 public:
123 %Rename(width, int, x);
124 %Rename(height,int, y);
125 %pythoncode { x = width; y = height }
126
127 DocCtorStr(
128 wxSize(int w=0, int h=0),
129 "Creates a size object.", "");
130
131 ~wxSize();
132
133
134 %extend {
135 KeepGIL(__eq__);
136 DocStr(__eq__, "Test for equality of wx.Size objects.", "");
137 bool __eq__(PyObject* other) {
138 wxSize temp, *obj = &temp;
139 if ( other == Py_None ) return false;
140 if ( ! wxSize_helper(other, &obj) ) {
141 PyErr_Clear();
142 return false;
143 }
144 return self->operator==(*obj);
145 }
146
147
148 KeepGIL(__ne__);
149 DocStr(__ne__, "Test for inequality of wx.Size objects.", "");
150 bool __ne__(PyObject* other) {
151 wxSize temp, *obj = &temp;
152 if ( other == Py_None ) return true;
153 if ( ! wxSize_helper(other, &obj)) {
154 PyErr_Clear();
155 return true;
156 }
157 return self->operator!=(*obj);
158 }
159 }
160
161 DocDeclStr(
162 wxSize, operator+(const wxSize& sz),
163 "Add sz's proprties to this and return the result.", "");
164
165 DocDeclStr(
166 wxSize, operator-(const wxSize& sz),
167 "Subtract sz's properties from this and return the result.", "");
168
169 DocDeclStr(
170 void, IncTo(const wxSize& sz),
171 "Increments this object so that both of its dimensions are not less
172 than the corresponding dimensions of the size.", "");
173
174 DocDeclStr(
175 void, DecTo(const wxSize& sz),
176 "Decrements this object so that both of its dimensions are not greater
177 than the corresponding dimensions of the size.", "");
178
179 DocDeclStr(
180 void, Set(int w, int h),
181 "Set both width and height.", "");
182
183 void SetWidth(int w);
184 void SetHeight(int h);
185 int GetWidth() const;
186 int GetHeight() const;
187
188
189 DocDeclStr(
190 bool , IsFullySpecified() const,
191 "Returns True if both components of the size are non-default values.", "");
192
193
194 DocDeclStr(
195 void , SetDefaults(const wxSize& size),
196 "Combine this size with the other one replacing the default components
197 of this object (i.e. equal to -1) with those of the other.", "");
198
199
200 //int GetX() const;
201 //int GetY() const;
202
203 %extend {
204 DocAStr(Get,
205 "Get() -> (width,height)",
206 "Returns the width and height properties as a tuple.", "");
207 PyObject* Get() {
208 wxPyBlock_t blocked = wxPyBeginBlockThreads();
209 PyObject* tup = PyTuple_New(2);
210 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
211 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
212 wxPyEndBlockThreads(blocked);
213 return tup;
214 }
215 }
216 %pythoncode {
217 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
218 def __str__(self): return str(self.Get())
219 def __repr__(self): return 'wx.Size'+str(self.Get())
220 def __len__(self): return len(self.Get())
221 def __getitem__(self, index): return self.Get()[index]
222 def __setitem__(self, index, val):
223 if index == 0: self.width = val
224 elif index == 1: self.height = val
225 else: raise IndexError
226 def __nonzero__(self): return self.Get() != (0,0)
227 __safe_for_unpickling__ = True
228 def __reduce__(self): return (wx.Size, self.Get())
229 }
230
231 };
232
233 //---------------------------------------------------------------------------
234 %newgroup
235
236 DocStr( wxRealPoint,
237 "A data structure for representing a point or position with floating
238 point x and y properties. In wxPython most places that expect a
239 wx.RealPoint can also accept a (x,y) tuple.", "");
240 class wxRealPoint
241 {
242 public:
243 double x;
244 double y;
245
246 DocCtorStr(
247 wxRealPoint(double x=0.0, double y=0.0),
248 "Create a wx.RealPoint object", "");
249
250 ~wxRealPoint();
251
252 %extend {
253 KeepGIL(__eq__);
254 DocStr(__eq__, "Test for equality of wx.RealPoint objects.", "");
255 bool __eq__(PyObject* other) {
256 wxRealPoint temp, *obj = &temp;
257 if ( other == Py_None ) return false;
258 if ( ! wxRealPoint_helper(other, &obj) ) {
259 PyErr_Clear();
260 return false;
261 }
262 return self->operator==(*obj);
263 }
264
265
266 KeepGIL(__ne__);
267 DocStr(__ne__, "Test for inequality of wx.RealPoint objects.", "");
268 bool __ne__(PyObject* other) {
269 wxRealPoint temp, *obj = &temp;
270 if ( other == Py_None ) return true;
271 if ( ! wxRealPoint_helper(other, &obj)) {
272 PyErr_Clear();
273 return true;
274 }
275 return self->operator!=(*obj);
276 }
277 }
278
279
280 DocDeclStr(
281 wxRealPoint, operator+(const wxRealPoint& pt),
282 "Add pt's proprties to this and return the result.", "");
283
284 DocDeclStr(
285 wxRealPoint, operator-(const wxRealPoint& pt),
286 "Subtract pt's proprties from this and return the result", "");
287
288
289 %extend {
290 DocStr(Set, "Set both the x and y properties", "");
291 void Set(double x, double y) {
292 self->x = x;
293 self->y = y;
294 }
295
296 DocAStr(Get,
297 "Get() -> (x,y)",
298 "Return the x and y properties as a tuple. ", "");
299 PyObject* Get() {
300 wxPyBlock_t blocked = wxPyBeginBlockThreads();
301 PyObject* tup = PyTuple_New(2);
302 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
303 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
304 wxPyEndBlockThreads(blocked);
305 return tup;
306 }
307 }
308
309 %pythoncode {
310 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
311 def __str__(self): return str(self.Get())
312 def __repr__(self): return 'wx.RealPoint'+str(self.Get())
313 def __len__(self): return len(self.Get())
314 def __getitem__(self, index): return self.Get()[index]
315 def __setitem__(self, index, val):
316 if index == 0: self.x = val
317 elif index == 1: self.y = val
318 else: raise IndexError
319 def __nonzero__(self): return self.Get() != (0.0, 0.0)
320 __safe_for_unpickling__ = True
321 def __reduce__(self): return (wx.RealPoint, self.Get())
322 }
323 };
324
325
326 //---------------------------------------------------------------------------
327 %newgroup
328
329
330 DocStr(wxPoint,
331 "A data structure for representing a point or position with integer x
332 and y properties. Most places in wxPython that expect a wx.Point can
333 also accept a (x,y) tuple.", "");
334
335 class wxPoint
336 {
337 public:
338 int x, y;
339
340 DocCtorStr(
341 wxPoint(int x=0, int y=0),
342 "Create a wx.Point object", "");
343
344 ~wxPoint();
345
346
347 %extend {
348 KeepGIL(__eq__);
349 DocStr(__eq__, "Test for equality of wx.Point objects.", "");
350 bool __eq__(PyObject* other) {
351 wxPoint temp, *obj = &temp;
352 if ( other == Py_None ) return false;
353 if ( ! wxPoint_helper(other, &obj) ) {
354 PyErr_Clear();
355 return false;
356 }
357 return self->operator==(*obj);
358 }
359
360
361 KeepGIL(__ne__);
362 DocStr(__ne__, "Test for inequality of wx.Point objects.", "");
363 bool __ne__(PyObject* other) {
364 wxPoint temp, *obj = &temp;
365 if ( other == Py_None ) return true;
366 if ( ! wxPoint_helper(other, &obj)) {
367 PyErr_Clear();
368 return true;
369 }
370 return self->operator!=(*obj);
371 }
372 }
373
374
375 // %nokwargs operator+;
376 // %nokwargs operator-;
377 // %nokwargs operator+=;
378 // %nokwargs operator-=;
379
380 DocDeclStr(
381 wxPoint, operator+(const wxPoint& pt),
382 "Add pt's proprties to this and return the result.", "");
383
384
385 DocDeclStr(
386 wxPoint, operator-(const wxPoint& pt),
387 "Subtract pt's proprties from this and return the result", "");
388
389
390 DocDeclStr(
391 wxPoint&, operator+=(const wxPoint& pt),
392 "Add pt to this object.", "");
393
394 DocDeclStr(
395 wxPoint&, operator-=(const wxPoint& pt),
396 "Subtract pt from this object.", "");
397
398
399
400 // DocDeclStr(
401 // wxPoint, operator+(const wxSize& sz),
402 // "Add sz to this Point and return the result.", "");
403
404 // DocDeclStr(
405 // wxPoint, operator-(const wxSize& sz),
406 // "Subtract sz from this Point and return the result", "");
407
408
409 // DocDeclStr(
410 // wxPoint&, operator+=(const wxSize& sz),
411 // "Add sz to this object.", "");
412
413 // DocDeclStr(
414 // wxPoint&, operator-=(const wxSize& sz),
415 // "Subtract sz from this object.", "");
416
417
418
419
420 %extend {
421 DocStr(Set, "Set both the x and y properties", "");
422 void Set(long x, long y) {
423 self->x = x;
424 self->y = y;
425 }
426
427 DocAStr(Get,
428 "Get() -> (x,y)",
429 "Return the x and y properties as a tuple. ", "");
430 PyObject* Get() {
431 wxPyBlock_t blocked = wxPyBeginBlockThreads();
432 PyObject* tup = PyTuple_New(2);
433 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
434 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
435 wxPyEndBlockThreads(blocked);
436 return tup;
437 }
438 }
439
440 %pythoncode {
441 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
442 def __str__(self): return str(self.Get())
443 def __repr__(self): return 'wx.Point'+str(self.Get())
444 def __len__(self): return len(self.Get())
445 def __getitem__(self, index): return self.Get()[index]
446 def __setitem__(self, index, val):
447 if index == 0: self.x = val
448 elif index == 1: self.y = val
449 else: raise IndexError
450 def __nonzero__(self): return self.Get() != (0,0)
451 __safe_for_unpickling__ = True
452 def __reduce__(self): return (wx.Point, self.Get())
453 }
454 };
455
456 //---------------------------------------------------------------------------
457 %newgroup
458
459
460 DocStr(wxRect,
461 "A class for representing and manipulating rectangles. It has x, y,
462 width and height properties. In wxPython most palces that expect a
463 wx.Rect can also accept a (x,y,width,height) tuple.", "");
464
465 class wxRect
466 {
467 public:
468 DocCtorStr(
469 wxRect(int x=0, int y=0, int width=0, int height=0),
470 "Create a new Rect object.", "");
471
472 DocCtorStrName(
473 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight),
474 "Create a new Rect object from Points representing two corners.", "",
475 RectPP);
476
477 DocCtorStrName(
478 wxRect(const wxPoint& pos, const wxSize& size),
479 "Create a new Rect from a position and size.", "",
480 RectPS);
481
482 DocCtorStrName(
483 wxRect(const wxSize& size),
484 "Create a new Rect from a size only.", "",
485 RectS);
486
487 ~wxRect();
488
489 int GetX() const;
490 void SetX(int x);
491
492 int GetY();
493 void SetY(int y);
494
495 int GetWidth() const;
496 void SetWidth(int w);
497
498 int GetHeight() const;
499 void SetHeight(int h);
500
501 wxPoint GetPosition() const;
502 void SetPosition( const wxPoint &p );
503
504 wxSize GetSize() const;
505 void SetSize( const wxSize &s );
506
507 bool IsEmpty() const;
508
509 wxPoint GetTopLeft() const;
510 void SetTopLeft(const wxPoint &p);
511 wxPoint GetBottomRight() const;
512 void SetBottomRight(const wxPoint &p);
513
514 // wxPoint GetLeftTop() const;
515 // void SetLeftTop(const wxPoint &p);
516 // wxPoint GetRightBottom() const;
517 // void SetRightBottom(const wxPoint &p);
518
519 int GetLeft() const;
520 int GetTop() const;
521 int GetBottom() const;
522 int GetRight() const;
523
524 void SetLeft(int left);
525 void SetRight(int right);
526 void SetTop(int top);
527 void SetBottom(int bottom);
528
529 %pythoncode {
530 position = property(GetPosition, SetPosition)
531 size = property(GetSize, SetSize)
532 left = property(GetLeft, SetLeft)
533 right = property(GetRight, SetRight)
534 top = property(GetTop, SetTop)
535 bottom = property(GetBottom, SetBottom)
536 }
537
538 DocDeclStr(
539 wxRect&, Inflate(wxCoord dx, wxCoord dy),
540 "Increases the size of the rectangle.
541
542 The left border is moved farther left and the right border is moved
543 farther right by ``dx``. The upper border is moved farther up and the
544 bottom border is moved farther down by ``dy``. (Note the the width and
545 height of the rectangle thus change by ``2*dx`` and ``2*dy``,
546 respectively.) If one or both of ``dx`` and ``dy`` are negative, the
547 opposite happens: the rectangle size decreases in the respective
548 direction.
549
550 The change is made to the rectangle inplace, if instead you need a
551 copy that is inflated, preserving the original then make the copy
552 first::
553
554 copy = wx.Rect(*original)
555 copy.Inflate(10,15)
556
557 ", "
558 Inflating and deflating behaves *naturally*. Defined more precisely,
559 that means:
560
561 * Real inflates (that is, ``dx`` and/or ``dy`` >= 0) are not
562 constrained. Thus inflating a rectangle can cause its upper left
563 corner to move into the negative numbers. (The versions prior to
564 2.5.4 forced the top left coordinate to not fall below (0, 0),
565 which implied a forced move of the rectangle.)
566
567 * Deflates are clamped to not reduce the width or height of the
568 rectangle below zero. In such cases, the top-left corner is
569 nonetheless handled properly. For example, a rectangle at (10,
570 10) with size (20, 40) that is inflated by (-15, -15) will
571 become located at (20, 25) at size (0, 10). Finally, observe
572 that the width and height are treated independently. In the
573 above example, the width is reduced by 20, whereas the height is
574 reduced by the full 30 (rather than also stopping at 20, when
575 the width reached zero).
576
577 :see: `Deflate`
578 ");
579
580 DocDeclStr(
581 wxRect&, Deflate(wxCoord dx, wxCoord dy),
582 "Decrease the rectangle size. This method is the opposite of `Inflate`
583 in that Deflate(a,b) is equivalent to Inflate(-a,-b). Please refer to
584 `Inflate` for a full description.", "");
585
586 DocDeclStrName(
587 void, Offset(wxCoord dx, wxCoord dy),
588 "Moves the rectangle by the specified offset. If dx is positive, the
589 rectangle is moved to the right, if dy is positive, it is moved to the
590 bottom, otherwise it is moved to the left or top respectively.", "",
591 OffsetXY);
592
593 DocDeclStr(
594 void, Offset(const wxPoint& pt),
595 "Same as `OffsetXY` but uses dx,dy from Point", "");
596
597 DocDeclStr(
598 wxRect, Intersect(const wxRect& rect),
599 "Returns the intersectsion of this rectangle and rect.", "");
600
601 DocDeclStr(
602 wxRect , Union(const wxRect& rect),
603 "Returns the union of this rectangle and rect.", "");
604
605
606 DocDeclStr(
607 wxRect, operator+(const wxRect& rect) const,
608 "Add the properties of rect to this rectangle and return the result.", "");
609
610 DocDeclStr(
611 wxRect&, operator+=(const wxRect& rect),
612 "Add the properties of rect to this rectangle, updating this rectangle.", "");
613
614 %extend {
615 KeepGIL(__eq__);
616 DocStr(__eq__, "Test for equality of wx.Rect objects.", "");
617 bool __eq__(PyObject* other) {
618 wxRect temp, *obj = &temp;
619 if ( other == Py_None ) return false;
620 if ( ! wxRect_helper(other, &obj) ) {
621 PyErr_Clear();
622 return false;
623 }
624 return self->operator==(*obj);
625 }
626
627
628 KeepGIL(__ne__);
629 DocStr(__ne__, "Test for inequality of wx.Rect objects.", "");
630 bool __ne__(PyObject* other) {
631 wxRect temp, *obj = &temp;
632 if ( other == Py_None ) return true;
633 if ( ! wxRect_helper(other, &obj)) {
634 PyErr_Clear();
635 return true;
636 }
637 return self->operator!=(*obj);
638 }
639 }
640
641
642 DocStr( Inside, "Return True if the point is (not strcitly) inside the rect.", "");
643 %Rename(InsideXY, bool, Inside(int x, int y) const);
644 bool Inside(const wxPoint& pt) const;
645
646 DocDeclStr(
647 bool, Intersects(const wxRect& rect) const,
648 "Returns True if the rectangles have a non empty intersection.", "");
649
650 DocDeclStr(
651 wxRect, CenterIn(const wxRect& r, int dir = wxBOTH),
652 "Center this rectangle within the one passed to the method, which is
653 usually, but not necessarily, the larger one.", "");
654 %pythoncode { CentreIn = CenterIn }
655
656
657 int x, y, width, height;
658
659
660 %extend {
661 DocStr(Set, "Set all rectangle properties.", "");
662 void Set(int x=0, int y=0, int width=0, int height=0) {
663 self->x = x;
664 self->y = y;
665 self->width = width;
666 self->height = height;
667 }
668
669 DocAStr(Get,
670 "Get() -> (x,y,width,height)",
671 "Return the rectangle properties as a tuple.", "");
672 PyObject* Get() {
673 wxPyBlock_t blocked = wxPyBeginBlockThreads();
674 PyObject* tup = PyTuple_New(4);
675 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
676 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
677 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
678 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
679 wxPyEndBlockThreads(blocked);
680 return tup;
681 }
682 }
683
684 %pythoncode {
685 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
686 def __str__(self): return str(self.Get())
687 def __repr__(self): return 'wx.Rect'+str(self.Get())
688 def __len__(self): return len(self.Get())
689 def __getitem__(self, index): return self.Get()[index]
690 def __setitem__(self, index, val):
691 if index == 0: self.x = val
692 elif index == 1: self.y = val
693 elif index == 2: self.width = val
694 elif index == 3: self.height = val
695 else: raise IndexError
696 def __nonzero__(self): return self.Get() != (0,0,0,0)
697 __safe_for_unpickling__ = True
698 def __reduce__(self): return (wx.Rect, self.Get())
699 }
700 };
701
702
703 MustHaveApp(wxIntersectRect);
704
705 DocAStr(wxIntersectRect,
706 "IntersectRect(Rect r1, Rect r2) -> Rect",
707 "Calculate and return the intersection of r1 and r2.", "");
708 %inline %{
709 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
710 wxRegion reg1(*r1);
711 wxRegion reg2(*r2);
712 wxRect dest(0,0,0,0);
713 PyObject* obj;
714
715 reg1.Intersect(reg2);
716 dest = reg1.GetBox();
717
718 if (dest != wxRect(0,0,0,0)) {
719 wxPyBlock_t blocked = wxPyBeginBlockThreads();
720 wxRect* newRect = new wxRect(dest);
721 obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true);
722 wxPyEndBlockThreads(blocked);
723 return obj;
724 }
725 Py_INCREF(Py_None);
726 return Py_None;
727 }
728 %}
729
730 //---------------------------------------------------------------------------
731 %newgroup
732
733
734 DocStr(wxPoint2D,
735 "wx.Point2Ds represent a point or a vector in a 2d coordinate system
736 with floating point values.", "");
737
738 class wxPoint2D
739 {
740 public:
741 DocStr(wxPoint2D, "Create a w.Point2D object.", "");
742 wxPoint2D( double x=0.0 , double y=0.0 );
743 %RenameCtor(Point2DCopy, wxPoint2D( const wxPoint2D &pt ));
744 %RenameCtor(Point2DFromPoint, wxPoint2D( const wxPoint &pt ));
745
746 DocDeclAStr(
747 void, GetFloor( int *OUTPUT , int *OUTPUT ) const,
748 "GetFloor() -> (x,y)",
749 "Convert to integer", "");
750
751 DocDeclAStr(
752 void, GetRounded( int *OUTPUT , int *OUTPUT ) const,
753 "GetRounded() -> (x,y)",
754 "Convert to integer", "");
755
756 double GetVectorLength() const;
757 double GetVectorAngle() const ;
758 void SetVectorLength( double length );
759 void SetVectorAngle( double degrees );
760
761 // LinkError: void SetPolarCoordinates( double angle , double length );
762 // LinkError: void Normalize();
763 %pythoncode {
764 def SetPolarCoordinates(self, angle, length):
765 self.SetVectorLength(length)
766 self.SetVectorAngle(angle)
767 def Normalize(self):
768 self.SetVectorLength(1.0)
769 }
770
771 double GetDistance( const wxPoint2D &pt ) const;
772 double GetDistanceSquare( const wxPoint2D &pt ) const;
773 double GetDotProduct( const wxPoint2D &vec ) const;
774 double GetCrossProduct( const wxPoint2D &vec ) const;
775
776 DocDeclStr(
777 wxPoint2D, operator-(),
778 "the reflection of this point", "");
779
780 wxPoint2D& operator+=(const wxPoint2D& pt);
781 wxPoint2D& operator-=(const wxPoint2D& pt);
782
783 wxPoint2D& operator*=(const wxPoint2D& pt);
784 wxPoint2D& operator/=(const wxPoint2D& pt);
785
786 %extend {
787 KeepGIL(__eq__);
788 DocStr(__eq__, "Test for equality of wx.Point2D objects.", "");
789 bool __eq__(PyObject* other) {
790 wxPoint2D temp, *obj = &temp;
791 if ( other == Py_None ) return false;
792 if ( ! wxPoint2D_helper(other, &obj) ) {
793 PyErr_Clear();
794 return false;
795 }
796 return self->operator==(*obj);
797 }
798
799
800 KeepGIL(__ne__);
801 DocStr(__ne__, "Test for inequality of wx.Point2D objects.", "");
802 bool __ne__(PyObject* other) {
803 wxPoint2D temp, *obj = &temp;
804 if ( other == Py_None ) return true;
805 if ( ! wxPoint2D_helper(other, &obj)) {
806 PyErr_Clear();
807 return true;
808 }
809 return self->operator!=(*obj);
810 }
811 }
812
813 %Rename(x, double, m_x);
814 %Rename(y, double, m_y);
815
816 %extend {
817 void Set( double x=0 , double y=0 ) {
818 self->m_x = x;
819 self->m_y = y;
820 }
821
822 DocAStr(Get,
823 "Get() -> (x,y)",
824 "Return x and y properties as a tuple.", "");
825 PyObject* Get() {
826 wxPyBlock_t blocked = wxPyBeginBlockThreads();
827 PyObject* tup = PyTuple_New(2);
828 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
829 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
830 wxPyEndBlockThreads(blocked);
831 return tup;
832 }
833 }
834
835 %pythoncode {
836 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
837 def __str__(self): return str(self.Get())
838 def __repr__(self): return 'wx.Point2D'+str(self.Get())
839 def __len__(self): return len(self.Get())
840 def __getitem__(self, index): return self.Get()[index]
841 def __setitem__(self, index, val):
842 if index == 0: self.x = val
843 elif index == 1: self.y = val
844 else: raise IndexError
845 def __nonzero__(self): return self.Get() != (0.0, 0.0)
846 __safe_for_unpickling__ = True
847 def __reduce__(self): return (wx.Point2D, self.Get())
848 }
849 };
850
851
852 //---------------------------------------------------------------------------
853
854 %immutable;
855 const wxPoint wxDefaultPosition;
856 const wxSize wxDefaultSize;
857 %mutable;
858
859 //---------------------------------------------------------------------------