wx.lib.graphics.GraphicsContext¶
The GraphicsContext is the object which facilitates drawing to a surface.
Class Hierarchy¶
Known Superclasses¶
wx.lib.graphics.GraphicsObject
Methods Summary¶
Create a new Context. |
|
Redirects future rendering to a temporary context. See |
|
Clear the context using the given color or the currently set brush. |
|
Adds the rectangle to the current clipping region. The |
|
Set the clip region to the path. |
|
Adds the |
|
Modifies the current transformation matrix by applying matrix |
|
Create a new |
|
Create a brush from a |
|
Create a font from a |
|
Create a GraphicsContext associated with a |
|
Create a context from an existing cairo Context |
|
Wrap a context around the given cairo Surface. |
|
Creates a native brush having a linear gradient, starting at (x1,y1) |
|
Create a new matrix object. |
|
If you need a temporary context just to quickly measure some |
|
Create a new path object. |
|
Create a new pen from a wx.Pen or a wx.GraphicsPenInfo. |
|
Creates a native brush, having a radial gradient originating at point |
|
Draw the bitmap at (x,y). If the width and height parameters |
|
Stroke and fill a circle centered at (x,y) with the given |
|
Stroke and fill an ellipse that fits in the given rectangle, |
|
Stroke and fill a series of connected lines using the current |
|
Draws the path by first filling it and then stroking it. |
|
Stroke and fill a rectangle using the current pen and current |
|
Draw the text at (x,y) using the current font and rotated |
|
Stroke and fill a rounded rectangle using the current pen and |
|
Draw the text at (x,y) using the current font. If |
|
Composites the drawing done on the temporary context created |
|
Fills the path using the current brush. |
|
Returns the current antialias mode. |
|
Returns the current brush |
|
Returns the current compositing operator for the context. |
|
Returns the (width, height, descent, externalLeading) of the |
|
Not implemented. |
|
Returns the current pen. |
|
Returns the (width, height) of the text using the current |
|
Returns the context’s current transformation matrix. |
|
Returns whether the object is valid. |
|
Restore the most recently saved state which was saved with |
|
Makes a copy of the current state of the context (ie the |
|
Resets the clipping region to the original shape of the context. |
|
Modifies the current transformation matrix by rotating the |
|
Modifies the current transformation matrix by translating the |
|
Set the antialiasing mode of the rasterizer used for drawing |
|
Set the brush to be used for filling shapes in future drawing |
|
Sets the compositing operator to be used for all drawing |
|
Sets the font to be used for drawing text. Either a |
|
Not implemented. |
|
Set the pen to be used for stroking lines in future drawing |
|
Set the context’s current transformation matrix to matrix. |
|
Strokes a single line using the current pen. |
|
Stroke a series of connected lines using the current pen. |
|
Stroke a series of lines using the current pen. For each line |
|
Strokes the path (draws the lines) using the current pen. |
|
Modifies the current transformation matrix by translating the |
Properties Summary¶
Returns the current antialias mode. |
|
Returns the current brush |
|
Returns the current compositing operator for the context. |
|
A reference to the Cairo Context |
|
Not implemented. |
|
Returns the current pen. |
|
Returns the context’s current transformation matrix. |
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.
- 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.
- ConcatTransform(self, matrix)¶
Modifies the current transformation matrix by applying matrix as an additional transformation.
- static Create(dc=None)¶
Create a new
GraphicsContext
. PassingNone
will create a context suitable for measuring.- Parameters:
dc –
None
or a compatiblewx.DC
- 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 cairoImageSurface
which is accessible via theSurface
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 object.
- CreatePen(self, pen)¶
Create a new pen from a wx.Pen or a wx.GraphicsPenInfo.
- 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 aGraphicsBitmap
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 ellipse 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.
- Flush(self)¶
- 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)¶
Returns whether the object is valid.
- 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 aGraphicsBrush
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 aGraphicsFont
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 aGraphicsPen
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
- 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.
- Transform¶
Returns the context’s current transformation matrix.