wx.Pen

Inheritance diagram for wx.Pen:



Description

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.

Predefined Pens

wxPython has a number of predefined pens (built-in), which are:

  • wx.RED_PEN
  • wx.CYAN_PEN
  • wx.GREEN_PEN
  • wx.BLACK_PEN
  • wx.WHITE_PEN
  • wx.TRANSPARENT_PEN
  • wx.BLACK_DASHED_PEN
  • wx.GREY_PEN
  • wx.MEDIUM_GREY_PEN
  • wx.LIGHT_GREY_PEN

Derived From

Remarks

On a monochrome display, wxWidgets shows all non-white pens as black.

An application may wish to dynamically create pens with different string 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 FindOrCreatePen. See the entry for wx.PenList.

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 API

Methods

__init__(colour, width=1, style=wx.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 wx.DOT, wx.LONG_DASH, wx.SHORT_DASH, wx.DOT_DASH, or wx.USER_DASH.

  • style (int): The style may be one of the following:

    Pen Styles

    Description

    wx.SOLID

    Solid style.

    wx.TRANSPARENT

    No pen is used.

    wx.DOT

    Dotted style.

    wx.LONG_DASH

    Long dashed style.

    wx.SHORT_DASH

    Short dashed style.

    wx.DOT_DASH

    Dot and dash style.

    wx.STIPPLE

    Use the stipple bitmap.

    wx.USER_DASH

    Use the user dashes: see SetDashes

    wx.BDIAGONAL_HATCH

    Backward diagonal hatch.

    wx.CROSSDIAG_HATCH

    Cross-diagonal hatch.

    wx.FDIAGONAL_HATCH

    Forward diagonal hatch.

    wx.CROSS_HATCH

    Cross hatch.

    wx.HORIZONTAL_HATCH

    Horizontal hatch.

    wx.VERTICAL_HATCH

    Vertical hatch.


Returns:

wx.Pen


GetCap()

Returns the pen cap style, which may be one of wx.CAP_ROUND, wx.CAP_PROJECTING and wx.CAP_BUTT.

The default is wx.CAP_ROUND.


Returns:

int

See also

SetCap


GetColour()

Returns a reference to the pen colour.


Returns:

wx.Colour

See also

SetColour


GetDashCount()
No docstrings available for this method.

GetDashes()

Gets an array of dashes (defined as char in X, DWORD under Windows).

The function returns the number of dashes associated with this pen.


Returns:

list of integers

See also

SetDashes


GetJoin()

Returns the pen join style, which may be one of wx.JOIN_BEVEL, wx.JOIN_ROUND and wx.JOIN_MITER.

The default is wx.JOIN_ROUND.


Returns:

int

See also

SetJoin


GetStipple()

Gets a pointer to the stipple bitmap.


Returns:

wx.Bitmap

See also

SetStipple


GetStyle()

Returns the pen style.


Returns:

int

See also

SetStyle


GetWidth()

Returns the pen width.


Returns:

int

See also

SetWidth


IsOk()

Returns True if the pen is initialised.


Returns:

bool


SetCap(capStyle)

Sets the pen cap style, which can be one of wx.CAP_ROUND, wx.CAP_PROJECTING and wx.CAP_BUTT.

Parameters:

  • capStyle (int)

See also

GetCap


SetColour(colour)

The pen’s colour is changed to the given colour.

Parameters:

See also

GetColour


SetDashes(dashes)

Associates an array of pointers to dashes (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)

See also

GetDashes


SetJoin(join_style)

Sets the pen join style, which may be one of wx.JOIN_BEVEL, wx.JOIN_ROUND and wx.JOIN_MITER.

Parameters:

  • join_style (int)

See also

GetJoin


SetStipple(stipple)

Sets the bitmap for stippling.

Parameters:

See also

GetStipple


SetStyle(style)

Set the pen style.

Parameters:

  • style (int)

SetWidth(width)

Sets the pen width.

Parameters:

  • width (int)

See also

GetWidth


Properties

Cap
See GetCap and SetCap
Colour
See GetColour and SetColour
DashCount
See GetDashCount
Dashes
See GetDashes and SetDashes
Join
See GetJoin and SetJoin
Stipple
See GetStipple and SetStipple
Style
See GetStyle and SetStyle
Width
See GetWidth and SetWidth