Phoenix Logo

phoenix_title wx.lib.graphics.GraphicsContext

The GraphicsContext is the object which facilitates drawing to a surface.


class_hierarchy Class Hierarchy

Inheritance diagram for class GraphicsContext:


method_summary Methods Summary

__init__ Create a new Context.
BeginLayer Redirects future rendering to a temporary context. See EndLayer.
Clear Clear the context using the given color or the currently set brush.
Clip Adds the rectangle to the current clipping region. The
ClipPath Set the clip region to the path.
ClipRegion Adds the wx.Region to the current clipping region.
ConcatTransform Modifies the current transformation matrix by applying matrix
Create Create a new GraphicsContext.
CreateBrush Create a brush from a wx.Brush.
CreateFont Create a font from a wx.Font
CreateFromImage Create a GraphicsContext associated with a wx.Image.
CreateFromNative Create a context from an existing cairo Context
CreateFromSurface Wrap a context around the given cairo Surface.
CreateLinearGradientBrush Creates a native brush having a linear gradient, starting at (x1,y1)
CreateMatrix Create a new matrix object.
CreateMeasuringContext If you need a temporary context just to quickly measure some
CreatePath Create a new path obejct.
CreatePen Create a new pen from a wx.Pen.
CreateRadialGradientBrush Creates a native brush, having a radial gradient originating at point
DrawBitmap Draw the bitmap at (x,y). If the width and height parameters
DrawCircle Stroke and fill a circle centered at (x,y) with the given
DrawEllipse Stroke and fill an elipse that fits in the given rectangle,
DrawIcon  
DrawLines Stroke and fill a series of connected lines using the current
DrawPath Draws the path by first filling it and then stroking it.
DrawRectangle Stroke and fill a rectangle using the current pen and current
DrawRotatedText Draw the text at (x,y) using the current font and rotated
DrawRoundedRectangle Stroke and fill a rounded rectangle using the current pen and
DrawText Draw the text at (x,y) using the current font. If
EndLayer Composites the drawing done on the temporary context created
FillPath Fills the path using the current brush.
GetAntialiasMode Returns the current antialias mode.
GetBrush Returns the current brush
GetCompositingOperator Returns the current compositing operator for the context.
GetFont  
GetFullTextExtent Returns the (width, height, descent, externalLeading) of the
GetLogicalFunction Not implemented.
GetNativeContext  
GetPartialTextExtents  
GetPen Returns the current pen.
GetSize  
GetTextExtent Returns the (width, height) of the text using the current
GetTransform Returns the context’s current transformation matrix.
IsNull  
PopState Restore the most recently saved state which was saved with
PushState Makes a copy of the current state of the context (ie the
ResetClip Resets the clipping region to the original shape of the context.
Rotate Modifies the current transformation matrix by rotating the
Scale Modifies the current transformation matrix by translating the
SetAntialiasMode Set the antialiasing mode of the rasterizer used for drawing
SetBrush Set the brush to be used for filling shapes in future drawing
SetCompositingOperator Sets the compositing operator to be used for all drawing
SetFont Sets the font to be used for drawing text. Either a wx.Font
SetLogicalFunction Not implemented.
SetPen Set the pen to be used for stroking lines in future drawing
SetTransform Set the context’s current transformation matrix to matrix.
StrokeLine Strokes a single line using the current pen.
StrokeLines Stroke a series of connected lines using the current pen.
StrokeLineSegments Stroke a series of lines using the current pen. For each line
StrokePath Strokes the path (draws the lines) using the current pen.
Translate Modifies the current transformation matrix by translating the

property_summary Properties Summary

AntialiasMode Returns the current antialias mode.
Brush Returns the current brush
CompositingOperator Returns the current compositing operator for the context.
Context A reference to the Cairo Context
Font  
LogicalFunction Not implemented.
Pen Returns the current pen.
Size  
Transform Returns the context’s current transformation matrix.

api Class API



class GraphicsContext(GraphicsObject)

The GraphicsContext is the object which facilitates drawing to a surface.


Methods



__init__(self, context=None, size=None)

Create a new Context. Normally you should use one of the "Create" static methods.



BeginLayer(self, opacity)

Redirects future rendering to a temporary context. See EndLayer.



Clear(self, colour=None)

Clear the context using the given color or the currently set brush.



Clip(self, x, y, w, h)

Adds the rectangle to the current clipping region. The clipping region causes drawing operations to be limited to the clipped areas of the context.



ClipPath(self, path)

Set the clip region to the path.



ClipRegion(self, region)

Adds the wx.Region to the current clipping region.



ConcatTransform(self, matrix)

Modifies the current transformation matrix by applying matrix as an additional transformation.



static Create(dc=None)

Create a new GraphicsContext. Passing None will create a context suitable for measuring.

Parameters:dcNone or a compatible wx.DC


CreateBrush(self, brush)

Create a brush from a wx.Brush.



CreateFont(self, font, colour=None)

Create a font from a wx.Font



static CreateFromImage(image)

Create a GraphicsContext associated with a wx.Image.

The image specifies the size of the context as well as whether alpha is supported (if wx.Image.HasAlpha) or not and the initial contents of the context. The image object must have a life time greater than that of the new context as the context copies its contents back to the image when it is destroyed.

Not implemented yet...



static CreateFromNative(cairoContext)

Create a context from an existing cairo Context



static CreateFromSurface(surface)

Wrap a context around the given cairo Surface. Note that a GraphicsBitmap contains a cairo ImageSurface which is accessible via the Surface property.



CreateLinearGradientBrush(self, x1, y1, x2, y2, *args)

Creates a native brush having a linear gradient, starting at (x1,y1) to (x2,y2) with the given boundary colors or the specified stops.

The *args can be either a GraphicsGradientStops or just two colours to be used as the starting and ending gradient colours.



CreateMatrix(self, a=1.0, b=0, c=0, d=1.0, tx=0, ty=0)

Create a new matrix object.



static CreateMeasuringContext()

If you need a temporary context just to quickly measure some text extents, or etc. then using this function will be a little less expensive than creating a real DC for it.



CreatePath(self)

Create a new path obejct.



CreatePen(self, pen)

Create a new pen from a wx.Pen.



CreateRadialGradientBrush(self, xo, yo, xc, yc, radius, *args)

Creates a native brush, having a radial gradient originating at point (xo,yo) and ending on a circle around (xc,yc) with the given radius; the colours may be specified by just the two extremes or the full array of gradient stops.

The *args can be either a GraphicsGradientStops or just two colours to be used as the starting and ending gradient colours.



DrawBitmap(self, bmp, x, y, w=-1, h=-1)

Draw the bitmap at (x,y). If the width and height parameters are passed then the bitmap is scaled to fit that size. Either a wx.Bitmap or a GraphicsBitmap may be used.



DrawCircle(self, x, y, radius)

Stroke and fill a circle centered at (x,y) with the given radius, using the current pen and brush.



DrawEllipse(self, x, y, w, h)

Stroke and fill an elipse that fits in the given rectangle, using the current pen and current brush.



DrawIcon(self, icon, x, y, w=-1, h=-1)


DrawLines(self, points, fillStyle=wx.ODDEVEN_RULE)

Stroke and fill a series of connected lines using the current pen and current brush.



DrawPath(self, path, fillStyle=wx.ODDEVEN_RULE)

Draws the path by first filling it and then stroking it.



DrawRectangle(self, x, y, w, h)

Stroke and fill a rectangle using the current pen and current brush.



DrawRotatedText(self, text, x, y, angle, backgroundBrush=None)

Draw the text at (x,y) using the current font and rotated angle radians. If backgroundBrush is set then it is used to fill the rectangle behind the text.



DrawRoundedRectangle(self, x, y, w, h, radius)

Stroke and fill a rounded rectangle using the current pen and current brush.



DrawText(self, text, x, y, backgroundBrush=None)

Draw the text at (x,y) using the current font. If backgroundBrush is set then it is used to fill the rectangle behind the text.



EndLayer(self)

Composites the drawing done on the temporary context created in BeginLayer back into the main context, using the opacity specified for the layer.



FillPath(self, path, fillStyle=wx.ODDEVEN_RULE)

Fills the path using the current brush.



GetAntialiasMode(self)

Returns the current antialias mode.



GetBrush(self)

Returns the current brush



GetCompositingOperator(self)

Returns the current compositing operator for the context.



GetFont(self): return (self._font, self._fontColour)


GetFullTextExtent(self, text)

Returns the (width, height, descent, externalLeading) of the text using the current font.



GetLogicalFunction(self)

Not implemented. Since DC logical functions are conceptually different than compositing operators don’t pretend they are the same thing, or try to implement them using the compositing operators.



GetNativeContext(self)


GetPartialTextExtents(self, text)


GetPen(self)

Returns the current pen.



GetSize(self)


GetTextExtent(self, text)

Returns the (width, height) of the text using the current font.



GetTransform(self)

Returns the context’s current transformation matrix.



IsNull(self)


PopState(self)

Restore the most recently saved state which was saved with PushState.



PushState(self)

Makes a copy of the current state of the context (ie the transformation matrix) and saves it on an internal stack of saved states. The saved state will be restored when meth:PopState is called.



ResetClip(self)

Resets the clipping region to the original shape of the context.



Rotate(self, angle)

Modifies the current transformation matrix by rotating the user-space axes by angle radians.



Scale(self, xScale, yScale)

Modifies the current transformation matrix by translating the user-space axes by xScale and yScale.



SetAntialiasMode(self, mode=ANTIALIAS_DEFAULT)

Set the antialiasing mode of the rasterizer used for drawing shapes. This value is a hint, and a particular backend may or may not support a particular value.



SetBrush(self, brush)

Set the brush to be used for filling shapes in future drawing operations. Either a wx.Brush or a GraphicsBrush object may be used.



SetCompositingOperator(self, op)

Sets the compositing operator to be used for all drawing operations. The default operator is OPERATOR_OVER.



SetFont(self, font, colour=None)

Sets the font to be used for drawing text. Either a wx.Font or a GraphicsFont may be used.



SetLogicalFunction(self, function)

Not implemented.



SetPen(self, pen)

Set the pen to be used for stroking lines in future drawing operations. Either a wx.Pen or a GraphicsPen object may be used.



SetTransform(self, matrix)

Set the context’s current transformation matrix to matrix.



StrokeLine(self, x1, y1, x2, y2)

Strokes a single line using the current pen.



StrokeLines(self, points)

Stroke a series of connected lines using the current pen. Points is a sequence of points or 2-tuples, and lines are drawn from point to point through the end of the sequence.



StrokeLineSegments(self, beginPoints, endPoints)

Stroke a series of lines using the current pen. For each line the begin point is taken from the beginPoints sequence and the ending point is taken from the endPoints sequence.



StrokePath(self, path)

Strokes the path (draws the lines) using the current pen.



Translate(self, dx, dy)

Modifies the current transformation matrix by translating the user-space origin by (dx, dy).


Properties



AntialiasMode

Returns the current antialias mode.



Brush

Returns the current brush



CompositingOperator

Returns the current compositing operator for the context.



Context

A reference to the Cairo Context



Font

See GetFont



LogicalFunction

Not implemented. Since DC logical functions are conceptually different than compositing operators don’t pretend they are the same thing, or try to implement them using the compositing operators.



Pen

Returns the current pen.



Size

See GetSize



Transform

Returns the context’s current transformation matrix.