A wx.Region represents a simple or complex region on a device context or window.
This class uses reference counting and copy-on-write internally so that assignments between two instances of this class are very cheap. You can therefore use actual objects instead of pointers without efficiency problems. If an instance of this class is changed it will create its own data internally so that other instances, which previously shared the data using the reference counting, are not affected.
See also
Default constructor. |
|
Clears the current region. |
|
Returns a value indicating whether the given point is contained within the region. |
|
Convert the region to a black and white bitmap with the white pixels being inside the region. |
|
Returns the outer bounds of the region. |
|
Finds the intersection of this region and another, rectangular region, specified using position and size. |
|
Returns |
|
Returns |
|
Moves the region by the specified offsets in horizontal and vertical directions. |
|
Subtracts a rectangular region from this region. |
|
Finds the union of this region and another, rectangular region, specified using position and size. |
|
Finds the Xor of this region and another, rectangular region, specified using position and size. |
|
Returns a rectangle iterator conforming to the Python iterator |
See |
wx.
Region
(GDIObject)¶Possible constructors:
Region()
Region(x, y, width, height)
Region(topLeft, bottomRight)
Region(rect)
Region(region)
Region(bmp)
Region(bmp, transColour, tolerance=0)
Region(points, fillStyle=ODDEVEN_RULE)
A Region represents a simple or complex region on a device context or window.
__init__
(self, *args, **kw)¶__init__ (self)
Default constructor.
This constructor creates an invalid, or null, object, i.e. calling IsOk() on it returns False
and IsEmpty
returns True
.
__init__ (self, x, y, width, height)
Constructs a rectangular region with the given position and size.
x (int) –
y (int) –
width (int) –
height (int) –
__init__ (self, topLeft, bottomRight)
Constructs a rectangular region from the top left point and the bottom right point.
__init__ (self, rect)
Constructs a rectangular region a wx.Rect object.
rect (wx.Rect) –
__init__ (self, region)
Copy constructor, uses Reference Counting.
region (wx.Region) –
__init__ (self, bmp)
Constructs a region using a bitmap.
See Union
for more details.
bmp (wx.Bitmap) –
__init__ (self, bmp, transColour, tolerance=0)
Constructs a region using the non-transparent pixels of a bitmap.
See Union
for more details.
__init__ (self, points, fillStyle=ODDEVEN_RULE)
Constructs a region corresponding to the polygon made from the points in the provided sequence.
Clear
(self)¶Clears the current region.
The object becomes invalid, or null, after being cleared.
Contains
(self, *args, **kw)¶Contains (self, x, y)
Returns a value indicating whether the given point is contained within the region.
This method always returns OutRegion
for an invalid region but may, nevertheless, be safely called in this case.
x (int) –
y (int) –
The return value is one of OutRegion
and InRegion
.
Contains (self, pt)
Returns a value indicating whether the given point is contained within the region.
This method always returns OutRegion
for an invalid region but may, nevertheless, be safely called in this case.
pt (wx.Point) –
The return value is one of OutRegion
and InRegion
.
Contains (self, x, y, width, height)
Returns a value indicating whether the given rectangle is contained within the region.
This method always returns OutRegion
for an invalid region but may, nevertheless, be safely called in this case.
x (int) –
y (int) –
width (int) –
height (int) –
One of wx.OutRegion
, wx.PartRegion
or wx.InRegion
.
Note
On Windows, only wx.OutRegion
and wx.InRegion
are returned; a value wx.InRegion
then indicates that all or some part of the region is contained in this region.
Contains (self, rect)
Returns a value indicating whether the given rectangle is contained within the region.
This method always returns OutRegion
for an invalid region but may, nevertheless, be safely called in this case.
rect (wx.Rect) –
One of wx.OutRegion
, wx.PartRegion
or wx.InRegion
.
Note
On Windows, only wx.OutRegion
and wx.InRegion
are returned; a value wx.InRegion
then indicates that all or some part of the region is contained in this region.
ConvertToBitmap
(self)¶Convert the region to a black and white bitmap with the white pixels being inside the region.
This method can’t be used for invalid region.
GetBox
(self)¶Returns the outer bounds of the region.
This method returns 0-sized bounding box for invalid regions.
Intersect
(self, *args, **kw)¶Intersect (self, x, y, width, height)
Finds the intersection of this region and another, rectangular region, specified using position and size.
This method always fails, i.e. returns False
, if this region is invalid but may nevertheless be safely used even in this case.
x (int) –
y (int) –
width (int) –
height (int) –
bool
True
if successful, False
otherwise.
Note
Creates the intersection of the two regions, that is, the parts which are in both regions. The result is stored in this region.
Intersect (self, rect)
Finds the intersection of this region and another, rectangular region.
This method always fails, i.e. returns False
, if this region is invalid but may nevertheless be safely used even in this case.
rect (wx.Rect) –
bool
True
if successful, False
otherwise.
Note
Creates the intersection of the two regions, that is, the parts which are in both regions. The result is stored in this region.
Intersect (self, region)
Finds the intersection of this region and another region.
This method always fails, i.e. returns False
, if this region is invalid but may nevertheless be safely used even in this case.
region (wx.Region) –
bool
True
if successful, False
otherwise.
Note
Creates the intersection of the two regions, that is, the parts which are in both regions. The result is stored in this region.
IsEmpty
(self)¶Returns True
if the region is empty, False
otherwise.
Always returns True
if the region is invalid.
bool
IsEqual
(self, region)¶Returns True
if the region is equal to, i.e. covers the same area as, another one.
If both this region and region are both invalid, they are considered to be equal.
region (wx.Region) –
bool
Offset
(self, *args, **kw)¶Moves the region by the specified offsets in horizontal and vertical directions.
This method can’t be called if the region is invalid as it doesn’t make sense to offset it then. Attempts to do it will result in assert failure.
True
if successful, False
otherwise (the region is unchanged then).
Offset (self, x, y)
x (int) –
y (int) –
bool
Offset (self, pt)
pt (wx.Point) –
bool
Subtract
(self, *args, **kw)¶Subtract (self, rect)
Subtracts a rectangular region from this region.
This method always fails, i.e. returns False
, if this region is invalid but may nevertheless be safely used even in this case.
rect (wx.Rect) –
bool
True
if successful, False
otherwise.
Note
This operation combines the parts of ‘this’ region that are not part of the second region. The result is stored in this region.
Subtract (self, region)
Subtracts a region from this region.
This method always fails, i.e. returns False
, if this region is invalid but may nevertheless be safely used even in this case.
region (wx.Region) –
bool
True
if successful, False
otherwise.
Note
This operation combines the parts of ‘this’ region that are not part of the second region. The result is stored in this region.
Union
(self, *args, **kw)¶Union (self, x, y, width, height)
Finds the union of this region and another, rectangular region, specified using position and size.
This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given rectangle.
x (int) –
y (int) –
width (int) –
height (int) –
bool
True
if successful, False
otherwise.
Note
This operation creates a region that combines all of this region and the second region. The result is stored in this region.
Union (self, rect)
Finds the union of this region and another, rectangular region.
This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given rectangle.
rect (wx.Rect) –
bool
True
if successful, False
otherwise.
Note
This operation creates a region that combines all of this region and the second region. The result is stored in this region.
Union (self, region)
Finds the union of this region and another region.
This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given region.
region (wx.Region) –
bool
True
if successful, False
otherwise.
Note
This operation creates a region that combines all of this region and the second region. The result is stored in this region.
Union (self, bmp)
Finds the union of this region and the non-transparent pixels of a bitmap.
The bitmap’s mask is used to determine transparency. If the bitmap doesn’t have a mask, the bitmap’s full dimensions are used.
bmp (wx.Bitmap) –
bool
True
if successful, False
otherwise.
Note
This operation creates a region that combines all of this region and the second region. The result is stored in this region.
Union (self, bmp, transColour, tolerance=0)
Finds the union of this region and the non-transparent pixels of a bitmap.
Colour to be treated as transparent is specified in the transColour argument, along with an optional colour tolerance value.
bool
True
if successful, False
otherwise.
Note
This operation creates a region that combines all of this region and the second region. The result is stored in this region.
Xor
(self, *args, **kw)¶Xor (self, x, y, width, height)
Finds the Xor of this region and another, rectangular region, specified using position and size.
This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given rectangle.
x (int) –
y (int) –
width (int) –
height (int) –
bool
True
if successful, False
otherwise.
Note
This operation creates a region that combines all of this region and the second region, except for any overlapping areas. The result is stored in this region.
Xor (self, rect)
Finds the Xor of this region and another, rectangular region.
This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given rectangle.
rect (wx.Rect) –
bool
True
if successful, False
otherwise.
Note
This operation creates a region that combines all of this region and the second region, except for any overlapping areas. The result is stored in this region.
Xor (self, region)
Finds the Xor of this region and another region.
This method can be used even if this region is invalid and has the natural behaviour in this case, i.e. makes this region equal to the given region.
region (wx.Region) –
bool
True
if successful, False
otherwise.
Note
This operation creates a region that combines all of this region and the second region, except for any overlapping areas. The result is stored in this region.
__iter__
(self)¶Returns a rectangle iterator conforming to the Python iterator protocol.