.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2020 by Total Control Software License: wxWindows License .. include:: headings.inc .. _wx.GraphicsContext: ========================================================================================================================================== |phoenix_title| **wx.GraphicsContext** ========================================================================================================================================== A :ref:`wx.GraphicsContext` instance is the object that is drawn upon. It is created by a renderer using :meth:`wx.GraphicsRenderer.CreateContext` . This can be either directly using a renderer instance, or indirectly using the static convenience :meth:`~wx.GraphicsContext.Create` functions of :ref:`wx.GraphicsContext` that always delegate the task to the default renderer. :: def OnPaint(self, event): # Create paint DC dc = wx.PaintDC(self) # Create graphics context from it gc = wx.GraphicsContext.Create(dc) if gc: # make a path that contains a circle and some lines gc.SetPen(wx.RED_PEN) path = gc.CreatePath() path.AddCircle(50.0, 50.0, 50.0) path.MoveToPoint(0.0, 50.0) path.AddLineToPoint(100.0, 50.0) path.MoveToPoint(50.0, 0.0) path.AddLineToPoint(50.0, 100.0) path.CloseSubpath() path.AddRectangle(25.0, 25.0, 50.0, 50.0) gc.StrokePath(path) .. note:: For some renderers (like Direct2D or Cairo) processing of drawing operations may be deferred (Direct2D render target normally builds up a batch of rendering commands but defers processing of these commands, Cairo operates on a separate surface) so to make drawing results visible you need to update the content of the context by calling :meth:`wx.GraphicsContext.Flush` or by destroying the context. .. seealso:: :meth:`wx.GraphicsRenderer.CreateContext` , :ref:`wx.GCDC`, :ref:`wx.DC` | |class_hierarchy| Class Hierarchy ================================= .. raw:: html
Inheritance diagram for class GraphicsContext:
| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~wx.GraphicsContext.BeginLayer` All rendering will be done into a fully transparent temporary context. :meth:`~wx.GraphicsContext.Clip` Sets the clipping region to the intersection of the given region and the previously set clipping region. :meth:`~wx.GraphicsContext.ConcatTransform` Concatenates the passed in transform with the current transform of this context. :meth:`~wx.GraphicsContext.Create` Creates a :ref:`wx.GraphicsContext` from a :ref:`wx.Window`. :meth:`~wx.GraphicsContext.CreateBitmap` Creates :ref:`wx.GraphicsBitmap` from an existing :ref:`wx.Bitmap`. :meth:`~wx.GraphicsContext.CreateBitmapFromImage` Creates :ref:`wx.GraphicsBitmap` from an existing :ref:`wx.Image`. :meth:`~wx.GraphicsContext.CreateBrush` Creates a native brush from a :ref:`wx.Brush`. :meth:`~wx.GraphicsContext.CreateFont` Creates a native graphics font from a :ref:`wx.Font` and a text colour. :meth:`~wx.GraphicsContext.CreateFromNative` Creates a :ref:`wx.GraphicsContext` from a native context. :meth:`~wx.GraphicsContext.CreateFromNativeWindow` Creates a :ref:`wx.GraphicsContext` from a native window. :meth:`~wx.GraphicsContext.CreateFromUnknownDC` Creates a :ref:`wx.GraphicsContext` from a DC of unknown specific type. :meth:`~wx.GraphicsContext.CreateLinearGradientBrush` Creates a native brush with a linear gradient. :meth:`~wx.GraphicsContext.CreateMatrix` Creates a native affine transformation matrix from the passed in values. :meth:`~wx.GraphicsContext.CreatePath` Creates a native graphics path which is initially empty. :meth:`~wx.GraphicsContext.CreatePen` Creates a native pen from a :ref:`wx.Pen`. :meth:`~wx.GraphicsContext.CreateRadialGradientBrush` Creates a native brush with a radial gradient. :meth:`~wx.GraphicsContext.CreateSubBitmap` Extracts a sub-bitmap from an existing bitmap. :meth:`~wx.GraphicsContext.DisableOffset` Helper to determine if a 0.5 offset should be applied for the drawing operation. :meth:`~wx.GraphicsContext.DrawBitmap` Draws the bitmap. :meth:`~wx.GraphicsContext.DrawEllipse` Draws an ellipse. :meth:`~wx.GraphicsContext.DrawIcon` Draws the icon. :meth:`~wx.GraphicsContext.DrawLines` Draws a polygon. :meth:`~wx.GraphicsContext.DrawPath` Draws the path by first filling and then stroking. :meth:`~wx.GraphicsContext.DrawRectangle` Draws a rectangle. :meth:`~wx.GraphicsContext.DrawRoundedRectangle` Draws a rounded rectangle. :meth:`~wx.GraphicsContext.DrawText` Draws text at the defined position. :meth:`~wx.GraphicsContext.EnableOffset` Indicates whether the context should try to offset for pixel boundaries. :meth:`~wx.GraphicsContext.EndDoc` Done with that document (relevant only for printing / pdf etc.) :meth:`~wx.GraphicsContext.EndLayer` Composites back the drawings into the context with the opacity given at the :meth:`~GraphicsContext.BeginLayer` call. :meth:`~wx.GraphicsContext.EndPage` Ends the current page (relevant only for printing / pdf etc.) :meth:`~wx.GraphicsContext.FillPath` Fills the path with the current brush. :meth:`~wx.GraphicsContext.Flush` Make sure that the current content of this context is immediately visible. :meth:`~wx.GraphicsContext.FromDIP` Convert DPI-independent pixel values to the value in pixels appropriate for the graphics context. :meth:`~wx.GraphicsContext.GetAntialiasMode` Returns the current shape antialiasing mode. :meth:`~wx.GraphicsContext.GetClipBox` Returns bounding box of the current clipping region. :meth:`~wx.GraphicsContext.GetCompositionMode` Returns the current compositing operator. :meth:`~wx.GraphicsContext.GetDPI` Returns the resolution of the graphics context in device points per inch. :meth:`~wx.GraphicsContext.GetInterpolationQuality` Returns the current interpolation quality. :meth:`~wx.GraphicsContext.GetNativeContext` Returns the native context (CGContextRef for Core Graphics, Graphics pointer for GDIPlus and cairo_t pointer for cairo). :meth:`~wx.GraphicsContext.GetPartialTextExtents` Fills the `widths` array with the widths from the beginning of `text` to the corresponding character of `text`. :meth:`~wx.GraphicsContext.GetSize` Returns the size of the graphics context in device coordinates. :meth:`~wx.GraphicsContext.GetFullTextExtent` Gets the dimensions of the string using the currently selected font. :meth:`~wx.GraphicsContext.GetTransform` Gets the current transformation matrix of this context. :meth:`~wx.GraphicsContext.GetWindow` Returns the associated window if any. :meth:`~wx.GraphicsContext.OffsetEnabled` Helper to determine if a 0.5 offset should be applied for the drawing operation. :meth:`~wx.GraphicsContext.PopState` Sets current state of the context to the state saved by a preceding call to :meth:`~GraphicsContext.PushState` and removes that state from the stack of saved states. :meth:`~wx.GraphicsContext.PushState` Push the current state (like transformations, clipping region and quality settings) of the context on a stack. :meth:`~wx.GraphicsContext.ResetClip` Resets the clipping to original shape. :meth:`~wx.GraphicsContext.Rotate` Rotates the current transformation matrix (in radians). :meth:`~wx.GraphicsContext.Scale` Scales the current transformation matrix. :meth:`~wx.GraphicsContext.SetAntialiasMode` Sets the antialiasing mode, returns ``True`` if it supported. :meth:`~wx.GraphicsContext.SetBrush` Sets the brush for filling paths. :meth:`~wx.GraphicsContext.SetCompositionMode` Sets the compositing operator, returns ``True`` if it supported. :meth:`~wx.GraphicsContext.SetFont` Sets the font for drawing text. :meth:`~wx.GraphicsContext.SetInterpolationQuality` Sets the interpolation quality, returns ``True`` if it is supported. :meth:`~wx.GraphicsContext.SetPen` Sets the pen used for stroking. :meth:`~wx.GraphicsContext.SetTransform` Sets the current transformation matrix of this context. :meth:`~wx.GraphicsContext.ShouldOffset` Helper to determine if a 0.5 offset should be applied for the drawing operation. :meth:`~wx.GraphicsContext.StartDoc` Begin a new document (relevant only for printing / pdf etc.) If there is a progress dialog, message will be shown. :meth:`~wx.GraphicsContext.StartPage` Opens a new page (relevant only for printing / pdf etc.) with the given size in points. :meth:`~wx.GraphicsContext.StrokeLine` Strokes a single line. :meth:`~wx.GraphicsContext.StrokeLineSegments` Stroke disconnected lines from begin to end points. :meth:`~wx.GraphicsContext.StrokeLines` Stroke lines connecting all the points. :meth:`~wx.GraphicsContext.StrokePath` Strokes along a path with the current pen. :meth:`~wx.GraphicsContext.ToDIP` Convert pixel values of the current graphics context to DPI-independent pixel values. :meth:`~wx.GraphicsContext.Translate` Translates the current transformation matrix. ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~wx.GraphicsContext.AntialiasMode` See :meth:`~wx.GraphicsContext.GetAntialiasMode` and :meth:`~wx.GraphicsContext.SetAntialiasMode` :attr:`~wx.GraphicsContext.CompositionMode` See :meth:`~wx.GraphicsContext.GetCompositionMode` and :meth:`~wx.GraphicsContext.SetCompositionMode` :attr:`~wx.GraphicsContext.InterpolationQuality` See :meth:`~wx.GraphicsContext.GetInterpolationQuality` and :meth:`~wx.GraphicsContext.SetInterpolationQuality` :attr:`~wx.GraphicsContext.NativeContext` See :meth:`~wx.GraphicsContext.GetNativeContext` :attr:`~wx.GraphicsContext.TextExtent` See :meth:`~wx.GraphicsContext.GetTextExtent` :attr:`~wx.GraphicsContext.Transform` See :meth:`~wx.GraphicsContext.GetTransform` and :meth:`~wx.GraphicsContext.SetTransform` :attr:`~wx.GraphicsContext.Window` See :meth:`~wx.GraphicsContext.GetWindow` ================================================================================ ================================================================================ | |api| Class API =============== .. class:: wx.GraphicsContext(GraphicsObject) A GraphicsContext instance is the object that is drawn upon. .. method:: BeginLayer(self, opacity) All rendering will be done into a fully transparent temporary context. Layers can be nested by making balanced calls to :meth:`BeginLayer` /EndLayer(). :param `opacity`: :type `opacity`: wx.Double .. method:: Clip(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **Clip** `(self, region)` Sets the clipping region to the intersection of the given region and the previously set clipping region. The clipping region is an area to which drawing is restricted. :param `region`: :type `region`: wx.Region .. note:: - Clipping region should be given in logical coordinates. - Calling this function can only make the clipping region smaller, never larger. - You need to call :meth:`ResetClip` first if you want to set the clipping region exactly to the region specified. - If resulting clipping region is empty, then all drawing upon the context is clipped out (all changes made by drawing operations are masked out). :html:`

` **Clip** `(self, x, y, w, h)` This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. :param `x`: :type `x`: wx.Double :param `y`: :type `y`: wx.Double :param `w`: :type `w`: wx.Double :param `h`: :type `h`: wx.Double :html:`

` .. method:: ConcatTransform(self, matrix) Concatenates the passed in transform with the current transform of this context. :param `matrix`: :type `matrix`: wx.GraphicsMatrix .. staticmethod:: Create(*args, **kw) |overload| Overloaded Implementations: :html:`

` **Create** `(window)` Creates a :ref:`wx.GraphicsContext` from a :ref:`wx.Window`. :param `window`: :type `window`: wx.Window :rtype: :ref:`wx.GraphicsContext` .. seealso:: :meth:`wx.GraphicsRenderer.CreateContext` :html:`

` **Create** `(windowDC)` Creates a :ref:`wx.GraphicsContext` from a :ref:`wx.WindowDC`. :param `windowDC`: :type `windowDC`: wx.WindowDC :rtype: :ref:`wx.GraphicsContext` .. seealso:: :meth:`wx.GraphicsRenderer.CreateContext` :html:`

` **Create** `(memoryDC)` Creates a :ref:`wx.GraphicsContext` from a :ref:`wx.MemoryDC`. :param `memoryDC`: :type `memoryDC`: wx.MemoryDC :rtype: :ref:`wx.GraphicsContext` .. seealso:: :meth:`wx.GraphicsRenderer.CreateContext` :html:`

` **Create** `(printerDC)` Creates a :ref:`wx.GraphicsContext` from a :ref:`wx.PrinterDC`. Under GTK+, this will only work when using the GtkPrint printing backend which is available since GTK+ 2.10. :param `printerDC`: :type `printerDC`: wx.PrinterDC :rtype: :ref:`wx.GraphicsContext` .. seealso:: :meth:`wx.GraphicsRenderer.CreateContext` , :html:`

` **Create** `(metaFileDC)` Creates a :ref:`wx.GraphicsContext` from a EnhMetaFileDC. This function, as EnhMetaFileDC class itself, is only available only under MSW. :param `metaFileDC`: :type `metaFileDC`: :class:`MetafileDC` :rtype: :ref:`wx.GraphicsContext` .. seealso:: :meth:`wx.GraphicsRenderer.CreateContext` :html:`

` **Create** `(image)` Creates a :ref:`wx.GraphicsContext` associated with a :ref:`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. :param `image`: :type `image`: wx.Image :rtype: :ref:`wx.GraphicsContext` .. versionadded:: 2.9.3 :html:`

` **Create** `()` Create a lightweight context that can be used only for measuring text. :rtype: :ref:`wx.GraphicsContext` :html:`

` **Create** `(autoPaintDC)` :rtype: :ref:`wx.GraphicsContext` :html:`

` .. method:: CreateBitmap(self, bitmap) Creates :ref:`wx.GraphicsBitmap` from an existing :ref:`wx.Bitmap`. Returns an invalid NullGraphicsBitmap on failure. :param `bitmap`: :type `bitmap`: wx.Bitmap :rtype: :ref:`wx.GraphicsBitmap` .. method:: CreateBitmapFromImage(self, image) Creates :ref:`wx.GraphicsBitmap` from an existing :ref:`wx.Image`. This method is more efficient than converting :ref:`wx.Image` to :ref:`wx.Bitmap` first and then calling :meth:`CreateBitmap` but otherwise has the same effect. Returns an invalid NullGraphicsBitmap on failure. :param `image`: :type `image`: wx.Image :rtype: :ref:`wx.GraphicsBitmap` .. versionadded:: 2.9.3 .. method:: CreateBrush(self, brush) Creates a native brush from a :ref:`wx.Brush`. :param `brush`: :type `brush`: wx.Brush :rtype: :ref:`wx.GraphicsBrush` .. method:: CreateFont(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **CreateFont** `(self, font, col=BLACK)` Creates a native graphics font from a :ref:`wx.Font` and a text colour. :param `font`: :type `font`: wx.Font :param `col`: :type `col`: wx.Colour :rtype: :ref:`wx.GraphicsFont` .. note:: For Direct2D graphics fonts can be created from TrueType fonts only. :html:`

` **CreateFont** `(self, sizeInPixels, facename, flags=FONTFLAG_DEFAULT, col=BLACK)` Creates a font object with the specified attributes. The use of overload taking :ref:`wx.Font` is preferred, see :meth:`wx.GraphicsRenderer.CreateFont` for more details. :param `sizeInPixels`: :type `sizeInPixels`: float :param `facename`: :type `facename`: string :param `flags`: :type `flags`: int :param `col`: :type `col`: wx.Colour :rtype: :ref:`wx.GraphicsFont` .. versionadded:: 2.9.3 .. note:: For Direct2D graphics fonts can be created from TrueType fonts only. :html:`

` .. staticmethod:: CreateFromNative(context) Creates a :ref:`wx.GraphicsContext` from a native context. This native context must be a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus, or a cairo_t pointer for cairo. :param `context`: :rtype: :ref:`wx.GraphicsContext` .. seealso:: :meth:`wx.GraphicsRenderer.CreateContextFromNativeContext` .. staticmethod:: CreateFromNativeWindow(window) Creates a :ref:`wx.GraphicsContext` from a native window. :param `window`: :rtype: :ref:`wx.GraphicsContext` .. seealso:: :meth:`wx.GraphicsRenderer.CreateContextFromNativeWindow` .. staticmethod:: CreateFromUnknownDC(dc) Creates a :ref:`wx.GraphicsContext` from a DC of unknown specific type. Creates a :ref:`wx.GraphicsContext` if `dc` is a supported type (i.e. has a corresponding :meth:`Create` method, e.g. :ref:`wx.WindowDC` or :ref:`wx.MemoryDC`). Returns ``None`` if the DC is unsupported. This method is only useful as a helper in generic code that operates with :ref:`wx.DC` and doesn't known its exact type. Use :meth:`Create` instead if you know that the DC is e.g. :ref:`wx.WindowDC`. :param `dc`: :type `dc`: wx.DC :rtype: :ref:`wx.GraphicsContext` .. versionadded:: 4.1/wxWidgets-3.1.1 .. seealso:: :meth:`wx.GraphicsRenderer.CreateContextFromUnknownDC` .. method:: CreateLinearGradientBrush(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **CreateLinearGradientBrush** `(self, x1, y1, x2, y2, c1, c2, matrix=NullGraphicsMatrix)` Creates a native brush with a linear gradient. The brush starts at (`x1`, `y1`) and ends at (`x2`, `y2`). Either just the start and end gradient colours (`c1` and `c2`) or full set of gradient `stops` can be specified. The version taking :ref:`wx.GraphicsGradientStops` is new in wxWidgets 2.9.1. The `matrix` parameter was added in wxWidgets 3.1.3 :param `x1`: :type `x1`: wx.Double :param `y1`: :type `y1`: wx.Double :param `x2`: :type `x2`: wx.Double :param `y2`: :type `y2`: wx.Double :param `c1`: :type `c1`: wx.Colour :param `c2`: :type `c2`: wx.Colour :param `matrix`: :type `matrix`: wx.GraphicsMatrix :rtype: :ref:`wx.GraphicsBrush` :html:`

` **CreateLinearGradientBrush** `(self, x1, y1, x2, y2, stops, matrix=NullGraphicsMatrix)` This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. :param `x1`: :type `x1`: wx.Double :param `y1`: :type `y1`: wx.Double :param `x2`: :type `x2`: wx.Double :param `y2`: :type `y2`: wx.Double :param `stops`: :type `stops`: wx.GraphicsGradientStops :param `matrix`: :type `matrix`: wx.GraphicsMatrix :rtype: :ref:`wx.GraphicsBrush` :html:`

` .. method:: CreateMatrix(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **CreateMatrix** `(self, a=1.0, b=0.0, c=0.0, d=1.0, tx=0.0, ty=0.0)` Creates a native affine transformation matrix from the passed in values. The default parameters result in an identity matrix. :param `a`: :type `a`: wx.Double :param `b`: :type `b`: wx.Double :param `c`: :type `c`: wx.Double :param `d`: :type `d`: wx.Double :param `tx`: :type `tx`: wx.Double :param `ty`: :type `ty`: wx.Double :rtype: :ref:`wx.GraphicsMatrix` :html:`

` **CreateMatrix** `(self, mat)` Creates a native affine transformation matrix from the passed generic one. :param `mat`: :type `mat`: wx.AffineMatrix2DBase :rtype: :ref:`wx.GraphicsMatrix` .. versionadded:: 2.9.4 :html:`

` .. method:: CreatePath(self) Creates a native graphics path which is initially empty. :rtype: :ref:`wx.GraphicsPath` .. method:: CreatePen(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **CreatePen** `(self, pen)` Creates a native pen from a :ref:`wx.Pen`. Prefer to use the overload taking :ref:`wx.GraphicsPenInfo` unless you already have a :ref:`wx.Pen` as constructing one only to pass it to this method is wasteful. :param `pen`: :type `pen`: wx.Pen :rtype: :ref:`wx.GraphicsPen` :html:`

` **CreatePen** `(self, info)` Creates a native pen from a :ref:`wx.GraphicsPenInfo`. :param `info`: :type `info`: wx.GraphicsPenInfo :rtype: :ref:`wx.GraphicsPen` .. versionadded:: 4.1/wxWidgets-3.1.1 :html:`

` .. method:: CreateRadialGradientBrush(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **CreateRadialGradientBrush** `(self, startX, startY, endX, endY, radius, oColor, cColor, matrix=NullGraphicsMatrix)` Creates a native brush with a radial gradient. The brush originates at (`startX`, `startY`) and ends on a circle around (`endX`, `endY`) with the given `radius`. The gradient may be specified either by its start and end colours `oColor` and `cColor` or by a full set of gradient `stops`. The version taking :ref:`wx.GraphicsGradientStops` is new in wxWidgets 2.9.1. The ability to apply a transformation matrix to the gradient was added in 3.1.3 :param `startX`: :type `startX`: wx.Double :param `startY`: :type `startY`: wx.Double :param `endX`: :type `endX`: wx.Double :param `endY`: :type `endY`: wx.Double :param `radius`: :type `radius`: wx.Double :param `oColor`: :type `oColor`: wx.Colour :param `cColor`: :type `cColor`: wx.Colour :param `matrix`: :type `matrix`: wx.GraphicsMatrix :rtype: :ref:`wx.GraphicsBrush` :html:`

` **CreateRadialGradientBrush** `(self, startX, startY, endX, endY, radius, stops, matrix=NullGraphicsMatrix)` This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. :param `startX`: :type `startX`: wx.Double :param `startY`: :type `startY`: wx.Double :param `endX`: :type `endX`: wx.Double :param `endY`: :type `endY`: wx.Double :param `radius`: :type `radius`: wx.Double :param `stops`: :type `stops`: wx.GraphicsGradientStops :param `matrix`: :type `matrix`: wx.GraphicsMatrix :rtype: :ref:`wx.GraphicsBrush` :html:`

` .. method:: CreateSubBitmap(self, bitmap, x, y, w, h) Extracts a sub-bitmap from an existing bitmap. :param `bitmap`: :type `bitmap`: wx.GraphicsBitmap :param `x`: :type `x`: wx.Double :param `y`: :type `y`: wx.Double :param `w`: :type `w`: wx.Double :param `h`: :type `h`: wx.Double :rtype: :ref:`wx.GraphicsBitmap` .. method:: DisableOffset(self) Helper to determine if a 0.5 offset should be applied for the drawing operation. .. method:: DrawBitmap(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **DrawBitmap** `(self, bmp, x, y, w, h)` Draws the bitmap. In case of a mono bitmap, this is treated as a mask and the current brushed is used for filling. :param `bmp`: :type `bmp`: wx.GraphicsBitmap :param `x`: :type `x`: wx.Double :param `y`: :type `y`: wx.Double :param `w`: :type `w`: wx.Double :param `h`: :type `h`: wx.Double :html:`

` **DrawBitmap** `(self, bmp, x, y, w, h)` This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. :param `bmp`: :type `bmp`: wx.Bitmap :param `x`: :type `x`: wx.Double :param `y`: :type `y`: wx.Double :param `w`: :type `w`: wx.Double :param `h`: :type `h`: wx.Double :html:`

` .. method:: DrawEllipse(self, x, y, w, h) Draws an ellipse. :param `x`: :type `x`: wx.Double :param `y`: :type `y`: wx.Double :param `w`: :type `w`: wx.Double :param `h`: :type `h`: wx.Double .. method:: DrawIcon(self, icon, x, y, w, h) Draws the icon. :param `icon`: :type `icon`: wx.Icon :param `x`: :type `x`: wx.Double :param `y`: :type `y`: wx.Double :param `w`: :type `w`: wx.Double :param `h`: :type `h`: wx.Double .. method:: DrawLines(self, point2Ds, fillStyle=ODDEVEN_RULE) Draws a polygon. .. method:: DrawPath(self, path, fillStyle=ODDEVEN_RULE) Draws the path by first filling and then stroking. :param `path`: :type `path`: wx.GraphicsPath :param `fillStyle`: :type `fillStyle`: wx.PolygonFillMode .. method:: DrawRectangle(self, x, y, w, h) Draws a rectangle. :param `x`: :type `x`: wx.Double :param `y`: :type `y`: wx.Double :param `w`: :type `w`: wx.Double :param `h`: :type `h`: wx.Double .. method:: DrawRoundedRectangle(self, x, y, w, h, radius) Draws a rounded rectangle. :param `x`: :type `x`: wx.Double :param `y`: :type `y`: wx.Double :param `w`: :type `w`: wx.Double :param `h`: :type `h`: wx.Double :param `radius`: :type `radius`: wx.Double .. method:: DrawText(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **DrawText** `(self, str, x, y)` Draws text at the defined position. :param `str`: :type `str`: string :param `x`: :type `x`: wx.Double :param `y`: :type `y`: wx.Double :html:`

` **DrawText** `(self, str, x, y, angle)` Draws text at the defined position. :param `str`: The text to draw. :type `str`: string :param `x`: The x coordinate position to draw the text at. :type `x`: wx.Double :param `y`: The y coordinate position to draw the text at. :type `y`: wx.Double :param `angle`: The angle, in radians, relative to the (default) horizontal direction to draw the string. :type `angle`: wx.Double :html:`

` **DrawText** `(self, str, x, y, backgroundBrush)` Draws text at the defined position. :param `str`: The text to draw. :type `str`: string :param `x`: The x coordinate position to draw the text at. :type `x`: wx.Double :param `y`: The y coordinate position to draw the text at. :type `y`: wx.Double :param `backgroundBrush`: Brush to fill the text with. :type `backgroundBrush`: wx.GraphicsBrush :html:`

` **DrawText** `(self, str, x, y, angle, backgroundBrush)` Draws text at the defined position. :param `str`: The text to draw. :type `str`: string :param `x`: The x coordinate position to draw the text at. :type `x`: wx.Double :param `y`: The y coordinate position to draw the text at. :type `y`: wx.Double :param `angle`: The angle, in radians, relative to the (default) horizontal direction to draw the string. :type `angle`: wx.Double :param `backgroundBrush`: Brush to fill the text with. :type `backgroundBrush`: wx.GraphicsBrush :html:`

` .. method:: EnableOffset(self, enable=True) Indicates whether the context should try to offset for pixel boundaries. This only makes sense on bitmap devices like screen. By default this is turned off. :param `enable`: :type `enable`: bool .. method:: EndDoc(self) Done with that document (relevant only for printing / pdf etc.) .. method:: EndLayer(self) Composites back the drawings into the context with the opacity given at the :meth:`BeginLayer` call. .. method:: EndPage(self) Ends the current page (relevant only for printing / pdf etc.) .. method:: FillPath(self, path, fillStyle=ODDEVEN_RULE) Fills the path with the current brush. :param `path`: :type `path`: wx.GraphicsPath :param `fillStyle`: :type `fillStyle`: wx.PolygonFillMode .. method:: Flush(self) Make sure that the current content of this context is immediately visible. .. method:: FromDIP(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **FromDIP** `(self, sz)` Convert DPI-independent pixel values to the value in pixels appropriate for the graphics context. See `Window.FromDIP(const` Size& sz) and `DC.FromDIP(const` Size& sz) for more info about converting device independent pixel values. :param `sz`: :type `sz`: wx.Size :rtype: :ref:`wx.Size` .. versionadded:: 4.1/wxWidgets-3.1.7 :html:`

` **FromDIP** `(self, pt)` This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. :param `pt`: :type `pt`: wx.Point :rtype: :ref:`wx.Point` :html:`

` **FromDIP** `(self, d)` Convert DPI-independent value in pixels to the value in pixels appropriate for the graphics context. This is the same as FromDIP(const Size& sz) overload, but assumes that the resolution is the same in horizontal and vertical directions. :param `d`: :type `d`: int :rtype: `int` .. versionadded:: 4.1/wxWidgets-3.1.7 :html:`

` .. method:: GetAntialiasMode(self) Returns the current shape antialiasing mode. :rtype: :ref:`wx.AntialiasMode` .. method:: GetClipBox(self, x, y, w, h) Returns bounding box of the current clipping region. :param `x`: :type `x`: wx.Double :param `y`: :type `y`: wx.Double :param `w`: :type `w`: wx.Double :param `h`: :type `h`: wx.Double .. versionadded:: 4.1/wxWidgets-3.1.1 .. note:: - If clipping region is empty, then empty rectangle is returned (`x`, `y`, `w`, `h` are set to zero). .. method:: GetCompositionMode(self) Returns the current compositing operator. :rtype: :ref:`wx.CompositionMode` .. method:: GetDPI(self) Returns the resolution of the graphics context in device points per inch. :rtype: `tuple` :returns: ( `dpiX`, `dpiY` ) .. method:: GetInterpolationQuality(self) Returns the current interpolation quality. :rtype: :ref:`wx.InterpolationQuality` .. method:: GetNativeContext(self) Returns the native context (CGContextRef for Core Graphics, Graphics pointer for GDIPlus and cairo_t pointer for cairo). .. method:: GetPartialTextExtents(self, text) Fills the `widths` array with the widths from the beginning of `text` to the corresponding character of `text`. :param `text`: :type `text`: string :rtype: `list of floats` .. method:: GetSize(self) Returns the size of the graphics context in device coordinates. :rtype: `tuple` :returns: ( `width`, `height` ) .. method:: GetFullTextExtent(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **GetFullTextExtent** `(self, text)` Gets the dimensions of the string using the currently selected font. :param `text`: The text string to measure. :type `text`: string :rtype: `tuple` :returns: ( `width`, `height`, `descent`, `externalLeading` ) :html:`

` **GetFullTextExtent** `(self, text)` Gets the dimensions of the string using the currently selected font. :rtype: `tuple` :returns: ( `width`, `height` ) :html:`

` .. method:: GetTransform(self) Gets the current transformation matrix of this context. :rtype: :ref:`wx.GraphicsMatrix` .. method:: GetWindow(self) Returns the associated window if any. If this context was created using :meth:`Create` overload taking :ref:`wx.Window` or :ref:`wx.WindowDC`, this method returns the corresponding window. Otherwise returns ``None``. :rtype: :ref:`wx.Window` :returns: A possibly ``None`` window pointer. .. versionadded:: 4.1/wxWidgets-3.1.2 .. method:: OffsetEnabled(self) Helper to determine if a 0.5 offset should be applied for the drawing operation. :rtype: `bool` .. method:: PopState(self) Sets current state of the context to the state saved by a preceding call to :meth:`PushState` and removes that state from the stack of saved states. .. seealso:: :meth:`PushState` .. method:: PushState(self) Push the current state (like transformations, clipping region and quality settings) of the context on a stack. Multiple balanced calls to :meth:`PushState` and :meth:`PopState` can be nested. .. seealso:: :meth:`PopState` .. method:: ResetClip(self) Resets the clipping to original shape. .. method:: Rotate(self, angle) Rotates the current transformation matrix (in radians). :param `angle`: :type `angle`: wx.Double .. method:: Scale(self, xScale, yScale) Scales the current transformation matrix. :param `xScale`: :type `xScale`: wx.Double :param `yScale`: :type `yScale`: wx.Double .. method:: SetAntialiasMode(self, antialias) Sets the antialiasing mode, returns ``True`` if it supported. :param `antialias`: :type `antialias`: wx.AntialiasMode :rtype: `bool` .. method:: SetBrush(self, *args, **kw) Sets the brush for filling paths. |overload| Overloaded Implementations: :html:`

` **SetBrush** `(self, brush)` :param `brush`: :type `brush`: wx.Brush :html:`

` **SetBrush** `(self, brush)` :param `brush`: :type `brush`: wx.GraphicsBrush :html:`

` .. method:: SetCompositionMode(self, op) Sets the compositing operator, returns ``True`` if it supported. :param `op`: :type `op`: wx.CompositionMode :rtype: `bool` .. method:: SetFont(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **SetFont** `(self, font, colour)` Sets the font for drawing text. :param `font`: :type `font`: wx.Font :param `colour`: :type `colour`: wx.Colour .. note:: For Direct2D only TrueType fonts can be used. :html:`

` **SetFont** `(self, font)` Sets the font for drawing text. :param `font`: :type `font`: wx.GraphicsFont :html:`

` .. method:: SetInterpolationQuality(self, interpolation) Sets the interpolation quality, returns ``True`` if it is supported. :param `interpolation`: :type `interpolation`: wx.InterpolationQuality :rtype: `bool` .. note:: Not implemented in Cairo backend currently. .. method:: SetPen(self, *args, **kw) Sets the pen used for stroking. |overload| Overloaded Implementations: :html:`

` **SetPen** `(self, pen)` :param `pen`: :type `pen`: wx.Pen :html:`

` **SetPen** `(self, pen)` :param `pen`: :type `pen`: wx.GraphicsPen :html:`

` .. method:: SetTransform(self, matrix) Sets the current transformation matrix of this context. :param `matrix`: :type `matrix`: wx.GraphicsMatrix .. method:: ShouldOffset(self) Helper to determine if a 0.5 offset should be applied for the drawing operation. :rtype: `bool` .. method:: StartDoc(self, message) Begin a new document (relevant only for printing / pdf etc.) If there is a progress dialog, message will be shown. :param `message`: :type `message`: string :rtype: `bool` .. method:: StartPage(self, width=0, height=0) Opens a new page (relevant only for printing / pdf etc.) with the given size in points. (If both are null the default page size will be used.) :param `width`: :type `width`: wx.Double :param `height`: :type `height`: wx.Double .. method:: StrokeLine(self, x1, y1, x2, y2) Strokes a single line. :param `x1`: :type `x1`: wx.Double :param `y1`: :type `y1`: wx.Double :param `x2`: :type `x2`: wx.Double :param `y2`: :type `y2`: wx.Double .. method:: StrokeLineSegments(self, beginPoint2Ds, endPoint2Ds) Stroke disconnected lines from begin to end points. .. method:: StrokeLines(self, point2Ds) Stroke lines connecting all the points. .. method:: StrokePath(self, path) Strokes along a path with the current pen. :param `path`: :type `path`: wx.GraphicsPath .. method:: ToDIP(self, *args, **kw) |overload| Overloaded Implementations: :html:`

` **ToDIP** `(self, sz)` Convert pixel values of the current graphics context to DPI-independent pixel values. See `Window.ToDIP(const` Size& sz) and `DC.ToDIP(const` Size& sz) for more info about converting device independent pixel values. :param `sz`: :type `sz`: wx.Size :rtype: :ref:`wx.Size` .. versionadded:: 4.1/wxWidgets-3.1.7 :html:`

` **ToDIP** `(self, pt)` This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. :param `pt`: :type `pt`: wx.Point :rtype: :ref:`wx.Point` :html:`

` **ToDIP** `(self, d)` Convert pixel values of the current graphics context to DPI-independent pixel values. This is the same as ToDIP(const Size& sz) overload, but assumes that the resolution is the same in horizontal and vertical directions. :param `d`: :type `d`: int :rtype: `int` .. versionadded:: 4.1/wxWidgets-3.1.7 :html:`

` .. method:: Translate(self, dx, dy) Translates the current transformation matrix. :param `dx`: :type `dx`: wx.Double :param `dy`: :type `dy`: wx.Double .. attribute:: AntialiasMode See :meth:`~wx.GraphicsContext.GetAntialiasMode` and :meth:`~wx.GraphicsContext.SetAntialiasMode` .. attribute:: CompositionMode See :meth:`~wx.GraphicsContext.GetCompositionMode` and :meth:`~wx.GraphicsContext.SetCompositionMode` .. attribute:: InterpolationQuality See :meth:`~wx.GraphicsContext.GetInterpolationQuality` and :meth:`~wx.GraphicsContext.SetInterpolationQuality` .. attribute:: NativeContext See :meth:`~wx.GraphicsContext.GetNativeContext` .. attribute:: TextExtent See :meth:`~wx.GraphicsContext.GetTextExtent` .. attribute:: Transform See :meth:`~wx.GraphicsContext.GetTransform` and :meth:`~wx.GraphicsContext.SetTransform` .. attribute:: Window See :meth:`~wx.GraphicsContext.GetWindow`