wx.DC

Inheritance diagram for wx.DC:



Description

A wx.DC is a device context onto which graphics and text can be drawn. It is intended to represent a number of output devices in a generic way, so a window can have a device context associated with it, and a printer also has a device context. In this way, the same piece of code may write to a number of different devices, if the device context is used as a parameter.

Note

Notice that wx.DC is an abstract base class and can’t be created directly, please use wx.PaintDC , wx.ClientDC, wx.WindowDC, wx.ScreenDC, wx.MemoryDC or wx.PrinterDC.

Derived From

Methods Summary

Class API

Methods

__init__()
No docstrings available for this method.

BeginDrawing()
No docstrings available for this method.

Blit(xdest, ydest, width, height, source, xsrc, ysrc, useMask=False, xsrcMask=-1, ysrcMask=-1)

Copy from a source DC to this DC, specifying the destination coordinates, size of area to copy, source DC, source coordinates, logical function, whether to use a bitmap mask, and mask source position.

Parameters:

  • xdest (int): Destination device context x position.

  • ydest (int): Destination device context y position.

  • width (int): Width of source area to be copied.

  • height (int): Height of source area to be copied.

  • source (wx.DC): Source device context.

  • xsrc (int): Source device context x position.

  • ysrc (int): Source device context y position.

  • useMask (bool): If True, Blit does a transparent blit using the mask that is associated with the bitmap selected into the source device context. The Windows implementation does the following if MaskBlt cannot be used:

    1. Creates a temporary bitmap and copies the destination area into it.
    2. Copies the source area into the temporary bitmap using the specified logical function.
    3. Sets the masked area in the temporary bitmap to BLACK by ANDing the mask bitmap with the temp bitmap with the foreground colour set to WHITE and the bg colour set to BLACK.
    4. Sets the unmasked area in the destination area to BLACK by ANDing the mask bitmap with the destination area with the foreground colour set to BLACK and the background colour set to WHITE.
    5. ORs the temporary bitmap with the destination area.
    6. Deletes the temporary bitmap.

    This sequence of operations ensures that the source’s transparent area need not be black, and logical functions are supported.

    On Windows, blitting with masks can be speeded up considerably by compiling wxWidgets with the wx.USE_DC_CACHE option enabled. You can also influence whether MaskBlt or the explicit mask blitting code above is used, by using wx.SystemOptions and setting the no-maskblt option to 1.

  • xsrcMask (int): Source x position on the mask. If both xsrcMask and ysrcMask are -1, xsrc and ysrc will be assumed for the mask source position. Currently only implemented on Windows.

  • ysrcMask (int): Source y position on the mask. If both xsrcMask and ysrcMask are -1, xsrc and ysrc will be assumed for the mask source position. Currently only implemented on Windows.


Returns:

bool

Note

There is partial support for Blit in wx.PostScriptDC, under X. See wx.MemoryDC for typical usage.


BlitPointSize(destPt, sz, source, srcPt, rop=wx.COPY, useMask=False, srcPtMask=wx.DefaultPosition)

Copy from a source DC to this DC. Parameters specify the destination coordinates, size of area to copy, source DC, source coordinates, logical function, whether to use a bitmap mask, and mask source position.

Parameters:


Returns:

bool


CalcBoundingBox(x, y)

Adds the specified point to the bounding box which can be retrieved with MinX, MaxX and MinY, MaxY functions.

Parameters:

  • x (int)
  • y (int)

See also

ResetBoundingBox


CalcBoundingBoxPoint(point)

Adds the specified point to the bounding box which can be retrieved with MinX, MaxX and MinY, MaxY or GetBoundingBox functions.

Parameters:


CanDrawBitmap()
No docstrings available for this method.

CanGetTextExtent()
No docstrings available for this method.

Clear()
Clears the device context using the current background brush.

ComputeScaleAndOrigin()
Performs all necessary computations for given platform and context type after each change of scale and origin parameters. Usually called automatically internally after such changes.

CrossHair(x, y)

Displays a cross hair using the current pen. This is a vertical and horizontal line the height and width of the window, centred on the given point.

Parameters:

  • x (int)
  • y (int)

CrossHairPoint(pt)

Displays a cross hair using the current pen. This is a vertical and horizontal line the height and width of the window, centred on the given point.

Parameters:


DestroyClippingRegion()
Destroys the current clipping region so that none of the DC is clipped.

DeviceToLogicalX(x)

