Gtk.CssProvider

g GObject.GInterface GObject.GInterface Gtk.StyleProvider Gtk.StyleProvider GObject.GInterface->Gtk.StyleProvider GObject.Object GObject.Object Gtk.CssProvider Gtk.CssProvider GObject.Object->Gtk.CssProvider Gtk.StyleProvider->Gtk.CssProvider

Subclasses

None

Methods

Inherited

GObject.Object (37), Gtk.StyleProvider (3)

Structs

GObject.ObjectClass (5)

class

get_default ()

class

get_named (name, variant)

class

new ()

load_from_data (data)

load_from_file (file)

load_from_path (path)

load_from_resource (resource_path)

to_string ()

Virtual Methods

Inherited

GObject.Object (7), Gtk.StyleProvider (3)

do_parsing_error (section, error)

Properties

None

Signals

Inherited

GObject.Object (1)

Name

Short Description

parsing-error

Signals that a parsing error occurred.

Fields

Inherited

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Gtk.CssProvider(**kwargs)
Bases

GObject.Object, Gtk.StyleProvider

Abstract

No

Structure

Gtk.CssProviderClass

Gtk.CssProvider is an object implementing the Gtk.StyleProvider interface. It is able to parse CSS-like input in order to style widgets.

An application can make GTK+ parse a specific CSS style sheet by calling Gtk.CssProvider.load_from_file() or Gtk.CssProvider.load_from_resource() and adding the provider with Gtk.StyleContext.add_provider() or Gtk.StyleContext.add_provider_for_screen().

In addition, certain files will be read when GTK+ is initialized. First, the file $XDG_CONFIG_HOME/gtk-3.0/gtk.css is loaded if it exists. Then, GTK+ loads the first existing file among XDG_DATA_HOME/themes/THEME/gtk-VERSION/gtk.css, $HOME/.themes/THEME/gtk-VERSION/gtk.css, $XDG_DATA_DIRS/themes/THEME/gtk-VERSION/gtk.css and DATADIR/share/themes/THEME/gtk-VERSION/gtk.css, where THEME is the name of the current theme (see the Gtk.Settings :gtk-theme-name setting), DATADIR is the prefix configured when GTK+ was compiled (unless overridden by the GTK_DATA_PREFIX environment variable), and VERSION is the GTK+ version number. If no file is found for the current version, GTK+ tries older versions all the way back to 3.0.

In the same way, GTK+ tries to load a gtk-keys.css file for the current key theme, as defined by Gtk.Settings :gtk-key-theme-name.

classmethod get_default()[source]
Returns

The provider used for fallback styling. This memory is owned by GTK+, and you must not free it.

Return type

Gtk.CssProvider

Returns the provider containing the style settings used as a fallback for all widgets.

Deprecated since version 3.24: Use Gtk.CssProvider.new() instead.

classmethod get_named(name, variant)[source]
Parameters
  • name (str) – A theme name

  • variant (str or None) – variant to load, for example, “dark”, or None for the default

Returns

a Gtk.CssProvider with the theme loaded. This memory is owned by GTK+, and you must not free it.

Return type

Gtk.CssProvider

Loads a theme from the usual theme paths

classmethod new()[source]
Returns

A new Gtk.CssProvider

Return type

Gtk.CssProvider

Returns a newly created Gtk.CssProvider.

load_from_data(data)[source]
Parameters

data (bytes) – CSS data loaded in memory

Raises

GLib.Error

Returns

True. The return value is deprecated and False will only be returned for backwards compatibility reasons if an error is not None and a loading error occurred. To track errors while loading CSS, connect to the Gtk.CssProvider ::parsing-error signal.

Return type

bool

Loads data into self, and by doing so clears any previously loaded information.

load_from_file(file)[source]
Parameters

file (Gio.File) – Gio.File pointing to a file to load

Raises

GLib.Error

Returns

True. The return value is deprecated and False will only be returned for backwards compatibility reasons if an error is not None and a loading error occurred. To track errors while loading CSS, connect to the Gtk.CssProvider ::parsing-error signal.

Return type

bool

Loads the data contained in file into self, making it clear any previously loaded information.

load_from_path(path)[source]
Parameters

path (str) – the path of a filename to load, in the GLib filename encoding

Raises

GLib.Error

Returns

True. The return value is deprecated and False will only be returned for backwards compatibility reasons if an error is not None and a loading error occurred. To track errors while loading CSS, connect to the Gtk.CssProvider ::parsing-error signal.

Return type

bool

Loads the data contained in path into self, making it clear any previously loaded information.

load_from_resource(resource_path)[source]
Parameters

resource_path (str) – a Gio.Resource resource path

Loads the data contained in the resource at resource_path into the Gtk.CssProvider, clearing any previously loaded information.

To track errors while loading CSS, connect to the Gtk.CssProvider ::parsing-error signal.

New in version 3.16.

to_string()[source]
Returns

a new string representing the self.

Return type

str

Converts the self into a string representation in CSS format.

Using Gtk.CssProvider.load_from_data() with the return value from this function on a new provider created with Gtk.CssProvider.new() will basically create a duplicate of this self.

New in version 3.2.

do_parsing_error(section, error) virtual
Parameters

Signal Details

Gtk.CssProvider.signals.parsing_error(css_provider, section, error)
Signal Name

parsing-error

Flags

RUN_LAST

Parameters

Signals that a parsing error occurred. the path, line and position describe the actual location of the error as accurately as possible.

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 that this signal may be emitted at any time as the css provider may opt to defer parsing parts or all of the input to a later time than when a loading function was called.