phoenix_title wx.Region

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.


class_hierarchy Class Hierarchy

Inheritance diagram for class Region:

method_summary Methods Summary

__init__

Default constructor.

Clear

Clears the current region.

Contains

Returns a value indicating whether the given point is contained within the region.

ConvertToBitmap

Convert the region to a black and white bitmap with the white pixels being inside the region.

GetBox

Returns the outer bounds of the region.

Intersect

Finds the intersection of this region and another, rectangular region, specified using position and size.

IsEmpty

Returns True if the region is empty, False otherwise.

IsEqual

Returns True if the region is equal to, i.e. covers the same area as, another one.

Offset

Moves the region by the specified offsets in horizontal and vertical directions.

Subtract

Subtracts a rectangular region from this region.

Union

Finds the union of this region and another, rectangular region, specified using position and size.

Xor

Finds the Xor of this region and another, rectangular region, specified using position and size.

__iter__

Returns a rectangle iterator conforming to the Python iterator


property_summary Properties Summary

Box

See GetBox


api Class API

class 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.


Methods

__init__(self, *args, **kw)

overload Overloaded Implementations:



__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.

Parameters
  • 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.

Parameters



__init__ (self, rect)

Constructs a rectangular region a wx.Rect object.

Parameters

rect (wx.Rect) –



__init__ (self, region)

Copy constructor, uses Reference Counting.

Parameters

region (wx.Region) –



__init__ (self, bmp)

Constructs a region using a bitmap.

See Union for more details.

Parameters

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.

Parameters



__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)

overload Overloaded Implementations:



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.

Parameters
  • x (int) –

  • y (int) –

Return type

wx.RegionContain

Returns

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.

Parameters

pt (wx.Point) –

Return type

wx.RegionContain

Returns

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.

Parameters
  • x (int) –

  • y (int) –

  • width (int) –

  • height (int) –

Return type

wx.RegionContain

Returns

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.

Parameters

rect (wx.Rect) –

Return type

wx.RegionContain

Returns

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.

Return type

wx.Bitmap



GetBox(self)

Returns the outer bounds of the region.

This method returns 0-sized bounding box for invalid regions.

Return type

wx.Rect



Intersect(self, *args, **kw)

overload Overloaded Implementations:



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.

Parameters
  • x (int) –

  • y (int) –

  • width (int) –

  • height (int) –

Return type

bool

Returns

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.

Parameters

rect (wx.Rect) –

Return type

bool

Returns

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.

Parameters

region (wx.Region) –

Return type

bool

Returns

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.

Return type

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.

Parameters

region (wx.Region) –

Return type

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.

Returns

True if successful, False otherwise (the region is unchanged then).

overload Overloaded Implementations:



Offset (self, x, y)

Parameters
  • x (int) –

  • y (int) –

Return type

bool



Offset (self, pt)

Parameters

pt (wx.Point) –

Return type

bool





Subtract(self, *args, **kw)

overload Overloaded Implementations:



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.

Parameters

rect (wx.Rect) –

Return type

bool

Returns

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.

Parameters

region (wx.Region) –

Return type

bool

Returns

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)

overload Overloaded Implementations:



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.

Parameters
  • x (int) –

  • y (int) –

  • width (int) –

  • height (int) –

Return type

bool

Returns

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.

Parameters

rect (wx.Rect) –

Return type

bool

Returns

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.

Parameters

region (wx.Region) –

Return type

bool

Returns

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.

Parameters

bmp (wx.Bitmap) –

Return type

bool

Returns

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.

Parameters
Return type

bool

Returns

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)

overload Overloaded Implementations:



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.

Parameters
  • x (int) –

  • y (int) –

  • width (int) –

  • height (int) –

Return type

bool

Returns

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.

Parameters

rect (wx.Rect) –

Return type

bool

Returns

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.

Parameters

region (wx.Region) –

Return type

bool

Returns

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.


Properties

Box

See GetBox