Convert device X coordinate to logical coordinate, using the current mapping mode.

Parameters:

  • x (int)

Returns:

int


DeviceToLogicalXRel(x)

Convert device X coordinate to relative logical coordinate, using the current mapping mode but ignoring the x axis orientation.

Use this function for converting a width, for example.

Parameters:

  • x (int)

Returns:

int


DeviceToLogicalY(y)

Converts device Y coordinate to logical coordinate, using the current mapping mode.

Parameters:

  • y (int)

Returns:

int


DeviceToLogicalYRel(y)

Convert device Y coordinate to relative logical coordinate, using the current mapping mode but ignoring the y axis orientation.

Use this function for converting a height, for example.

Parameters:

  • y (int)

Returns:

int


DrawArc(x1, y1, x2, x2, xc, yc)

Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1) and ending at (x2, y2). The current pen is used for the outline and the current brush for filling the shape.

The arc is drawn in an anticlockwise direction from the start point to the end point.

Parameters:

  • x1 (int)
  • y1 (int)
  • x2 (int)
  • y2 (int)
  • xc (int)
  • yc (int)

DrawArcPoint(pt1, pt2, center)

Draws an arc of a circle, centred on the center point (xc, yc), from the first point to the second. The current pen is used for the outline and the current brush for filling the shape.

The arc is drawn in an anticlockwise direction from the start point to the end point.

Parameters:


DrawBitmap(bmp, x, y, useMask=False)

Draw a bitmap on the device context at the specified point. If useMask is True and the bitmap has a transparency mask, the bitmap will be drawn transparently.

When drawing a mono-bitmap, the current text foreground colour will be used to draw the foreground of the bitmap (all bits set to 1), and the current text background colour to draw the background (all bits set to 0).


DrawBitmapPoint(bmp, pt, useMask=False)

Draw a bitmap on the device context at the specified point. If useMask is True and the bitmap has a transparency mask, (or alpha channel on the platforms that support it) then the bitmap will be drawn transparently.

Parameters:


DrawCheckMark(x, y, width, height)

Draws a check mark inside the given rectangle.

Parameters:

  • x (int)
  • y (int)
  • width (int)
  • height (int)

DrawCheckMarkRect(rect)

Draws a check mark inside the given rectangle.

Parameters:


DrawCircle(x, y, radius)

Draws a circle with the given centre and radius.

Parameters:

  • x (int)
  • y (int)
  • radius (int)

See also

DrawEllipse


DrawCirclePoint(pt, radius)

Draws a circle with the given center point and radius. The current pen is used for the outline and the current brush for filling the shape.

Parameters:


DrawEllipse(x, y, width, height)

Draws an ellipse contained in the rectangle specified either with the given top left corner and the given size or directly. The current pen is used for the outline and the current brush for filling the shape.

Parameters:

  • x (int)
  • y (int)
  • width (int)
  • height (int)

See also

DrawCircle


DrawEllipseList(ellipses, pens=None, brushes=None)

Draw a list of ellipses as quickly as possible.

Parameters:

  • ellipses: A sequence of 4-element sequences representing each ellipse to draw, (x, y, w, h).
  • pens: If None, then the current pen is used. If a single pen then it will be used for all ellipses. If a list of pens then there should be one for each ellipse in ellipses.
  • brushes: A brush or brushes to be used to fill the ellipses, with similar semantics as the pens parameter.

DrawEllipsePointSize(pt, sz)

Draws an ellipse contained in the specified rectangle. The current pen is used for the outline and the current brush for filling the shape.

Parameters:


DrawEllipseRect(rect)

Draws an ellipse contained in the specified rectangle. The current pen is used for the outline and the current brush for filling the shape.

Parameters:


DrawEllipticArc(x, y, w, h, start, end)

Draws an arc of an ellipse. The current pen is used for drawing the arc and the current brush is used for drawing the pie. x and y specify the x and y coordinates of the upper-left corner of the rectangle that contains the ellipse. width and height specify the width and height of the rectangle that contains the ellipse. start and end specify the start and end of the arc relative to the three-o’clock position from the center of the rectangle.

Angles are specified in degrees (360 is a complete circle). Positive values mean counter-clockwise motion. If start is equal to end, a complete ellipse will be drawn.

Parameters:

  • x (int)
  • y (int)
  • w (int)
  • h (int)
  • start (double)
  • end (double)

DrawEllipticArcPointSize(pt, sz, start, end)

