X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bea992c87396ddd230043542b752d47da89cec44..d7645bfd20e2b197b2d73043e602f947610e44ff:/wxPython/src/_gdicmn.i?ds=sidebyside diff --git a/wxPython/src/_gdicmn.i b/wxPython/src/_gdicmn.i index bb54248466..7d2ff9e7ba 100644 --- a/wxPython/src/_gdicmn.i +++ b/wxPython/src/_gdicmn.i @@ -17,6 +17,11 @@ %newgroup +// Turn off the aquisition of the Global Interpreter Lock for the classes and +// functions in this file +%threadWrapperOff + + enum wxBitmapType { wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility! @@ -37,6 +42,7 @@ enum wxBitmapType wxBITMAP_TYPE_ICON, wxBITMAP_TYPE_ANI, wxBITMAP_TYPE_IFF, + wxBITMAP_TYPE_TGA, wxBITMAP_TYPE_MACCURSOR, // wxBITMAP_TYPE_BMP_RESOURCE, @@ -130,19 +136,33 @@ public: ~wxSize(); -// None/NULL is now handled properly by the typemap, so these are not needed. -// %extend { -// bool __eq__(const wxSize* other) { return other ? (*self == *other) : false; } -// bool __ne__(const wxSize* other) { return other ? (*self != *other) : true; } -// } - - DocDeclStr( - bool, operator==(const wxSize& sz), - "Test for equality of wx.Size objects.", ""); + + %extend { + //KeepGIL(__eq__); + DocStr(__eq__, "Test for equality of wx.Size objects.", ""); + bool __eq__(PyObject* other) { + wxSize temp, *obj = &temp; + if ( other == Py_None ) return false; + if ( ! wxSize_helper(other, &obj) ) { + PyErr_Clear(); + return false; + } + return self->operator==(*obj); + } - DocDeclStr( - bool, operator!=(const wxSize& sz), - "Test for inequality.", ""); + + //KeepGIL(__ne__); + DocStr(__ne__, "Test for inequality of wx.Size objects.", ""); + bool __ne__(PyObject* other) { + wxSize temp, *obj = &temp; + if ( other == Py_None ) return true; + if ( ! wxSize_helper(other, &obj)) { + PyErr_Clear(); + return true; + } + return self->operator!=(*obj); + } + } DocDeclStr( wxSize, operator+(const wxSize& sz), @@ -162,6 +182,26 @@ than the corresponding dimensions of the size.", ""); "Decrements this object so that both of its dimensions are not greater than the corresponding dimensions of the size.", ""); + + DocDeclStr( + void , IncBy(int dx, int dy), + "", ""); + + + DocDeclStr( + void , DecBy(int dx, int dy), + "", ""); + +// TODO: handle these overloads too? +// void IncBy(const wxSize& sz); +// void IncBy(int d); +// void DecBy(const wxSize& sz); +// void DecBy(int d); + + DocDeclStr( + void , Scale(float xscale, float yscale), + "Scales the dimensions of this object by the given factors.", ""); + DocDeclStr( void, Set(int w, int h), "Set both width and height.", ""); @@ -191,11 +231,11 @@ of this object (i.e. equal to -1) with those of the other.", ""); "Get() -> (width,height)", "Returns the width and height properties as a tuple.", ""); PyObject* Get() { - wxPyBlock_t blocked = wxPyBeginBlockThreads(); + //wxPyBlock_t blocked = wxPyBeginBlockThreads(); PyObject* tup = PyTuple_New(2); PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); - wxPyEndBlockThreads(blocked); + //wxPyEndBlockThreads(blocked); return tup; } } @@ -235,13 +275,32 @@ public: ~wxRealPoint(); - DocDeclStr( - bool, operator==(const wxRealPoint& pt), - "Test for equality of wx.RealPoint objects.", ""); + %extend { + //KeepGIL(__eq__); + DocStr(__eq__, "Test for equality of wx.RealPoint objects.", ""); + bool __eq__(PyObject* other) { + wxRealPoint temp, *obj = &temp; + if ( other == Py_None ) return false; + if ( ! wxRealPoint_helper(other, &obj) ) { + PyErr_Clear(); + return false; + } + return self->operator==(*obj); + } - DocDeclStr( - bool, operator!=(const wxRealPoint& pt), - "Test for inequality of wx.RealPoint objects.", ""); + + //KeepGIL(__ne__); + DocStr(__ne__, "Test for inequality of wx.RealPoint objects.", ""); + bool __ne__(PyObject* other) { + wxRealPoint temp, *obj = &temp; + if ( other == Py_None ) return true; + if ( ! wxRealPoint_helper(other, &obj)) { + PyErr_Clear(); + return true; + } + return self->operator!=(*obj); + } + } DocDeclStr( @@ -264,11 +323,11 @@ public: "Get() -> (x,y)", "Return the x and y properties as a tuple. ", ""); PyObject* Get() { - wxPyBlock_t blocked = wxPyBeginBlockThreads(); + //wxPyBlock_t blocked = wxPyBeginBlockThreads(); PyObject* tup = PyTuple_New(2); PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x)); PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y)); - wxPyEndBlockThreads(blocked); + //PyEndBlockThreads(blocked); return tup; } } @@ -311,14 +370,32 @@ public: ~wxPoint(); - DocDeclStr( - bool, operator==(const wxPoint& pt), - "Test for equality of wx.Point objects.", ""); - - DocDeclStr( - bool, operator!=(const wxPoint& pt), - "Test for inequality of wx.Point objects.", ""); + %extend { + //KeepGIL(__eq__); + DocStr(__eq__, "Test for equality of wx.Point objects.", ""); + bool __eq__(PyObject* other) { + wxPoint temp, *obj = &temp; + if ( other == Py_None ) return false; + if ( ! wxPoint_helper(other, &obj) ) { + PyErr_Clear(); + return false; + } + return self->operator==(*obj); + } + + //KeepGIL(__ne__); + DocStr(__ne__, "Test for inequality of wx.Point objects.", ""); + bool __ne__(PyObject* other) { + wxPoint temp, *obj = &temp; + if ( other == Py_None ) return true; + if ( ! wxPoint_helper(other, &obj)) { + PyErr_Clear(); + return true; + } + return self->operator!=(*obj); + } + } // %nokwargs operator+; @@ -377,11 +454,11 @@ public: "Get() -> (x,y)", "Return the x and y properties as a tuple. ", ""); PyObject* Get() { - wxPyBlock_t blocked = wxPyBeginBlockThreads(); + //wxPyBlock_t blocked = wxPyBeginBlockThreads(); PyObject* tup = PyTuple_New(2); PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); - wxPyEndBlockThreads(blocked); + //wxPyEndBlockThreads(blocked); return tup; } } @@ -460,10 +537,19 @@ public: wxPoint GetBottomRight() const; void SetBottomRight(const wxPoint &p); + wxPoint GetTopRight() const; + void SetTopRight(const wxPoint &p); + wxPoint GetBottomLeft() const; + void SetBottomLeft(const wxPoint &p); + // wxPoint GetLeftTop() const; // void SetLeftTop(const wxPoint &p); // wxPoint GetRightBottom() const; // void SetRightBottom(const wxPoint &p); +// wxPoint GetRightTop() const; +// void SetRightTop(const wxPoint &p); +// wxPoint GetLeftBottom() const; +// void SetLeftBottom(const wxPoint &p); int GetLeft() const; int GetTop() const; @@ -484,6 +570,7 @@ public: bottom = property(GetBottom, SetBottom) } + DocDeclStr( wxRect&, Inflate(wxCoord dx, wxCoord dy), "Increases the size of the rectangle. @@ -526,12 +613,21 @@ that means: :see: `Deflate` "); + // There are also these versions... + //wxRect& Inflate(const wxSize& d); + //wxRect& Inflate(wxCoord d); + + DocDeclStr( wxRect&, Deflate(wxCoord dx, wxCoord dy), "Decrease the rectangle size. This method is the opposite of `Inflate` in that Deflate(a,b) is equivalent to Inflate(-a,-b). Please refer to `Inflate` for a full description.", ""); + // There are also these versions... + //wxRect& Deflate(const wxSize& d) { return Inflate(-d.x, -d.y); } + //wxRect& Deflate(wxCoord d) { return Inflate(-d); } + DocDeclStrName( void, Offset(wxCoord dx, wxCoord dy), "Moves the rectangle by the specified offset. If dx is positive, the @@ -560,19 +656,53 @@ bottom, otherwise it is moved to the left or top respectively.", "", wxRect&, operator+=(const wxRect& rect), "Add the properties of rect to this rectangle, updating this rectangle.", ""); - DocDeclStr( - bool, operator==(const wxRect& rect) const, - "Test for equality.", ""); + %extend { + //KeepGIL(__eq__); + DocStr(__eq__, "Test for equality of wx.Rect objects.", ""); + bool __eq__(PyObject* other) { + wxRect temp, *obj = &temp; + if ( other == Py_None ) return false; + if ( ! wxRect_helper(other, &obj) ) { + PyErr_Clear(); + return false; + } + return self->operator==(*obj); + } - DocDeclStr( - bool, operator!=(const wxRect& rect) const, - "Test for inequality.", ""); + + //KeepGIL(__ne__); + DocStr(__ne__, "Test for inequality of wx.Rect objects.", ""); + bool __ne__(PyObject* other) { + wxRect temp, *obj = &temp; + if ( other == Py_None ) return true; + if ( ! wxRect_helper(other, &obj)) { + PyErr_Clear(); + return true; + } + return self->operator!=(*obj); + } + } - DocStr( Inside, "Return True if the point is (not strcitly) inside the rect.", ""); - %Rename(InsideXY, bool, Inside(int x, int y) const); - bool Inside(const wxPoint& pt) const; + DocStr( Contains, "Return True if the point is inside the rect.", ""); + %Rename(ContainsXY, bool, Contains(int x, int y) const); + bool Contains(const wxPoint& pt) const; + DocDeclStrName( + bool, Contains(const wxRect& rect) const, + "Returns ``True`` if the given rectangle is completely inside this +rectangle or touches its boundary.", "", + ContainsRect); + + %pythoncode { + %#Inside = wx._deprecated(Contains, "Use `Contains` instead.") + %#InsideXY = wx._deprecated(ContainsXY, "Use `ContainsXY` instead.") + %#InsideRect = wx._deprecated(ContainsRect, "Use `ContainsRect` instead.") + Inside = Contains + InsideXY = ContainsXY + InsideRect = ContainsRect + } + DocDeclStr( bool, Intersects(const wxRect& rect) const, "Returns True if the rectangles have a non empty intersection.", ""); @@ -600,13 +730,13 @@ usually, but not necessarily, the larger one.", ""); "Get() -> (x,y,width,height)", "Return the rectangle properties as a tuple.", ""); PyObject* Get() { - wxPyBlock_t blocked = wxPyBeginBlockThreads(); + //wxPyBlock_t blocked = wxPyBeginBlockThreads(); PyObject* tup = PyTuple_New(4); PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x)); PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y)); PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width)); PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height)); - wxPyEndBlockThreads(blocked); + //wxPyEndBlockThreads(blocked); return tup; } } @@ -627,6 +757,24 @@ usually, but not necessarily, the larger one.", ""); __safe_for_unpickling__ = True def __reduce__(self): return (wx.Rect, self.Get()) } + + + %property(Bottom, GetBottom, SetBottom, doc="See `GetBottom` and `SetBottom`"); + %property(BottomRight, GetBottomRight, SetBottomRight, doc="See `GetBottomRight` and `SetBottomRight`"); + %property(BottomLeft, GetBottomLeft, SetBottomLeft, doc="See `GetBottomLeft` and `SetBottomLeft`"); + %property(Height, GetHeight, SetHeight, doc="See `GetHeight` and `SetHeight`"); + %property(Left, GetLeft, SetLeft, doc="See `GetLeft` and `SetLeft`"); + %property(Position, GetPosition, SetPosition, doc="See `GetPosition` and `SetPosition`"); + %property(Right, GetRight, SetRight, doc="See `GetRight` and `SetRight`"); + %property(Size, GetSize, SetSize, doc="See `GetSize` and `SetSize`"); + %property(Top, GetTop, SetTop, doc="See `GetTop` and `SetTop`"); + %property(TopLeft, GetTopLeft, SetTopLeft, doc="See `GetTopLeft` and `SetTopLeft`"); + %property(TopRight, GetTopRight, SetTopRight, doc="See `GetTopRight` and `SetTopRight`"); + %property(Width, GetWidth, SetWidth, doc="See `GetWidth` and `SetWidth`"); + %property(X, GetX, SetX, doc="See `GetX` and `SetX`"); + %property(Y, GetY, SetY, doc="See `GetY` and `SetY`"); + + %property(Empty, IsEmpty, doc="See `IsEmpty`"); }; @@ -646,10 +794,10 @@ DocAStr(wxIntersectRect, dest = reg1.GetBox(); if (dest != wxRect(0,0,0,0)) { - wxPyBlock_t blocked = wxPyBeginBlockThreads(); + //wxPyBlock_t blocked = wxPyBeginBlockThreads(); wxRect* newRect = new wxRect(dest); obj = wxPyConstructObject((void*)newRect, wxT("wxRect"), true); - wxPyEndBlockThreads(blocked); + //wxPyEndBlockThreads(blocked); return obj; } Py_INCREF(Py_None); @@ -673,6 +821,8 @@ public: %RenameCtor(Point2DCopy, wxPoint2D( const wxPoint2D &pt )); %RenameCtor(Point2DFromPoint, wxPoint2D( const wxPoint &pt )); + ~wxPoint2D(); + DocDeclAStr( void, GetFloor( int *OUTPUT , int *OUTPUT ) const, "GetFloor() -> (x,y)", @@ -713,13 +863,32 @@ public: wxPoint2D& operator*=(const wxPoint2D& pt); wxPoint2D& operator/=(const wxPoint2D& pt); - DocDeclStr( - bool, operator==(const wxPoint2D& pt) const, - "Test for equality", ""); - - DocDeclStr( - bool, operator!=(const wxPoint2D& pt) const, - "Test for inequality", ""); + %extend { + //KeepGIL(__eq__); + DocStr(__eq__, "Test for equality of wx.Point2D objects.", ""); + bool __eq__(PyObject* other) { + wxPoint2D temp, *obj = &temp; + if ( other == Py_None ) return false; + if ( ! wxPoint2D_helper(other, &obj) ) { + PyErr_Clear(); + return false; + } + return self->operator==(*obj); + } + + + //KeepGIL(__ne__); + DocStr(__ne__, "Test for inequality of wx.Point2D objects.", ""); + bool __ne__(PyObject* other) { + wxPoint2D temp, *obj = &temp; + if ( other == Py_None ) return true; + if ( ! wxPoint2D_helper(other, &obj)) { + PyErr_Clear(); + return true; + } + return self->operator!=(*obj); + } + } %Rename(x, double, m_x); %Rename(y, double, m_y); @@ -734,11 +903,11 @@ public: "Get() -> (x,y)", "Return x and y properties as a tuple.", ""); PyObject* Get() { - wxPyBlock_t blocked = wxPyBeginBlockThreads(); + //wxPyBlock_t blocked = wxPyBeginBlockThreads(); PyObject* tup = PyTuple_New(2); PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x)); PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y)); - wxPyEndBlockThreads(blocked); + //wxPyEndBlockThreads(blocked); return tup; } } @@ -757,9 +926,186 @@ public: __safe_for_unpickling__ = True def __reduce__(self): return (wx.Point2D, self.Get()) } + + %property(Floor, GetFloor, doc="See `GetFloor`"); + %property(Rounded, GetRounded, doc="See `GetRounded`"); + %property(VectorAngle, GetVectorAngle, SetVectorAngle, doc="See `GetVectorAngle` and `SetVectorAngle`"); + %property(VectorLength, GetVectorLength, SetVectorLength, doc="See `GetVectorLength` and `SetVectorLength`"); + }; +//--------------------------------------------------------------------------- +%newgroup + + +enum wxOutCode +{ + wxInside = 0x00 , + wxOutLeft = 0x01 , + wxOutRight = 0x02 , + wxOutTop = 0x08 , + wxOutBottom = 0x04 +}; + + +DocStr(wxRect2D, + "wx.Rect2D is a rectangle, with position and size, in a 2D coordinate system +with floating point component values.", ""); + +class wxRect2D +{ +public: + wxRect2D(wxDouble x=0.0, wxDouble y=0.0, wxDouble w=0.0, wxDouble h=0.0); + + ~wxRect2D(); + + wxPoint2D GetPosition(); + wxSize GetSize(); + + // for the edge and corner accessors there are two setters conterparts, + // the Set.. functions keep the other corners at their position whenever + // sensible, the Move.. functions keep the size of the rect and move the + // other corners apropriately + + wxDouble GetLeft() const; + void SetLeft( wxDouble n ); + void MoveLeftTo( wxDouble n ); + wxDouble GetTop() const; + void SetTop( wxDouble n ); + void MoveTopTo( wxDouble n ); + wxDouble GetBottom() const; + void SetBottom( wxDouble n ); + void MoveBottomTo( wxDouble n ); + wxDouble GetRight() const; + void SetRight( wxDouble n ); + void MoveRightTo( wxDouble n ); + + wxPoint2D GetLeftTop() const; + void SetLeftTop( const wxPoint2D &pt ); + void MoveLeftTopTo( const wxPoint2D &pt ); + wxPoint2D GetLeftBottom() const; + void SetLeftBottom( const wxPoint2D &pt ); + void MoveLeftBottomTo( const wxPoint2D &pt ); + wxPoint2D GetRightTop() const; + void SetRightTop( const wxPoint2D &pt ); + void MoveRightTopTo( const wxPoint2D &pt ); + wxPoint2D GetRightBottom() const; + void SetRightBottom( const wxPoint2D &pt ); + void MoveRightBottomTo( const wxPoint2D &pt ); + wxPoint2D GetCentre() const; + void SetCentre( const wxPoint2D &pt ); + void MoveCentreTo( const wxPoint2D &pt ); + wxOutCode GetOutcode(const wxPoint2D &pt) const; + bool Contains( const wxPoint2D &pt ) const; + %Rename(ContainsRect, bool , Contains( const wxRect2D &rect ) const); + bool IsEmpty() const; + bool HaveEqualSize( const wxRect2D &rect ) const; + + %nokwargs Inset; + void Inset( wxDouble x , wxDouble y ); + void Inset( wxDouble left , wxDouble top ,wxDouble right , wxDouble bottom ); + void Offset( const wxPoint2D &pt ); + + void ConstrainTo( const wxRect2D &rect ); + + wxPoint2D Interpolate( wxInt32 widthfactor , wxInt32 heightfactor ); + + //static void Intersect( const wxRect2D &src1 , const wxRect2D &src2 , wxRect2D *dest ); + + void Intersect( const wxRect2D &otherRect ); + wxRect2D CreateIntersection( const wxRect2D &otherRect ) const; + bool Intersects( const wxRect2D &rect ) const; + + // static void Union( const wxRect2D &src1 , const wxRect2D &src2 , wxRect2D *dest ); + + void Union( const wxRect2D &otherRect ); + //void Union( const wxPoint2D &pt ); + + wxRect2D CreateUnion( const wxRect2D &otherRect ) const; + + %nokwargs Scale; + void Scale( wxDouble f ); + void Scale( int num , int denum ); + + //wxRect2D& operator = (const wxRect2D& rect); + //bool operator == (const wxRect2D& rect) const; + //bool operator != (const wxRect2D& rect) const; + + %extend { + //KeepGIL(__eq__); + DocStr(__eq__, "Test for equality of wx.Rect2D objects.", ""); + bool __eq__(PyObject* other) { + wxRect2D temp, *obj = &temp; + if ( other == Py_None ) return false; + if ( ! wxRect2D_helper(other, &obj) ) { + PyErr_Clear(); + return false; + } + return self->operator==(*obj); + } + + + //KeepGIL(__ne__); + DocStr(__ne__, "Test for inequality of wx.Rect2D objects.", ""); + bool __ne__(PyObject* other) { + wxRect2D temp, *obj = &temp; + if ( other == Py_None ) return true; + if ( ! wxRect2D_helper(other, &obj)) { + PyErr_Clear(); + return true; + } + return self->operator!=(*obj); + } + } + + + %Rename(x, wxDouble , m_x); + %Rename(y, wxDouble , m_y); + %Rename(width, wxDouble , m_width); + %Rename(height, wxDouble , m_height); + + %extend { + void Set( wxDouble x=0 , wxDouble y=0, wxDouble width=0, wxDouble height=0 ) { + self->m_x = x; + self->m_y = y; + self->m_width = width; + self->m_height = height; + } + + DocAStr(Get, + "Get() -> (x,y, width, height)", + "Return x, y, width and height y properties as a tuple.", ""); + PyObject* Get() { + //wxPyBlock_t blocked = wxPyBeginBlockThreads(); + PyObject* tup = PyTuple_New(4); + PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x)); + PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y)); + PyTuple_SET_ITEM(tup, 2, PyFloat_FromDouble(self->m_width)); + PyTuple_SET_ITEM(tup, 3, PyFloat_FromDouble(self->m_height)); + //wxPyEndBlockThreads(blocked); + return tup; + } + } + + %pythoncode { + def __str__(self): return str(self.Get()) + def __repr__(self): return 'wx.Rect2D'+str(self.Get()) + def __len__(self): return len(self.Get()) + def __getitem__(self, index): return self.Get()[index] + def __setitem__(self, index, val): + if index == 0: self.x = val + elif index == 1: self.y = val + elif index == 2: self.width = val + elif index == 3: self.height = val + else: raise IndexError + def __nonzero__(self): return self.Get() != (0.0, 0.0, 0.0, 0.0) + __safe_for_unpickling__ = True + def __reduce__(self): return (wx.Rect2D, self.Get()) + } + +}; + //--------------------------------------------------------------------------- %immutable; @@ -768,3 +1114,6 @@ const wxSize wxDefaultSize; %mutable; //--------------------------------------------------------------------------- + +// Turn GIL acquisition back on. +%threadWrapperOn