wx.Pen¶
A pen is a drawing tool for drawing outlines.
It is used for drawing lines and painting the outline of rectangles, ellipses, etc. It has a colour, a width and a style.
Do not initialize objects on the stack before the program commences, since other required structures may not have been set up yet. Instead, define global pointers to objects and create them in wx.App.OnInit
or when required.
An application may wish to dynamically create pens with different characteristics, and there is the consequent danger that a large number of duplicate pens will be created. Therefore an application may wish to get a pointer to a pen by using the global list of pens wx.ThePenList , and calling the member function wx.PenList.FindOrCreatePen
. See wx.PenList for more info.
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.
Note
On a monochrome display, wxWidgets shows all non-white pens as black.
See also
Class Hierarchy¶
Methods Summary¶
Default constructor. |
|
Returns the pen cap style, which may be one of |
|
Returns a reference to the pen colour. |
|
Gets an array of dashes (defined as |
|
Returns the pen join style, which may be one of |
|
Returns the pen quality. |
|
Gets a pointer to the stipple bitmap. |
|
Returns the pen style. |
|
Returns the pen width. |
|
Returns |
|
Returns |
|
Returns |
|
Sets the pen cap style, which may be one of |
|
The pen’s colour is changed to the given colour. |
|
Associates an array of dash values (defined as |
|
Sets the pen join style, which may be one of |
|
Sets the pen quality. |
|
Sets the bitmap for stippling. |
|
Set the pen style. |
|
Sets the pen width. |
|
For internal use only. |
|
Inequality operator. |
|
Equality operator. |
Properties Summary¶
See |
|
See |
|
Class API¶
- class wx.Pen(GDIObject)¶
Possible constructors:
Pen() -> None Pen(info) -> None Pen(colour, width=1, style=PENSTYLE_SOLID) -> None Pen(pen) -> None
A pen is a drawing tool for drawing outlines.
Methods¶
- __init__(self, *args, **kw)¶
-
__init__ (self)
Default constructor.
The pen will be uninitialised, and
IsOk
will returnFalse
.- Return type:
None
__init__ (self, info)
Creates a pen object using the specified pen description.
- Parameters:
info (wx.PenInfo)
- Return type:
None
__init__ (self, colour, width=1, style=PENSTYLE_SOLID)
Constructs a pen from a colour object, pen width and style.
- Parameters:
colour (wx.Colour) – A colour object.
width (int) – Pen width. Under Windows, the pen width cannot be greater than 1 if the style is
PENSTYLE_DOT
,PENSTYLE_LONG_DASH
,PENSTYLE_SHORT_DASH
,PENSTYLE_DOT_DASH
, orPENSTYLE_USER_DASH
.style (PenStyle) – The style may be one of the wx.PenStyle values.
- Return type:
None
Note
Different versions of Windows and different versions of other platforms support very different subsets of the styles above so handle with care.
__init__ (self, pen)
Copy constructor, uses Reference Counting.
- Parameters:
pen (wx.Pen) – A pointer or reference to a pen to copy.
- Return type:
None
- GetCap(self)¶
Returns the pen cap style, which may be one of
CAP_ROUND
,CAP_PROJECTING
andCAP_BUTT
.The default is
CAP_ROUND
.- Return type:
See also
- GetDashes(self)¶
Gets an array of dashes (defined as
char
in X,DWORD
under Windows).dashes is a pointer to the internal array. Do not deallocate or store this pointer.
- Return type:
List[int]
- Returns:
The number of dashes associated with this pen.
See also
- GetJoin(self)¶
Returns the pen join style, which may be one of
JOIN_BEVEL
,JOIN_ROUND
andJOIN_MITER
.The default is
JOIN_ROUND
.- Return type:
See also
- GetQuality(self)¶
Returns the pen quality.
The default is
PEN_QUALITY_DEFAULT
.- Return type:
See also
- GetStipple(self)¶
Gets a pointer to the stipple bitmap.
- Return type:
See also
- GetStyle(self)¶
Returns the pen style.
- Return type:
- IsNonTransparent(self)¶
Returns
True
if the pen is a valid non-transparent pen.This method returns
True
if the pen object is initialized and has a non-transparent style. Notice that this should be used instead of simply testing whetherGetStyle
returns a style different fromwx.PENSTYLE_TRANSPARENT
if the pen may be invalid asGetStyle
would assert in this case.- Return type:
bool
Added in version 2.9.2..
See also
- IsOk(self)¶
Returns
True
if the pen is initialised.Notice that an uninitialized pen object can’t be queried for any pen properties and all calls to the accessor methods on it will result in an assert failure.
- Return type:
bool
- IsTransparent(self)¶
Returns
True
if the pen is transparent.A transparent pen is simply a pen with
wx.PENSTYLE_TRANSPARENT
style.Notice that this function works even for non-initialized pens (for which it returns
False
) unlike tests of the formGetStyle
==wx.PENSTYLE_TRANSPARENT
which would assert if the pen is invalid.- Return type:
bool
Added in version 2.9.2..
See also
- SetCap(self, capStyle)¶
Sets the pen cap style, which may be one of
CAP_ROUND
,CAP_PROJECTING
andCAP_BUTT
.The default is
CAP_ROUND
.- Parameters:
capStyle (PenCap)
- Return type:
None
See also
- SetColour(self, *args, **kw)¶
The pen’s colour is changed to the given colour.
See also
SetColour (self, colour)
- Parameters:
colour (wx.Colour)
- Return type:
None
SetColour (self, red, green, blue)
- Parameters:
red (int)
green (int)
blue (int)
- Return type:
None
- SetDashes(self, dashes)¶
Associates an array of dash values (defined as
char
in X,DWORD
under Windows) with the pen.The array is not deallocated by wx.Pen, but neither must it be deallocated by the calling application until the pen is deleted or this function is called with a
None
array.- Parameters:
dashes (list of integers)
- Return type:
None
See also
- SetJoin(self, join_style)¶
Sets the pen join style, which may be one of
JOIN_BEVEL
,JOIN_ROUND
andJOIN_MITER
.The default is
JOIN_ROUND
.- Parameters:
join_style (PenJoin)
- Return type:
None
See also
- SetQuality(self, quality)¶
Sets the pen quality.
Explicitly selecting low pen quality may be useful in wxMSW if drawing performance is more important than the exact appearance of the lines drawn with this pen.
- Parameters:
quality (PenQuality)
- Return type:
None
Added in version 4.1/wxWidgets-3.1.5.
See also
- SetStipple(self, stipple)¶
Sets the bitmap for stippling.
- Parameters:
stipple (wx.Bitmap)
- Return type:
None
See also
- SetWidth(self, width)¶
Sets the pen width.
- Parameters:
width (int)
- Return type:
None
See also
- _copyFrom(self, other)¶
For internal use only.
- Return type:
None
- __ne__(self, pen)¶
Inequality operator.
See reference-counted object comparison for more info.
- Parameters:
pen (wx.Pen)
- Return type:
bool
- __eq__(self, pen)¶
Equality operator.
See reference-counted object comparison for more info.
- Parameters:
pen (wx.Pen)
- Return type:
bool
Properties¶
- Quality¶
See
GetQuality
andSetQuality
- Stipple¶
See
GetStipple
andSetStipple