Draws an arc of an ellipse, with the given rectangle defining the bounds of the ellipse. The current pen is used for drawing the arc and the current brush is used for drawing the pie.

The start and end parameters specify the start and end of the arc relative to the three-o’clock position from the center of the rectangle. Angles are specified in degrees (360 is a complete circle). Positive values mean counter-clockwise motion. If start is equal to end, a complete ellipse will be drawn.

Parameters:


DrawIcon(icon, x, y)

Draw an icon on the display (does nothing if the device context is wx.PostScriptDC).

This can be the simplest way of drawing bitmaps on a window.

Parameters:


DrawIconPoint(icon, pt)

Draw an icon on the display (does nothing if the device context is wx.PostScriptDC).

This can be the simplest way of drawing bitmaps on a window.

Parameters:


DrawImageLabel(text, image, rect, alignment=wx.ALIGN_LEFT|wx.ALIGN_TOP, indexAccel=-1)

Draw text and an image (which may be wx.NullBitmap to skip drawing it) within the specified rectangle, abiding by the alignment flags. Will additionally emphasize the character at indexAccel if it is not -1.

Returns the bounding rectangle.

Parameters:

  • text (string)
  • image (wx.Bitmap)
  • rect (wx.Rect)
  • alignment (int)
  • indexAccel (int)

Returns:

wx.Rect


DrawLabel(text, rect, alignment=wx.ALIGN_LEFT|wx.ALIGN_TOP, indexAccel=-1)

Draw optional bitmap and the text into the given rectangle and aligns it as specified by the alignment parameter; it also will emphasize the character with the given index if it is != -1.

Parameters:

  • text (string)
  • rect (wx.Rect)
  • alignment (int)
  • indexAccel (int)

DrawLine(x1, y1, x2, y2)

Draws a line from the first point to the second. The current pen is used for drawing the line.

Parameters:

  • x1 (int)
  • y1 (int)
  • x2 (int)
  • y2 (int)

Note

Note that the point (x2, y2) is not part of the line and is not drawn by this function (this is consistent with the behaviour of many other toolkits).


DrawLineList(lines, pens=None)

Draw a list of lines as quickly as possible.

Parameters:

  • lines: A sequence of 4-element sequences representing each line to draw, (x1, y1, x2, y2).
  • pens: If None, then the current pen is used. If a single pen then it will be used for all lines. If a list of pens then there should be one for each line in lines.

DrawLinePoint(pt1, pt2)

Draws a line from the first point to the second. The current pen is used for drawing the line.

Parameters:

Note

Note that the second point pt2 is not part of the line and is not drawn by this function (this is consistent with the behaviour of many other toolkits).


DrawLines(points, xoffset=0, yoffset=0)

Draws lines using an array of points, adding the optional offset coordinate. The current pen is used for drawing the lines.

The programmer is responsible for deleting the list of points.

Parameters:

  • points (list of wx.Points)
  • xoffset (int)
  • yoffset (int)

DrawPoint(x, y)

Draws a point using the color of the current pen.

Parameters:

  • x (int)
  • y (int)

Note

Note that the other properties of the pen are not used, such as width etc..


DrawPointList(points, pens=None)

Draw a list of points as quickly as possible.

Parameters:

  • points: A sequence of 2-element sequences representing each point to draw, (x, y).
  • pens: If None, then the current pen is used. If a single pen then it will be used for all points. If a list of pens then there should be one for each point in points.

DrawPointPoint(pt)

Draws a point using the current pen.

Parameters:


DrawPolygon(points, xoffset=0, yoffset=0, fillStyle=wx.ODDEVEN_RULE)

Draws a filled polygon using an array of points, adding the optional offset coordinate. The last argument specifies the fill rule: wx.ODDEVEN_RULE (the default) or wx.WINDING_RULE.

The current pen is used for drawing the outline, and the current brush for filling the shape. Using a transparent brush suppresses filling.

The programmer is responsible for deleting the list of points.

Parameters:

  • points (list of wx.Points)
  • xoffset (int)
  • yoffset (int)
  • fillStyle (int)

Note

Note that wxPython automatically closes the first and last points.


DrawPolygonList(polygons, pens=None, brushes=None)

Draw a list of polygons, each of which is a list of points.

Parameters:

  • polygons: A sequence of sequences of sequences., i.e.

    [[(x1,y1),(x2,y2),(x3,y3)...],
    [(x1,y1),(x2,y2),(x3,y3)...]]
  • pens: If None, then the current pen is used. If a single pen then it will be used for all polygons. If a list of pens then there should be one for each polygon.

  • brushes: A brush or brushes to be used to fill the polygons, with similar semantics as the pens parameter.


