Skip to content

Gtk.CssSection

record (struct)

Defines a part of a CSS document.

Because sections are nested into one another, you can use CssSection.get_parent to get the containing region.

Constructors

new

@classmethod
def new(cls, file: Gio.File | None, start: CssLocation, end: CssLocation) -> CssSection

Creates a new GtkCssSection referring to the section in the given file from the start location to the end location.

Parameters:

  • file — The file this section refers to
  • start — The start location
  • end — The end location

new_with_bytes

@classmethod
def new_with_bytes(cls, file: Gio.File | None, bytes: bytes | None, start: CssLocation, end: CssLocation) -> CssSection

Creates a new GtkCssSection referring to the section in the given file or the given bytes from the start location to the end location.

Parameters:

  • file — The file this section refers to
  • bytes — The bytes this sections refers to
  • start — The start location
  • end — The end location

Methods

get_bytes

def get_bytes(self) -> bytes | None

Gets the bytes that section was parsed from.

get_end_location

def get_end_location(self) -> CssLocation

Returns the location in the CSS document where this section ends.

get_file

def get_file(self) -> Gio.File | None

Gets the file that section was parsed from.

If no such file exists, for example because the CSS was loaded via CssProvider.load_from_data, then NULL is returned.

get_parent

def get_parent(self) -> CssSection | None

Gets the parent section for the given section.

The parent section is the section that contains this section. A special case are sections of type GTK_CSS_SECTION_DOCUMENT. Their parent will either be NULL if they are the original CSS document that was loaded by CssProvider.load_from_file or a section of type GTK_CSS_SECTION_IMPORT if it was loaded with an @import rule from a different file.

get_start_location

def get_start_location(self) -> CssLocation

Returns the location in the CSS document where this section starts.

print

def print(self, string: GLib.String) -> None

Prints the section into string in a human-readable form.

This is a form like gtk.css:32:1-23 to denote line 32, characters 1 to 23 in the file gtk.css.

Parameters:

  • string — a GString to print to

ref

def ref(self) -> CssSection

Increments the reference count on section.

to_string

def to_string(self) -> str

Prints the section into a human-readable text form using CssSection.print.

unref

def unref(self) -> None

Decrements the reference count on section, freeing the structure if the reference count reaches 0.