CssProvider#
Superclasses: Object
Implemented Interfaces: StyleProvider
GtkCssProvider
is an object implementing the GtkStyleProvider
interface
for CSS.
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
load_from_file
or
load_from_resource
and adding the provider with add_provider
or
add_provider_for_display
.
In addition, certain files will be read when GTK is initialized.
First, the file $XDG_CONFIG_HOME/gtk-4.0/gtk.css
is loaded if it
exists. Then, GTK loads the first existing file among
XDG_DATA_HOME/themes/THEME/gtk-VERSION/gtk-VARIANT.css
,
$HOME/.themes/THEME/gtk-VERSION/gtk-VARIANT.css
,
$XDG_DATA_DIRS/themes/THEME/gtk-VERSION/gtk-VARIANT.css
and
DATADIR/share/themes/THEME/gtk-VERSION/gtk-VARIANT.css
,
where THEME
is the name of the current theme (see the
gtk_theme_name
setting), VARIANT
is the
variant to load (see the
gtk_application_prefer_dark_theme
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 4.0.
To track errors while loading CSS, connect to the
parsing_error
signal.
Constructors#
- class CssProvider
- classmethod new() CssProvider #
Returns a newly created
GtkCssProvider
.
Methods#
- class CssProvider
- load_from_bytes(data: Bytes) None #
Loads
data
intocss_provider
.This clears any previously loaded information.
Added in version 4.12.
- Parameters:
data –
GBytes
containing the data to load
- load_from_data(text, length=-1)#
Loads
data
intocss_provider
.This clears any previously loaded information.
Deprecated since version 4.12: Use
load_from_string
orload_from_bytes
instead- Parameters:
text
length – the length of
data
in bytes, or -1 for NUL terminated strings
- load_from_file(file: File) None #
Loads the data contained in
file
intocss_provider
.This clears any previously loaded information.
- Parameters:
file –
GFile
pointing to a file to load
- load_from_path(path: str) None #
Loads the data contained in
path
intocss_provider
.This clears any previously loaded information.
- Parameters:
path – the path of a filename to load, in the GLib filename encoding
- load_from_resource(resource_path: str) None #
Loads the data contained in the resource at
resource_path
into thecss_provider
.This clears any previously loaded information.
- Parameters:
resource_path – a
GResource
resource path
- load_from_string(string: str) None #
Loads
string
intocss_provider
.This clears any previously loaded information.
Added in version 4.12.
- Parameters:
string – the CSS to load
- load_named(name: str, variant: str | None = None) None #
Loads a theme from the usual theme paths.
The actual process of finding the theme might change between releases, but it is guaranteed that this function uses the same mechanism to load the theme that GTK uses for loading its own theme.
- Parameters:
name – A theme name
variant – variant to load, for example, “dark”, or
None
for the default
- to_string() str #
Converts the
provider
into a string representation in CSS format.Using
load_from_string
with the return value from this function on a new provider created withnew
will basically create a duplicate of thisprovider
.
Signals#
- class CssProvider.signals
- parsing_error(section: CssSection, error: GError) None #
The type of the None singleton.
- Parameters:
section – section the error happened in
error – The parsing error
Fields#
- class CssProvider
- parent_instance#