DrawRectangle(x, y, width, height)

Draws a rectangle with the given top left corner, and with the given size. The current pen is used for the outline and the current brush for filling the shape.

Parameters:

  • x (int)
  • y (int)
  • width (int)
  • height (int)

DrawRectangleList(rectangles, pens=None, brushes=None)

Draw a list of rectangles as quickly as possible.

Parameters:

  • rectangles: A sequence of 4-element sequences representing each rectangle to draw, (x, y, w, h).
  • pens: If None, then the current pen is used. If a single pen then it will be used for all rectangles. If a list of pens then there should be one for each rectangle in rectangles.
  • brushes: A brush or brushes to be used to fill the rectagles, with similar semantics as the pens parameter.

DrawRectanglePointSize(pt, sz)

Draws a rectangle with the given top left corner, and with the given size. The current pen is used for the outline and the current brush for filling the shape.

Parameters:


DrawRectangleRect(rect)

Draws a rectangle with the given top left corner, and with the given size. The current pen is used for the outline and the current brush for filling the shape.

Parameters:


DrawRotatedText(text, x, y, angle)

Draws the text rotated by angle degrees.

Parameters:

  • text (string)
  • x (int)
  • y (int)
  • angle (double)

Note

Under Win9x only TrueType fonts can be drawn by this function. In particular, a font different from wx.NORMAL_FONT should be used as the latter is not a TrueType font. wx.SWISS_FONT is an example of a font which is.

See also

DrawText


DrawRotatedTextPoint(text, pt, angle)

Draws the text rotated by angle degrees, if supported by the platform.

Parameters:

  • text (string)
  • pt (wx.Point)
  • angle (double)

Note

Under Win9x only TrueType fonts can be drawn by this function. In particular, a font different from wx.NORMAL_FONT should be used as the latter is not a TrueType font. wx.SWISS_FONT is an example of a font which is.


DrawRoundedRectangle(x, y, width, height, radius)

Draws a rectangle with the given top left corner, and with the given size. The corners are quarter-circles using the given radius. The current pen is used for the outline and the current brush for filling the shape.

If radius is positive, the value is assumed to be the radius of the rounded corner. If radius is negative, the absolute value is assumed to be the proportion of the smallest dimension of the rectangle. This means that the corner can be a sensible size relative to the size of the rectangle, and also avoids the strange effects X produces when the corners are too big for the rectangle.

Parameters:

  • x (int)
  • y (int)
  • width (int)
  • height (int)
  • angle (double)

DrawRoundedRectanglePointSize(pt, sz, radius)

Draws a rectangle with the given top left corner, and with the given size. The corners are quarter-circles using the given radius. The current pen is used for the outline and the current brush for filling the shape.

If radius is positive, the value is assumed to be the radius of the rounded corner. If radius is negative, the absolute value is assumed to be the proportion of the smallest dimension of the rectangle. This means that the corner can be a sensible size relative to the size of the rectangle, and also avoids the strange effects X produces when the corners are too big for the rectangle.

Parameters:


DrawRoundedRectangleRect(r, radius)

Draws a rectangle with the given rect. The corners are quarter-circles using the given radius. The current pen is used for the outline and the current brush for filling the shape.

If radius is positive, the value is assumed to be the radius of the rounded corner. If radius is negative, the absolute value is assumed to be the proportion of the smallest dimension of the rectangle. This means that the corner can be a sensible size relative to the size of the rectangle, and also avoids the strange effects X produces when the corners are too big for the rectangle.

Parameters:


DrawSpline(points)

Draws a three-point spline using the current pen.

Parameters:


DrawText(text, x, y)

Draws a text string at the specified point, using the current text font, and the current text foreground and background colours.

The coordinates refer to the top-left corner of the rectangle bounding the string. See GetTextExtent for how to get the dimensions of a text string, which can be used to position the text more precisely.

Parameters:

  • text (string)
  • x (int)
  • y (int)

Note

under wxGTK the current logical function is used by this function but it is ignored by wxMSW. Thus, you should avoid using logical functions with this function in portable programs.


DrawTextList(textList, coords, foregrounds=None, backgrounds=None)

Draw a list of strings using a list of coordinants for positioning each string.

