.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2017 by Total Control Software License: wxWindows License .. include:: headings.inc .. currentmodule:: wx.lib.graphics .. highlight:: python .. _wx.lib.graphics.GraphicsContext: ========================================================================================================================================== |phoenix_title| **wx.lib.graphics.GraphicsContext** ========================================================================================================================================== The GraphicsContext is the object which facilitates drawing to a surface. | |class_hierarchy| Class Hierarchy ================================= .. raw:: html
Inheritance diagram for class GraphicsContext:

| |super_classes| Known Superclasses ================================== :class:`wx.lib.graphics.GraphicsObject` | |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~wx.lib.graphics.GraphicsContext.__init__` Create a new Context. :meth:`~wx.lib.graphics.GraphicsContext.BeginLayer` Redirects future rendering to a temporary context. See :meth:`EndLayer`. :meth:`~wx.lib.graphics.GraphicsContext.Clear` Clear the context using the given color or the currently set brush. :meth:`~wx.lib.graphics.GraphicsContext.Clip` Adds the rectangle to the current clipping region. The :meth:`~wx.lib.graphics.GraphicsContext.ClipPath` Set the clip region to the path. :meth:`~wx.lib.graphics.GraphicsContext.ClipRegion` Adds the :class:`wx.Region` to the current clipping region. :meth:`~wx.lib.graphics.GraphicsContext.ConcatTransform` Modifies the current transformation matrix by applying matrix :meth:`~wx.lib.graphics.GraphicsContext.Create` Create a new ``GraphicsContext``. :meth:`~wx.lib.graphics.GraphicsContext.CreateBrush` Create a brush from a :class:`wx.Brush`. :meth:`~wx.lib.graphics.GraphicsContext.CreateFont` Create a font from a :class:`wx.Font` :meth:`~wx.lib.graphics.GraphicsContext.CreateFromImage` Create a GraphicsContext associated with a :class:`wx.Image`. :meth:`~wx.lib.graphics.GraphicsContext.CreateFromNative` Create a context from an existing cairo Context :meth:`~wx.lib.graphics.GraphicsContext.CreateFromSurface` Wrap a context around the given cairo Surface. :meth:`~wx.lib.graphics.GraphicsContext.CreateLinearGradientBrush` Creates a native brush having a linear gradient, starting at (x1,y1) :meth:`~wx.lib.graphics.GraphicsContext.CreateMatrix` Create a new matrix object. :meth:`~wx.lib.graphics.GraphicsContext.CreateMeasuringContext` If you need a temporary context just to quickly measure some :meth:`~wx.lib.graphics.GraphicsContext.CreatePath` Create a new path obejct. :meth:`~wx.lib.graphics.GraphicsContext.CreatePen` Create a new pen from a wx.Pen. :meth:`~wx.lib.graphics.GraphicsContext.CreateRadialGradientBrush` Creates a native brush, having a radial gradient originating at point :meth:`~wx.lib.graphics.GraphicsContext.DrawBitmap` Draw the bitmap at (x,y). If the width and height parameters :meth:`~wx.lib.graphics.GraphicsContext.DrawCircle` Stroke and fill a circle centered at (x,y) with the given :meth:`~wx.lib.graphics.GraphicsContext.DrawEllipse` Stroke and fill an elipse that fits in the given rectangle, :meth:`~wx.lib.graphics.GraphicsContext.DrawIcon` :meth:`~wx.lib.graphics.GraphicsContext.DrawLines` Stroke and fill a series of connected lines using the current :meth:`~wx.lib.graphics.GraphicsContext.DrawPath` Draws the path by first filling it and then stroking it. :meth:`~wx.lib.graphics.GraphicsContext.DrawRectangle` Stroke and fill a rectangle using the current pen and current :meth:`~wx.lib.graphics.GraphicsContext.DrawRotatedText` Draw the text at (x,y) using the current font and rotated :meth:`~wx.lib.graphics.GraphicsContext.DrawRoundedRectangle` Stroke and fill a rounded rectangle using the current pen and :meth:`~wx.lib.graphics.GraphicsContext.DrawText` Draw the text at (x,y) using the current font. If :meth:`~wx.lib.graphics.GraphicsContext.EndLayer` Composites the drawing done on the temporary context created :meth:`~wx.lib.graphics.GraphicsContext.FillPath` Fills the path using the current brush. :meth:`~wx.lib.graphics.GraphicsContext.GetAntialiasMode` Returns the current antialias mode. :meth:`~wx.lib.graphics.GraphicsContext.GetBrush` Returns the current brush :meth:`~wx.lib.graphics.GraphicsContext.GetCompositingOperator` Returns the current compositing operator for the context. :meth:`~wx.lib.graphics.GraphicsContext.GetFont` :meth:`~wx.lib.graphics.GraphicsContext.GetFullTextExtent` Returns the (width, height, descent, externalLeading) of the :meth:`~wx.lib.graphics.GraphicsContext.GetLogicalFunction` Not implemented. :meth:`~wx.lib.graphics.GraphicsContext.GetNativeContext` :meth:`~wx.lib.graphics.GraphicsContext.GetPartialTextExtents` :meth:`~wx.lib.graphics.GraphicsContext.GetPen` Returns the current pen. :meth:`~wx.lib.graphics.GraphicsContext.GetSize` :meth:`~wx.lib.graphics.GraphicsContext.GetTextExtent` Returns the (width, height) of the text using the current :meth:`~wx.lib.graphics.GraphicsContext.GetTransform` Returns the context's current transformation matrix. :meth:`~wx.lib.graphics.GraphicsContext.IsNull` :meth:`~wx.lib.graphics.GraphicsContext.PopState` Restore the most recently saved state which was saved with :meth:`~wx.lib.graphics.GraphicsContext.PushState` Makes a copy of the current state of the context (ie the :meth:`~wx.lib.graphics.GraphicsContext.ResetClip` Resets the clipping region to the original shape of the context. :meth:`~wx.lib.graphics.GraphicsContext.Rotate` Modifies the current transformation matrix by rotating the :meth:`~wx.lib.graphics.GraphicsContext.Scale` Modifies the current transformation matrix by translating the :meth:`~wx.lib.graphics.GraphicsContext.SetAntialiasMode` Set the antialiasing mode of the rasterizer used for drawing :meth:`~wx.lib.graphics.GraphicsContext.SetBrush` Set the brush to be used for filling shapes in future drawing :meth:`~wx.lib.graphics.GraphicsContext.SetCompositingOperator` Sets the compositing operator to be used for all drawing :meth:`~wx.lib.graphics.GraphicsContext.SetFont` Sets the font to be used for drawing text. Either a :class:`wx.Font` :meth:`~wx.lib.graphics.GraphicsContext.SetLogicalFunction` Not implemented. :meth:`~wx.lib.graphics.GraphicsContext.SetPen` Set the pen to be used for stroking lines in future drawing :meth:`~wx.lib.graphics.GraphicsContext.SetTransform` Set the context's current transformation matrix to matrix. :meth:`~wx.lib.graphics.GraphicsContext.StrokeLine` Strokes a single line using the current pen. :meth:`~wx.lib.graphics.GraphicsContext.StrokeLines` Stroke a series of connected lines using the current pen. :meth:`~wx.lib.graphics.GraphicsContext.StrokeLineSegments` Stroke a series of lines using the current pen. For each line :meth:`~wx.lib.graphics.GraphicsContext.StrokePath` Strokes the path (draws the lines) using the current pen. :meth:`~wx.lib.graphics.GraphicsContext.Translate` Modifies the current transformation matrix by translating the ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~wx.lib.graphics.GraphicsContext.AntialiasMode` Returns the current antialias mode. :attr:`~wx.lib.graphics.GraphicsContext.Brush` Returns the current brush :attr:`~wx.lib.graphics.GraphicsContext.CompositingOperator` Returns the current compositing operator for the context. :attr:`~wx.lib.graphics.GraphicsContext.Context` A reference to the Cairo Context :attr:`~wx.lib.graphics.GraphicsContext.Font` :attr:`~wx.lib.graphics.GraphicsContext.LogicalFunction` Not implemented. :attr:`~wx.lib.graphics.GraphicsContext.Pen` Returns the current pen. :attr:`~wx.lib.graphics.GraphicsContext.Size` :attr:`~wx.lib.graphics.GraphicsContext.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. .. method:: __init__(self, context=None, size=None) Create a new Context. Normally you should use one of the ``"Create"`` static methods. .. method:: BeginLayer(self, opacity) Redirects future rendering to a temporary context. See :meth:`EndLayer`. .. method:: Clear(self, colour=None) Clear the context using the given color or the currently set brush. .. method:: 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. .. method:: ClipPath(self, path) Set the clip region to the path. .. method:: ClipRegion(self, region) Adds the :class:`wx.Region` to the current clipping region. .. method:: ConcatTransform(self, matrix) Modifies the current transformation matrix by applying matrix as an additional transformation. .. staticmethod:: Create(dc=None) Create a new ``GraphicsContext``. Passing ``None`` will create a context suitable for measuring. :param dc: ``None`` or a compatible :class:`wx.DC` .. method:: CreateBrush(self, brush) Create a brush from a :class:`wx.Brush`. .. method:: CreateFont(self, font, colour=None) Create a font from a :class:`wx.Font` .. staticmethod:: CreateFromImage(image) Create a GraphicsContext associated with a :class:`wx.Image`. The image specifies the size of the context as well as whether alpha is supported (if :meth:`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... .. staticmethod:: CreateFromNative(cairoContext) Create a context from an existing cairo Context .. staticmethod:: CreateFromSurface(surface) Wrap a context around the given cairo Surface. Note that a :class:`GraphicsBitmap` contains a cairo ``ImageSurface`` which is accessible via the ``Surface`` property. .. method:: 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 :class:`GraphicsGradientStops` or just two colours to be used as the starting and ending gradient colours. .. method:: CreateMatrix(self, a=1.0, b=0, c=0, d=1.0, tx=0, ty=0) Create a new matrix object. .. staticmethod:: 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. .. method:: CreatePath(self) Create a new path obejct. .. method:: CreatePen(self, pen) Create a new pen from a wx.Pen. .. method:: 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 :class:`GraphicsGradientStops` or just two colours to be used as the starting and ending gradient colours. .. method:: 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 :class:`wx.Bitmap` or a :class:`GraphicsBitmap` may be used. .. method:: DrawCircle(self, x, y, radius) Stroke and fill a circle centered at (x,y) with the given radius, using the current pen and brush. .. method:: DrawEllipse(self, x, y, w, h) Stroke and fill an elipse that fits in the given rectangle, using the current pen and current brush. .. method:: DrawIcon(self, icon, x, y, w=-1, h=-1) .. method:: DrawLines(self, points, fillStyle=wx.ODDEVEN_RULE) Stroke and fill a series of connected lines using the current pen and current brush. .. method:: DrawPath(self, path, fillStyle=wx.ODDEVEN_RULE) Draws the path by first filling it and then stroking it. .. method:: DrawRectangle(self, x, y, w, h) Stroke and fill a rectangle using the current pen and current brush. .. method:: 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. .. method:: DrawRoundedRectangle(self, x, y, w, h, radius) Stroke and fill a rounded rectangle using the current pen and current brush. .. method:: 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. .. method:: EndLayer(self) Composites the drawing done on the temporary context created in :meth:`BeginLayer` back into the main context, using the opacity specified for the layer. .. method:: FillPath(self, path, fillStyle=wx.ODDEVEN_RULE) Fills the path using the current brush. .. method:: GetAntialiasMode(self) Returns the current antialias mode. .. method:: GetBrush(self) Returns the current brush .. method:: GetCompositingOperator(self) Returns the current compositing operator for the context. .. method:: GetFont(self): return (self._font, self._fontColour) .. method:: GetFullTextExtent(self, text) Returns the (width, height, descent, externalLeading) of the text using the current font. .. method:: 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. .. method:: GetNativeContext(self) .. method:: GetPartialTextExtents(self, text) .. method:: GetPen(self) Returns the current pen. .. method:: GetSize(self) .. method:: GetTextExtent(self, text) Returns the (width, height) of the text using the current font. .. method:: GetTransform(self) Returns the context's current transformation matrix. .. method:: IsNull(self) .. method:: PopState(self) Restore the most recently saved state which was saved with :meth:`PushState`. .. method:: 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. .. method:: ResetClip(self) Resets the clipping region to the original shape of the context. .. method:: Rotate(self, angle) Modifies the current transformation matrix by rotating the user-space axes by angle radians. .. method:: Scale(self, xScale, yScale) Modifies the current transformation matrix by translating the user-space axes by xScale and yScale. .. method:: 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. .. method:: SetBrush(self, brush) Set the brush to be used for filling shapes in future drawing operations. Either a :class:`wx.Brush` or a :class:`GraphicsBrush` object may be used. .. method:: SetCompositingOperator(self, op) Sets the compositing operator to be used for all drawing operations. The default operator is OPERATOR_OVER. .. method:: SetFont(self, font, colour=None) Sets the font to be used for drawing text. Either a :class:`wx.Font` or a :class:`GraphicsFont` may be used. .. method:: SetLogicalFunction(self, function) Not implemented. .. method:: SetPen(self, pen) Set the pen to be used for stroking lines in future drawing operations. Either a :class:`wx.Pen` or a :class:`GraphicsPen` object may be used. .. method:: SetTransform(self, matrix) Set the context's current transformation matrix to matrix. .. method:: StrokeLine(self, x1, y1, x2, y2) Strokes a single line using the current pen. .. method:: 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. .. method:: 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. .. method:: StrokePath(self, path) Strokes the path (draws the lines) using the current pen. .. method:: Translate(self, dx, dy) Modifies the current transformation matrix by translating the user-space origin by (dx, dy). .. attribute:: AntialiasMode Returns the current antialias mode. .. attribute:: Brush Returns the current brush .. attribute:: CompositingOperator Returns the current compositing operator for the context. .. attribute:: Context A reference to the Cairo Context .. attribute:: Font See :meth:`~GraphicsContext.GetFont` .. attribute:: 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. .. attribute:: Pen Returns the current pen. .. attribute:: Size See :meth:`~GraphicsContext.GetSize` .. attribute:: Transform Returns the context's current transformation matrix.