.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2020 by Total Control Software License: wxWindows License .. include:: headings.inc .. _wx.Rect: ========================================================================================================================================== |phoenix_title| **wx.Rect** ========================================================================================================================================== Represents a rectangle with integer coordinates. ``x`` and ``y`` members specify the coordinates of the rectangle top-left corner and ``width`` and ``height`` specify its width and height respectively. The usual C++ semi-open interval convention is used: point ``p`` lies inside the rectangle if and only if both conditions below are satisfied: :: x <= p.x < (rect.x + rect.width) y <= p.y < (rect.y + rect.height) In other words, the rectangle left and right boundaries are at ``x`` and ``x+width-1`` and its top and bottom boundaries are at ``y`` and ``y+height-1`` respectively. Note that the x and y coordinates may be negative, but width and height are always strictly positive for non-empty rectangles. .. seealso:: :ref:`wx.Point`, :ref:`wx.Size` | |class_hierarchy| Class Hierarchy ================================= .. raw:: html
Inheritance diagram for class Rect:
| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~wx.Rect.__init__` Default constructor. :meth:`~wx.Rect.CenterIn` Returns the rectangle having the same size as this one but centered relatively to the given rectangle `r`. :meth:`~wx.Rect.CentreIn` Returns the rectangle having the same size as this one but centered relatively to the given rectangle `r`. :meth:`~wx.Rect.Contains` Returns ``True`` if the given point is inside the rectangle (or on its boundary) and ``False`` otherwise. :meth:`~wx.Rect.Deflate` Decrease the rectangle size. :meth:`~wx.Rect.Get` Return the rectangle's properties as a tuple. :meth:`~wx.Rect.GetBottom` Gets the bottom point of the rectangle. :meth:`~wx.Rect.GetBottomLeft` Gets the position of the bottom left corner. :meth:`~wx.Rect.GetBottomRight` Gets the position of the bottom right corner. :meth:`~wx.Rect.GetHeight` Gets the height member. :meth:`~wx.Rect.GetIM` Returns an immutable representation of the ``wx.Rect`` object, based on ``namedtuple``. :meth:`~wx.Rect.GetLeft` Gets the left point of the rectangle (the same as :meth:`~Rect.GetX` ). :meth:`~wx.Rect.GetPosition` Gets the position. :meth:`~wx.Rect.GetRight` Gets the right point of the rectangle. :meth:`~wx.Rect.GetSize` Gets the size. :meth:`~wx.Rect.GetTop` Gets the top point of the rectangle (the same as :meth:`~Rect.GetY` ). :meth:`~wx.Rect.GetTopLeft` Gets the position of the top left corner of the rectangle, same as :meth:`~Rect.GetPosition` . :meth:`~wx.Rect.GetTopRight` Gets the position of the top right corner. :meth:`~wx.Rect.GetWidth` Gets the width member. :meth:`~wx.Rect.GetX` Gets the x member. :meth:`~wx.Rect.GetY` Gets the y member. :meth:`~wx.Rect.Inflate` Increases the size of the rectangle. :meth:`~wx.Rect.Intersect` Modifies this rectangle to contain the overlapping portion of this rectangle and the one passed in as parameter. :meth:`~wx.Rect.Intersects` Returns ``True`` if this rectangle has a non-empty intersection with the rectangle `rect` and ``False`` otherwise. :meth:`~wx.Rect.IsEmpty` Returns ``True`` if this rectangle has a width or height less than or equal to 0 and ``False`` otherwise. :meth:`~wx.Rect.Offset` Moves the rectangle by the specified offset. :meth:`~wx.Rect.SetBottom` Set the bottom edge of the rectangle. :meth:`~wx.Rect.SetBottomLeft` Set the bottom-left point of the rectangle. :meth:`~wx.Rect.SetBottomRight` Set the bottom-right point of the rectangle. :meth:`~wx.Rect.SetHeight` Sets the height. :meth:`~wx.Rect.SetLeft` Set the left side of the rectangle. :meth:`~wx.Rect.SetPosition` Sets the position. :meth:`~wx.Rect.SetRight` Set the right side of the rectangle. :meth:`~wx.Rect.SetSize` Sets the size. :meth:`~wx.Rect.SetTop` Set the top edge of the rectangle. :meth:`~wx.Rect.SetTopLeft` Set the top-left point of the rectangle. :meth:`~wx.Rect.SetTopRight` Set the top-right point of the rectangle. :meth:`~wx.Rect.SetWidth` Sets the width. :meth:`~wx.Rect.SetX` Sets the x position. :meth:`~wx.Rect.SetY` Sets the y position. :meth:`~wx.Rect.Union` Modifies the rectangle to contain the bounding box of this rectangle and the one passed in as parameter. :meth:`~wx.Rect.__bool__` :meth:`~wx.Rect.__eq__` :meth:`~wx.Rect.__getitem__` :meth:`~wx.Rect.__len__` :meth:`~wx.Rect.__ne__` :meth:`~wx.Rect.__nonzero__` :meth:`~wx.Rect.__reduce__` :meth:`~wx.Rect.__repr__` :meth:`~wx.Rect.__setitem__` :meth:`~wx.Rect.__str__` :meth:`~wx.Rect.__imul__` Returns the intersection of two rectangles (which may be empty). :meth:`~wx.Rect.__iadd__` Like :meth:`~Rect.Union` , but doesn't treat empty rectangles specially. ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~wx.Rect.Bottom` See :meth:`~wx.Rect.GetBottom` and :meth:`~wx.Rect.SetBottom` :attr:`~wx.Rect.BottomLeft` See :meth:`~wx.Rect.GetBottomLeft` and :meth:`~wx.Rect.SetBottomLeft` :attr:`~wx.Rect.BottomRight` See :meth:`~wx.Rect.GetBottomRight` and :meth:`~wx.Rect.SetBottomRight` :attr:`~wx.Rect.Height` See :meth:`~wx.Rect.GetHeight` and :meth:`~wx.Rect.SetHeight` :attr:`~wx.Rect.Left` See :meth:`~wx.Rect.GetLeft` and :meth:`~wx.Rect.SetLeft` :attr:`~wx.Rect.Position` See :meth:`~wx.Rect.GetPosition` and :meth:`~wx.Rect.SetPosition` :attr:`~wx.Rect.Right` See :meth:`~wx.Rect.GetRight` and :meth:`~wx.Rect.SetRight` :attr:`~wx.Rect.Size` See :meth:`~wx.Rect.GetSize` and :meth:`~wx.Rect.SetSize` :attr:`~wx.Rect.Top` See :meth:`~wx.Rect.GetTop` and :meth:`~wx.Rect.SetTop` :attr:`~wx.Rect.TopLeft` See :meth:`~wx.Rect.GetTopLeft` and :meth:`~wx.Rect.SetTopLeft` :attr:`~wx.Rect.TopRight` See :meth:`~wx.Rect.GetTopRight` and :meth:`~wx.Rect.SetTopRight` :attr:`~wx.Rect.Width` See :meth:`~wx.Rect.GetWidth` and :meth:`~wx.Rect.SetWidth` :attr:`~wx.Rect.X` See :meth:`~wx.Rect.GetX` and :meth:`~wx.Rect.SetX` :attr:`~wx.Rect.Y` See :meth:`~wx.Rect.GetY` and :meth:`~wx.Rect.SetY` :attr:`~wx.Rect.bottom` See :meth:`~wx.Rect.GetBottom` and :meth:`~wx.Rect.SetBottom` :attr:`~wx.Rect.bottomLeft` See :meth:`~wx.Rect.GetBottomLeft` and :meth:`~wx.Rect.SetBottomLeft` :attr:`~wx.Rect.bottomRight` See :meth:`~wx.Rect.GetBottomRight` and :meth:`~wx.Rect.SetBottomRight` :attr:`~wx.Rect.left` See :meth:`~wx.Rect.GetLeft` and :meth:`~wx.Rect.SetLeft` :attr:`~wx.Rect.right` See :meth:`~wx.Rect.GetRight` and :meth:`~wx.Rect.SetRight` :attr:`~wx.Rect.top` See :meth:`~wx.Rect.GetTop` and :meth:`~wx.Rect.SetTop` :attr:`~wx.Rect.topLeft` See :meth:`~wx.Rect.GetTopLeft` and :meth:`~wx.Rect.SetTopLeft` :attr:`~wx.Rect.topRight` See :meth:`~wx.Rect.GetTopRight` and :meth:`~wx.Rect.SetTopRight` :attr:`~wx.Rect.height` A public C++ attribute of type ``int``. Height member. :attr:`~wx.Rect.width` A public C++ attribute of type ``int``. Width member. :attr:`~wx.Rect.x` A public C++ attribute of type ``int``. x coordinate of the top-left corner of the rectangle. :attr:`~wx.Rect.y` A public C++ attribute of type ``int``. y coordinate of the top-left corner of the rectangle. ================================================================================ ================================================================================ | |api| Class API =============== .. class:: wx.Rect(object) **Possible constructors**:: Rect() Rect(x, y, width, height) Rect(pos, size) Rect(size) Rect(topLeft, bottomRight) Represents a rectangle with integer coordinates. .. method:: __init__(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **__init__** `(self)` Default constructor. Initializes to zero the internal `x`, `y`, `width` and `height` members. :html:`

` **__init__** `(self, x, y, width, height)` Creates a :ref:`wx.Rect` object from `x`, `y`, `width` and `height` values. :param `x`: :type `x`: int :param `y`: :type `y`: int :param `width`: :type `width`: int :param `height`: :type `height`: int :html:`

` **__init__** `(self, pos, size)` Creates a :ref:`wx.Rect` object from position `pos` and `size` values. :param `pos`: :type `pos`: wx.Point :param `size`: :type `size`: wx.Size :html:`

` **__init__** `(self, size)` Creates a :ref:`wx.Rect` object from `size` values at the origin. :param `size`: :type `size`: wx.Size :html:`

` **__init__** `(self, topLeft, bottomRight)` Creates a :ref:`wx.Rect` object from top-left and bottom-right points. The width of the rectangle will be ``bottomRight.x-topLeft.x+1`` and the height will be ``bottomRight.y-topLeft.y+1`` . :param `topLeft`: :type `topLeft`: wx.Point :param `bottomRight`: :type `bottomRight`: wx.Point :html:`

` .. method:: CenterIn(self, r, dir=BOTH) Returns the rectangle having the same size as this one but centered relatively to the given rectangle `r`. By default, rectangle is centred in both directions but if `dir` includes only ``VERTICAL`` or only ``HORIZONTAL`` , then it is only centered in this direction while the other component of its position remains unchanged. :param `r`: :type `r`: wx.Rect :param `dir`: :type `dir`: int :rtype: :ref:`wx.Rect` .. method:: CentreIn(self, r, dir=BOTH) Returns the rectangle having the same size as this one but centered relatively to the given rectangle `r`. By default, rectangle is centred in both directions but if `dir` includes only ``VERTICAL`` or only ``HORIZONTAL`` , then it is only centered in this direction while the other component of its position remains unchanged. :param `r`: :type `r`: wx.Rect :param `dir`: :type `dir`: int :rtype: :ref:`wx.Rect` .. method:: Contains(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **Contains** `(self, x, y)` Returns ``True`` if the given point is inside the rectangle (or on its boundary) and ``False`` otherwise. :param `x`: :type `x`: int :param `y`: :type `y`: int :rtype: `bool` :html:`

` **Contains** `(self, pt)` Returns ``True`` if the given point is inside the rectangle (or on its boundary) and ``False`` otherwise. :param `pt`: :type `pt`: wx.Point :rtype: `bool` :html:`

` **Contains** `(self, rect)` Returns ``True`` if the given rectangle is completely inside this rectangle (or touches its boundary) and ``False`` otherwise. :param `rect`: :type `rect`: wx.Rect :rtype: `bool` :html:`

` .. method:: Deflate(self, *args, **kw) Decrease the rectangle size. This method is the opposite from :meth:`Inflate` : Deflate(a, b) is equivalent to Inflate(-a, -b). Please refer to :meth:`Inflate` for full description. |overload| Overloaded Implementations: :html:`

` **Deflate** `(self, dx, dy)` :param `dx`: :type `dx`: int :param `dy`: :type `dy`: int :rtype: :ref:`wx.Rect` :html:`

` **Deflate** `(self, diff)` :param `diff`: :type `diff`: wx.Size :rtype: :ref:`wx.Rect` :html:`

` **Deflate** `(self, diff)` :param `diff`: :type `diff`: int :rtype: :ref:`wx.Rect` :html:`

` .. method:: Get(self) Return the rectangle's properties as a tuple. :rtype: `tuple` :returns: ( `x`, `y`, `width`, `height` ) .. method:: GetBottom(self) Gets the bottom point of the rectangle. :rtype: `int` .. method:: GetBottomLeft(self) Gets the position of the bottom left corner. :rtype: :ref:`wx.Point` .. method:: GetBottomRight(self) Gets the position of the bottom right corner. :rtype: :ref:`wx.Point` .. method:: GetHeight(self) Gets the height member. :rtype: `int` .. method:: GetIM(self) Returns an immutable representation of the ``wx.Rect`` object, based on ``namedtuple``. This new object is hashable and can be used as a dictionary key, be added to sets, etc. It can be converted back into a real ``wx.Rect`` with a simple statement like this: ``obj = wx.Rect(imObj)``. .. method:: GetLeft(self) Gets the left point of the rectangle (the same as :meth:`GetX` ). :rtype: `int` .. method:: GetPosition(self) Gets the position. :rtype: :ref:`wx.Point` .. method:: GetRight(self) Gets the right point of the rectangle. :rtype: `int` .. method:: GetSize(self) Gets the size. :rtype: :ref:`wx.Size` .. seealso:: :meth:`SetSize` .. method:: GetTop(self) Gets the top point of the rectangle (the same as :meth:`GetY` ). :rtype: `int` .. method:: GetTopLeft(self) Gets the position of the top left corner of the rectangle, same as :meth:`GetPosition` . :rtype: :ref:`wx.Point` .. method:: GetTopRight(self) Gets the position of the top right corner. :rtype: :ref:`wx.Point` .. method:: GetWidth(self) Gets the width member. :rtype: `int` .. method:: GetX(self) Gets the x member. :rtype: `int` .. method:: GetY(self) Gets the y member. :rtype: `int` .. method:: Inflate(self, *args, **kw) Increases the size of the rectangle. The left border is moved farther left and the right border is moved farther right by `dx`. The upper border is moved farther up and the bottom border is moved farther down by `dy`. (Note that the width and height of the rectangle thus change by 2dx and 2dy, respectively.) If one or both of `dx` and `dy` are negative, the opposite happens: the rectangle size decreases in the respective direction. Inflating and deflating behaves "naturally". Defined more precisely, that means: - "Real" inflates (that is, `dx` and/or `dy` = 0) are not constrained. Thus inflating a rectangle can cause its upper left corner to move into the negative numbers. (2.5.4 and older forced the top left coordinate to not fall below (0, 0), which implied a forced move of the rectangle.) - Deflates are clamped to not reduce the width or height of the rectangle below zero. In such cases, the top-left corner is nonetheless handled properly. For example, a rectangle at (10, 10) with size (20, 40) that is inflated by (-15, -15) will become located at (20, 25) at size (0, 10). Finally, observe that the width and height are treated independently. In the above example, the width is reduced by 20, whereas the height is reduced by the full 30 (rather than also stopping at 20, when the width reached zero). .. seealso:: :meth:`Deflate` |overload| Overloaded Implementations: :html:`

` **Inflate** `(self, dx, dy)` :param `dx`: :type `dx`: int :param `dy`: :type `dy`: int :rtype: :ref:`wx.Rect` :html:`

` **Inflate** `(self, diff)` :param `diff`: :type `diff`: wx.Size :rtype: :ref:`wx.Rect` :html:`

` **Inflate** `(self, diff)` :param `diff`: :type `diff`: int :rtype: :ref:`wx.Rect` :html:`

` .. method:: Intersect(self, rect) Modifies this rectangle to contain the overlapping portion of this rectangle and the one passed in as parameter. :param `rect`: :type `rect`: wx.Rect :rtype: :ref:`wx.Rect` :returns: This rectangle, modified. .. method:: Intersects(self, rect) Returns ``True`` if this rectangle has a non-empty intersection with the rectangle `rect` and ``False`` otherwise. :param `rect`: :type `rect`: wx.Rect :rtype: `bool` .. method:: IsEmpty(self) Returns ``True`` if this rectangle has a width or height less than or equal to 0 and ``False`` otherwise. :rtype: `bool` .. method:: Offset(self, *args, **kw) Moves the rectangle by the specified offset. If `dx` is positive, the rectangle is moved to the right, if `dy` is positive, it is moved to the bottom, otherwise it is moved to the left or top respectively. |overload| Overloaded Implementations: :html:`

` **Offset** `(self, dx, dy)` :param `dx`: :type `dx`: int :param `dy`: :type `dy`: int :html:`

` **Offset** `(self, pt)` :param `pt`: :type `pt`: wx.Point :html:`

` .. method:: SetBottom(self, bottom) Set the bottom edge of the rectangle. Notice that this doesn't affect :meth:`GetTop` return value but changes the rectangle height to set its bottom side to the given position. :param `bottom`: :type `bottom`: int .. method:: SetBottomLeft(self, p) Set the bottom-left point of the rectangle. :param `p`: :type `p`: wx.Point .. method:: SetBottomRight(self, p) Set the bottom-right point of the rectangle. :param `p`: :type `p`: wx.Point .. method:: SetHeight(self, height) Sets the height. :param `height`: :type `height`: int .. method:: SetLeft(self, left) Set the left side of the rectangle. Notice that because the rectangle stores its left side and width, calling :meth:`SetLeft` changes the right side position too – but does preserve the width. :param `left`: :type `left`: int .. method:: SetPosition(self, pos) Sets the position. :param `pos`: :type `pos`: wx.Point .. method:: SetRight(self, right) Set the right side of the rectangle. Notice that this doesn't affect :meth:`GetLeft` return value but changes the rectangle width to set its right side to the given position. :param `right`: :type `right`: int .. method:: SetSize(self, s) Sets the size. :param `s`: :type `s`: wx.Size .. seealso:: :meth:`GetSize` .. method:: SetTop(self, top) Set the top edge of the rectangle. Notice that because the rectangle stores its top side and height, calling :meth:`SetTop` changes the bottom side position too – but does preserve the height. :param `top`: :type `top`: int .. method:: SetTopLeft(self, p) Set the top-left point of the rectangle. :param `p`: :type `p`: wx.Point .. method:: SetTopRight(self, p) Set the top-right point of the rectangle. :param `p`: :type `p`: wx.Point .. method:: SetWidth(self, width) Sets the width. :param `width`: :type `width`: int .. method:: SetX(self, x) Sets the x position. :param `x`: :type `x`: int .. method:: SetY(self, y) Sets the y position. :param `y`: :type `y`: int .. method:: Union(self, rect) Modifies the rectangle to contain the bounding box of this rectangle and the one passed in as parameter. :param `rect`: :type `rect`: wx.Rect :rtype: :ref:`wx.Rect` .. method:: __bool__(self) .. method:: __eq__(self, other) :rtype: `bool` .. method:: __getitem__(self, idx) .. method:: __len__(self) .. method:: __ne__(self, other) :rtype: `bool` .. method:: __nonzero__(self) .. method:: __reduce__(self) .. method:: __repr__(self) .. method:: __setitem__(self, idx, val) .. method:: __str__(self) .. method:: __imul__(self) Returns the intersection of two rectangles (which may be empty). :param `r`: :type `r`: wx.Rect .. method:: __iadd__(self) Like :meth:`Union` , but doesn't treat empty rectangles specially. :param `r`: :type `r`: wx.Rect .. attribute:: Bottom See :meth:`~wx.Rect.GetBottom` and :meth:`~wx.Rect.SetBottom` .. attribute:: BottomLeft See :meth:`~wx.Rect.GetBottomLeft` and :meth:`~wx.Rect.SetBottomLeft` .. attribute:: BottomRight See :meth:`~wx.Rect.GetBottomRight` and :meth:`~wx.Rect.SetBottomRight` .. attribute:: Height See :meth:`~wx.Rect.GetHeight` and :meth:`~wx.Rect.SetHeight` .. attribute:: Left See :meth:`~wx.Rect.GetLeft` and :meth:`~wx.Rect.SetLeft` .. attribute:: Position See :meth:`~wx.Rect.GetPosition` and :meth:`~wx.Rect.SetPosition` .. attribute:: Right See :meth:`~wx.Rect.GetRight` and :meth:`~wx.Rect.SetRight` .. attribute:: Size See :meth:`~wx.Rect.GetSize` and :meth:`~wx.Rect.SetSize` .. attribute:: Top See :meth:`~wx.Rect.GetTop` and :meth:`~wx.Rect.SetTop` .. attribute:: TopLeft See :meth:`~wx.Rect.GetTopLeft` and :meth:`~wx.Rect.SetTopLeft` .. attribute:: TopRight See :meth:`~wx.Rect.GetTopRight` and :meth:`~wx.Rect.SetTopRight` .. attribute:: Width See :meth:`~wx.Rect.GetWidth` and :meth:`~wx.Rect.SetWidth` .. attribute:: X See :meth:`~wx.Rect.GetX` and :meth:`~wx.Rect.SetX` .. attribute:: Y See :meth:`~wx.Rect.GetY` and :meth:`~wx.Rect.SetY` .. attribute:: bottom See :meth:`~wx.Rect.GetBottom` and :meth:`~wx.Rect.SetBottom` .. attribute:: bottomLeft See :meth:`~wx.Rect.GetBottomLeft` and :meth:`~wx.Rect.SetBottomLeft` .. attribute:: bottomRight See :meth:`~wx.Rect.GetBottomRight` and :meth:`~wx.Rect.SetBottomRight` .. attribute:: height A public C++ attribute of type ``int``. Height member. .. attribute:: left See :meth:`~wx.Rect.GetLeft` and :meth:`~wx.Rect.SetLeft` .. attribute:: right See :meth:`~wx.Rect.GetRight` and :meth:`~wx.Rect.SetRight` .. attribute:: top See :meth:`~wx.Rect.GetTop` and :meth:`~wx.Rect.SetTop` .. attribute:: topLeft See :meth:`~wx.Rect.GetTopLeft` and :meth:`~wx.Rect.SetTopLeft` .. attribute:: topRight See :meth:`~wx.Rect.GetTopRight` and :meth:`~wx.Rect.SetTopRight` .. attribute:: width A public C++ attribute of type ``int``. Width member. .. attribute:: x A public C++ attribute of type ``int``. x coordinate of the top-left corner of the rectangle. .. attribute:: y A public C++ attribute of type ``int``. y coordinate of the top-left corner of the rectangle.