Parameters:

  • textList (list of strings): A list of strings
  • coords (list of tuples): A list of (x, y) positions
  • foregrounds (list of wx.Colour): A list of wx.Colour objects to use for the foregrounds of the strings.
  • backgrounds (list of wx.Colour): A list of wx.Colour objects to use for the backgrounds of the strings.

Note

Make sure you set background mode to wx.SOLID (using SetBackgroundMode) If you want backgrounds to do anything.


DrawTextPoint(text, pt)

Draws a text string at the specified point, using the current text font, and the current text foreground and background colours.

The coordinates refer to the top-left corner of the rectangle bounding the string. See GetTextExtent for how to get the dimensions of a text string, which can be used to position the text more precisely.

Parameters:

Note

under wxGTK the current logical function is used by this function but it is ignored by wxMSW. Thus, you should avoid using logical functions with this function in portable programs.


EndDoc()
Ends a document (only relevant when outputting to a printer).

EndDrawing()
No docstrings available for this method.

EndPage()
Ends a document page (only relevant when outputting to a printer).

FloodFill(x, y, col, style=wx.FLOOD_SURFACE)

Flood fills the device context starting from the given point, using the current brush colour, and using a style:

  • wx.FLOOD_SURFACE: the flooding occurs until a colour other than the given colour is encountered.
  • wx.FLOOD_BORDER: the area to be flooded is bounded by the given colour.

Returns False if the operation failed.

Parameters:

  • x (int)
  • y (int)
  • col (wx.Colour)
  • style (int)

Returns:

bool

Note

The present implementation for non-Windows platforms may fail to find colour borders if the pixels do not match the colour exactly. However the function will still return True.


FloodFillPoint(pt, col, style=wx.FLOOD_SURFACE)

Flood fills the device context starting from the given point, using the current brush colour, and using a style:

  • wx.FLOOD_SURFACE: the flooding occurs until a colour other than the given colour is encountered.
  • wx.FLOOD_BORDER: the area to be flooded is bounded by the given colour.

Returns False if the operation failed.

Parameters:


Returns:

bool

Note

The present implementation for non-Windows platforms may fail to find colour borders if the pixels do not match the colour exactly. However the function will still return True.


GetAsBitmap(subrect=None)

Parameters:


Returns:

wx.Bitmap


GetBackground()

Gets the brush used for painting the background


Returns:

wx.Brush

See also

SetBackground


GetBackgroundMode()

Returns the current background mode: wx.SOLID or wx.TRANSPARENT.


Returns:

int


GetBoundingBox()

Returns the min and max points used in drawing commands so far.


Returns:

(x1, y1, x2, y2)


GetBrush()

Gets the current brush.


Returns:

wx.Brush

See also

SetBrush


GetCharHeight()

Gets the character height of the currently set font.


Returns:

int


GetCharWidth()

Gets the average character width of the currently set font.


Returns:

int


GetClippingBox()

Gets the rectangle surrounding the current clipping region.


Returns:

(x1, y1, width, height)


GetClippingRect()

Gets the rectangle surrounding the current clipping region.


Returns:

wx.Rect


GetDepth()

Returns the colour depth of the DC.


Returns:

int


GetDeviceOrigin()
No docstrings available for this method.

GetDeviceOriginTuple()
No docstrings available for this method.

GetFont()

Gets the current font.


Returns:

wx.Font

Note

Notice that even although each device context object has some default font after creation, this method would return a wx.NullFont initially and only after calling SetFont a valid font is returned.


GetFullTextExtent(string, font=None)

Get the width, height, decent and leading of the text using the current or specified font. Only works for single line strings.

Parameters:

  • string (wx.string)
  • font (wx.Font)

Returns:

(width, height, descent, externalLeading)


GetHDC()
No docstrings available for this method.

GetLayoutDirection()

Gets the current layout direction of the device context. On platforms where RTL layout is supported, the return value will either be wx.Layout_LeftToRight or wx.Layout_RightToLeft. If RTL layout is not supported, the return value will be wx.Layout_Default.


Returns:

int


GetLogicalFunction()

Gets the current logical function.


Returns:

int


GetLogicalOrigin()
No docstrings available for this method.

GetLogicalOriginTuple()
No docstrings available for this method.

GetLogicalScale()
No docstrings available for this method.

GetMapMode()

Gets the mapping mode for the device context.


Returns:

int

See also

SetMapMode


GetMultiLineTextExtent(string, font=None)

