Gtk.SvgWidget

g GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget Gtk.SvgWidget Gtk.SvgWidget Gtk.Widget->Gtk.SvgWidget

Subclasses:

None

Methods

Inherited:

Gtk.Widget (183), GObject.Object (37), Gtk.Accessible (18), Gtk.Buildable (1)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new ()

get_state ()

get_stylesheet ()

load_from_bytes (bytes)

set_state (state)

set_stylesheet (bytes)

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (7), Gtk.Buildable (9)

Properties

Inherited:

Gtk.Widget (35), Gtk.Accessible (1)

Name

Type

Flags

Short Description

resource

str

r/w

state

int

r/w/en

stylesheet

GLib.Bytes

r/w/en

svg

Gtk.Svg

r/en

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Name

Short Description

activate

Emitted when a link or other element is activated.

error

Signals that an error occurred.

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Class Details

class Gtk.SvgWidget(**kwargs)
Bases:

Gtk.Widget

Abstract:

No

Structure:

Gtk.SvgWidgetClass

A widget that renders SVG, with animations and event handling.

GtkSvgWidget uses [class`Gtk`.Svg] internally, and should read its documentation to learn about the supported SVG features and extensions.

On top of the GtkSvg rendering, GtkSvgWidget adds event handling. <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keys can be used to move the focus and <kbd>Enter</kbd> and clicks will activate links by emitting the [signal`Gtk`.SvgWidget::activate] signal.

The tabindex and autofocus attributes can be used to influence what elements act as focus locations, and where focus goes initially.

The styling of the SVG content is following input-related pseudo classes such as :focus, :active, :hover or :visited.

If [property`Gtk`.Widget:has-tooltip] is set, then the content of <title> elements will be shown as tooltips.

SVG animations and different ``<view>``s can be triggered by input events as well. The following events are supported: focus, blur, mouseenter, mouseleave, click. See the SVG animation specification for details.

Added in version 4.24.

classmethod new()[source]
Returns:

the new widget

Return type:

Gtk.SvgWidget

Creates a new, empty GtkSvgWidget.

Added in version 4.24.

get_state()[source]
Returns:

the state

Return type:

int

Gets the current state of the widget.

Added in version 4.24.

get_stylesheet()[source]
Returns:

a GBytes with the CSS data

Return type:

GLib.Bytes or None

Gets the CSS user stylesheet.

Added in version 4.24.

load_from_bytes(bytes)[source]
Parameters:

bytes (GLib.Bytes) – the data to data

Loads SVG content into an existing SVG widget.

To track errors while loading SVG content, connect to the [signal`Gtk`.SvgWidget::error] signal.

This clears any previously loaded content.

Added in version 4.24.

set_state(state)[source]
Parameters:

state (int) – the state to set, as a value between 0 and 63

Sets the state of the widget.

The state change will apply transitions that are defined in the SVG. See [class`Gtk`.Svg] for details about states and transitions.

Added in version 4.24.

set_stylesheet(bytes)[source]
Parameters:

bytes (GLib.Bytes or None) – CSS data

Sets a CSS user stylesheet to use.

Note that styles are applied at load time, so this function must be called before loading SVG.

Added in version 4.24.

Signal Details

Gtk.SvgWidget.signals.activate(svg_widget, id, href)
Signal Name:

activate

Flags:

RUN_LAST

Parameters:
  • svg_widget (Gtk.SvgWidget) – The object which received the signal

  • id (str or None) – the ID of the element

  • href (str or None) – the href, if the element is a link

Emitted when a link or other element is activated.

Activating elements can be achieved by clicking or by hitting <kbd>Enter</kbd> while the element has focus.

Added in version 4.24.

Gtk.SvgWidget.signals.error(svg_widget, error)
Signal Name:

error

Flags:

RUN_LAST

Parameters:

Signals that an error occurred.

Errors can occur both during parsing and during rendering.

The expected error values are in the [error`Gtk`.SvgError] enumeration, context information about the location of parsing errors can be obtained with the various gtk_svg_error functions.

Parsing errors are never fatal, so the parsing will resume after the error. Errors may however cause parts of the given data or even all of it to not be parsed at all. So it is a useful idea to check that the parsing succeeds by connecting to this signal.

::: note This signal is emitted in the middle of parsing or rendering, and if you handle it, you must be careful. Logging the errors you receive is fine, but modifying the widget hierarchy or changing the paintable state definitively isn’t.

If in doubt, defer to an idle.

Added in version 4.24.

Property Details

Gtk.SvgWidget.props.resource
Name:

resource

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE

Resource to load SVG data from.

This property is meant for use in ui files.

Added in version 4.24.

Gtk.SvgWidget.props.state
Name:

state

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The current state of the renderer.

This can be a number between 0 and 63.

Added in version 4.24.

Gtk.SvgWidget.props.stylesheet
Name:

stylesheet

Type:

GLib.Bytes

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

A CSS stylesheet to apply to the SVG.

Added in version 4.24.

Gtk.SvgWidget.props.svg
Name:

svg

Type:

Gtk.Svg

Default Value:

None

Flags:

READABLE, EXPLICIT_NOTIFY

The Gtk.Svg paintable used for rendering.

This property is mainly useful for making details of the SVG rendering machinery available in the GTK inspector.

You should not modify the returned object.

Added in version 4.24.