Gets the dimensions of the string using the currently selected font. string is the text string to measure.

If the optional parameter font is specified and valid, then it is used for the text extent calculation. Otherwise the currently selected font is.

Parameters:

Note

Note that this function works both with single-line and multi-line strings.


GetPPI()

Returns the resolution of the device in pixels per inch.


Returns:

wx.Size


GetPartialTextExtents(text)

Returns a list of integers such that each value is the distance in pixels from the begining of text to the corresponding character of text. The generic version simply builds a running total of the widths of each character using GetTextExtent, however if the various platforms have a native API function that is faster or more accurate than the generic implementation then it will be used instead.

Parameters:

  • text (string)

Returns:

list of integers


GetPen()

Gets the current pen.


Returns:

wx.Pen

See also

SetPen


GetPixel(x, y)

Gets the colour at the specified location on the DC.

Parameters:

  • x (int)
  • y (int)

Returns:

wx.Colour

Note

Note that setting a pixel can be done using DrawPoint


GetPixelPoint(pt)

Gets the colour at the specified location on the DC.

Parameters:


Returns:

wx.Colour


GetSize()

This gets the horizontal and vertical resolution in device units. It can be used to scale graphics to fit the page. For example, if maxX and maxY represent the maximum horizontal and vertical ‘pixel’ values used in your application, the following code will scale the graphic to fit on the printer page:

w, h = dc.GetSize()
scaleX = maxX*1.0/w
scaleY = maxY*1.0/h
dc.SetUserScale(min(scaleX, scaleY), min(scaleX, scaleY))

Returns:

wx.Size


GetSizeMM()

Returns the horizontal and vertical resolution in millimetres.


Returns:

wx.Size


GetSizeMMTuple()

Get the DC size in millimeters as a tuple.


Returns:

(width, height)


GetSizeTuple()

This gets the horizontal and vertical resolution in device units. It can be used to scale graphics to fit the page. For example, if maxX and maxY represent the maximum horizontal and vertical ‘pixel’ values used in your application, the following code will scale the graphic to fit on the printer page:

w, h = dc.GetSize()
scaleX = maxX*1.0/w
scaleY = maxY*1.0/h
dc.SetUserScale(min(scaleX, scaleY), min(scaleX, scaleY))

Returns:

(width, height)


GetTextBackground()

Gets the current text background colour.


Returns:

wx.Colour


GetTextExtent(string)

Gets the dimensions of the string using the currently selected font. string is the text string to measure.

Parameters:

  • string (string)

Returns:

(width, height)

Note

Note that this function only works with single-line strings.


GetTextForeground()

Gets the current text foreground colour.


Returns:

wx.Colour


GetUserScale()

Gets the current user scale factor (set by SetUserScale).


Returns:

(xScale, yScale)


GradientFillConcentric(rect, initialColour, destColour, circleCenter)

Fill the area specified by rect with a radial gradient, starting from initialColour at the centre of the circle and fading to destColour on the circle outside. circleCenter are the relative coordinates of centre of the circle in the specified rect. If not specified, the cercle is placed at the centre of rect.

Parameters:

Warning

Currently this function is very slow, don’t use it for real-time drawing.


GradientFillLinear(rect, initialColour, destColour, nDirection=wx.EAST)

Fill the area specified by rect with a linear gradient, starting from initialColour and eventually fading to destColour. The nDirection specifies the direction of the colour change, default is to use initialColour on the left part of the rectangle and destColour on the right one.

Parameters:


IsOk()

Returns True if the DC is ok to use.


Returns:

bool


LogicalToDeviceX(x)

Converts logical X coordinate to device coordinate, using the current mapping mode.

Parameters:

  • x (int)

Returns:

int


LogicalToDeviceXRel(x)

Converts logical X coordinate to relative device coordinate, using the current mapping mode but ignoring the x axis orientation.

Use this for converting a width, for example.

Parameters:

  • x (int)

Returns:

int


LogicalToDeviceY(y)

Converts logical Y coordinate to device coordinate, using the current mapping mode.

Parameters:

  • y (int)

Returns:

int


LogicalToDeviceYRel(y)

Converts logical Y coordinate to relative device coordinate, using the current mapping mode but ignoring the y axis orientation.

Use this for converting a height, for example.

Parameters:

  • y (int)

Returns:

int


MaxX()

Gets the maximum horizontal extent used in drawing commands so far.


Returns:

int


MaxY()

Gets the maximum vertical extent used in drawing commands so far.


Returns:

int


MinX()

Gets the minimum horizontal extent used in drawing commands so far.


Returns:

int


MinY()

Gets the minimum vertical extent used in drawing commands so far.


Returns:

int


ResetBoundingBox()
Resets the bounding box: after a call to this function, the bounding box doesn’t contain anything.

See also

CalcBoundingBox


SetAxisOrientation(xLeftRight, yBottomUp)

Sets the x and y axis orientation (i.e., the direction from lowest to highest values on the axis).

The default orientation is x axis from left to right and y axis from top down.

Parameters:

  • xLeftRight (bool): True to set the x axis orientation to the natural left to right orientation, False to invert it.
  • yBottomUp (bool): True to set the y axis orientation to the natural bottom up orientation, False to invert it.

SetBackground(brush)

Sets the current background brush for the DC.

Parameters:


SetBackgroundMode(mode)

mode may be one of wx.SOLID and wx.TRANSPARENT.

This setting determines whether text will be drawn with a background colour or not.

Parameters:

  • mode (int)

SetBrush(brush)

Sets the current brush for the DC.

If the argument is wx.NullBrush, the current brush is selected out of the device context, and the original brush restored, allowing the current brush to be destroyed safely.

Parameters:

See also

wx.Brush, wx.MemoryDC


SetClippingRect(rect)

Sets the clipping region for this device context to the intersection of the given region described by the parameters of this method and the previously set clipping region. You should call DestroyClippingRegion if you want to set the clipping region exactly to the region specified.

The clipping region is an area to which drawing is restricted. Possible uses for the clipping region are for clipping text or for speeding up window redraws when only a known area of the screen is damaged.

Parameters:


SetClippingRegion(x, y, width, height)

Sets the clipping region for this device context to the intersection of the given region described by the parameters of this method and the previously set clipping region. You should call DestroyClippingRegion if you want to set the clipping region exactly to the region specified.

The clipping region is an area to which drawing is restricted. Possible uses for the clipping region are for clipping text or for speeding up window redraws when only a known area of the screen is damaged.

Parameters:

  • x (int)
  • y (int)
  • width (int)
  • height (int)

SetClippingRegionAsRegion(region)

Sets the clipping region for this device context to the intersection of the given region described by the parameters of this method and the previously set clipping region. You should call DestroyClippingRegion if you want to set the clipping region exactly to the region specified.

The clipping region is an area to which drawing is restricted. Possible uses for the clipping region are for clipping text or for speeding up window redraws when only a known area of the screen is damaged.

Parameters:


SetClippingRegionPointSize(pt, sz)

Sets the clipping region for this device context to the intersection of the given region described by the parameters of this method and the previously set clipping region. You should call DestroyClippingRegion if you want to set the clipping region exactly to the region specified.

The clipping region is an area to which drawing is restricted. Possible uses for the clipping region are for clipping text or for speeding up window redraws when only a known area of the screen is damaged.

Parameters:


SetDeviceOrigin(x, y)

Sets the device origin (i.e., the origin in pixels after scaling has been applied).

This function may be useful in Windows printing operations for placing a graphic on a page.

Parameters:

  • x (int)
  • y (int)

SetDeviceOriginPoint(point)

Sets the device origin (i.e., the origin in pixels after scaling has been applied).

This function may be useful in Windows printing operations for placing a graphic on a page.

Parameters:


SetFont(font)

Sets the current font for the DC. It must be a valid font, in particular you should not pass wx.NullFont to this method.

Parameters:

See also

wx.Font


SetLayoutDirection(dir)

Sets the current layout direction for the device context. dir may be either wx.Layout_Default, wx.Layout_LeftToRight or wx.Layout_RightToLeft.

Parameters:

  • dir (int)

SetLogicalFunction(function)

Sets the current logical function for the device context. This determines how a source pixel (from a pen or brush colour, or source device context if using Blit) combines with a destination pixel in the current device context.

The possible values and their meaning in terms of source and destination pixel values are as follows:

Function Flag Description
wx.AND src AND dst
wx.AND_INVERT (NOT src) AND dst
wx.AND_REVERSE src AND (NOT dst)
wx.CLEAR 0
wx.COPY src
wx.EQUIV (NOT src) XOR dst
wx.INVERT NOT dst
wx.NAND (NOT src) OR (NOT dst)
wx.NOR (NOT src) AND (NOT dst)
wx.NO_OP dst
wx.OR src OR dst
wx.OR_INVERT (NOT src) OR dst
wx.OR_REVERSE src OR (NOT dst)
wx.SET 1
wx.SRC_INVERT NOT src
wx.XOR src XOR dst

The default is wx.COPY, which simply draws with the current colour. The others combine the current colour and the background using a logical operation.

wx.INVERT is commonly used for drawing rubber bands or moving outlines, since drawing twice reverts to the original colour.

Parameters:

  • function (int)

SetLogicalOrigin(x, y)

Parameters:

  • x (int)
  • y (int)

SetLogicalOriginPoint(point)

Parameters:


SetLogicalScale(x, y)

Parameters:

  • x (double)
  • y (double)

SetMapMode(int)

The mapping mode of the device context defines the unit of measurement used to convert logical units to device units. Note that in X, text drawing isn’t handled consistently with the mapping mode; a font is always specified in point size. However, setting the user scale (see SetUserScale) scales the text appropriately. In Windows, scalable TrueType fonts are always used; in X, results depend on availability of fonts, but usually a reasonable match is found.

The coordinate origin is always at the top left of the screen/printer.

Drawing to a Windows printer device context uses the current mapping mode, but mapping mode is currently ignored for PostScript output.

The mapping mode can be one of the following:

Mapping Mode Description
wx.MM_TWIPS Each logical unit is 1/20 of a point, or 1/1440 of an inch.
wx.MM_POINTS Each logical unit is a point, or 1/72 of an inch.
wx.MM_METRIC Each logical unit is 1 mm.
wx.MM_LOMETRIC Each logical unit is 1/10 of a mm.
wx.MM_TEXT Each logical unit is 1 pixel.

Parameters:

  • int (int)

SetPalette(palette)

If this is a window DC or memory DC, assigns the given palette to the window or bitmap associated with the DC.

If the argument is wx.NullPalette, the current palette is selected out of the device context, and the original palette restored.

Parameters:

See also

wx.Palette


SetPen(pen)

Sets the current pen for the DC.

If the argument is wx.NullPen, the current pen is selected out of the device context, and the original pen restored.

Parameters:

See also

wx.MemoryDC


SetTextBackground(colour)

Sets the current text background colour for the DC.

Parameters:


SetTextForeground(colour)

Sets the current text foreground colour for the DC.

Parameters:

See also

wx.MemoryDC


SetUserScale(xScale, yScale)

Sets the user scaling factor, useful for applications which require ‘zooming’.

Parameters:

  • xScale (double)
  • yScale (double)

StartDoc(message)

Starts a document (only relevant when outputting to a printer). Message is a message to show while printing.

Parameters:

  • message (string)

Returns:

bool


StartPage()

Starts a document page (only relevant when outputting to a printer).


Returns:

bool


Properties

Background
See GetBackground and SetBackground
BackgroundMode
See GetBackgroundMode and SetBackgroundMode
BoundingBox
See GetBoundingBox
Brush
See GetBrush and SetBrush
CharHeight
See GetCharHeight
CharWidth
See GetCharWidth
ClippingBox
See GetClippingBox
ClippingRect
See GetClippingRect and SetClippingRect
Depth
See GetDepth
DeviceOrigin
See GetDeviceOrigin and SetDeviceOrigin
Font
See GetFont and SetFont
FullTextExtent
See GetFullTextExtent
LayoutDirection
Get the layout direction (LTR or RTL)_ for this dc. On platforms where RTL layout is supported, the return value will either be wx.Layout_LeftToRight or wx.Layout_RightToLeft. wx.Layout_Default is returned if layout direction is not supported.
LogicalFunction
See GetLogicalFunction and SetLogicalFunction
LogicalOrigin
See GetLogicalOrigin and SetLogicalOrigin
LogicalScale
See GetLogicalScale and SetLogicalScale
MapMode
See GetMapMode and SetMapMode
MultiLineTextExtent
See GetMultiLineTextExtent
Optimization
See GetOptimization and SetOptimization
PPI
See GetPPI
PartialTextExtents
See GetPartialTextExtents
Pen
See GetPen and SetPen
Pixel
See GetPixel
PixelPoint
See GetPixelPoint
Size
See GetSize
SizeMM
See GetSizeMM
TextBackground
See GetTextBackground and SetTextBackground
TextExtent
See GetTextExtent
TextForeground
See GetTextForeground and SetTextForeground
UserScale
See GetUserScale and SetUserScale