CSS Manager#

class ignis.css_manager.CssManager(*args: Any, **kwargs: Any)#

The CSS manager. Provides convenient utilities to apply, remove, and reload CSS.

Example usage:

import os
from ignis.css_manager import CssManager, CssInfoString, CssInfoPath
from ignis import utils

css_manager = CssManager.get_default()

# Apply from a path
css_manager.apply_css(
    CssInfoPath(
        name="main",
        path="PATH/TO/style.css", # e.g., os.path.join(utils.get_current_dir(), "style.css"),
    )
)

# Apply from a string
css_manager.apply_css(
    CssInfoString(
        name="some-name",
        string="* { background-color: red; }",
    )
)

# Remove an applied info
css_manager.remove_css("some-name")

# Reload an applied info
css_manager.reload_css("main")

Sass/SCSS compilation

You can use CssInfoBase.compiler_function to compile Sass/SCSS:

from ignis.css_manager import CssManager, CssInfoString, CssInfoPath
from ignis import utils

css_manager = CssManager.get_default()

# File
css_manager.apply_css(
    CssInfoPath(
        name="main",
        path="PATH/TO/style.scss",
        compiler_function=lambda path: utils.sass_compile(path=path),
    )
)

# String
css_manager.apply_css(
    CssInfoString(
        name="some-name",
        string="some sass/scss string",
        compiler_function=lambda string: utils.sass_compile(string=string),
    )
)
signal css_applied#

Emitted when a CSS info has been applied.

Parameters:

info (CssInfoString | CssInfoPath) -- The applied CSS.

signal css_removed#

Emitted when a CSS info has been removed.

Parameters:

info (CssInfoString | CssInfoPath) -- The removed CSS.

signal css_resetted#

Emitted when all applied CSS infos have been resetted.

signal css_reloaded#

Emitted when a CSS info has been reloaded.

Parameters:

info (CssInfoString | CssInfoPath) -- The reloaded CSS.

signal all_css_reloaded#

Emitted when all applied CSS infos have been reloaded.

gproperty widgets_style_priority: Literal['application', 'fallback', 'settings', 'theme', 'user']#
  • read-write

The priority used for each widget style property. unless a widget specifies a custom style priority using style_priority. For more information about style priorities see Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION and CssInfoPath.priority.

Default: "application".

Warning

Changing this property won't affect already initialized widgets! If you want to set a custom global style priority for all widgets, do this before initializing them (e.g., at the start of your configuration).

from ignis.css_manager import CssManager

css_manager = CssManager.get_default()

css_manager.widgets_style_priority = "user"
apply_css(info: CssInfoString | CssInfoPath) None#

Apply a CSS info.

Parameters:

info (CssInfoString | CssInfoPath) -- The CSS info to apply.

Raises:
Return type:

None

remove_css(name: str) None#

Remove CSS info by its name.

Parameters:

name (str) -- The name of the CSS info to remove.

Raises:

CssInfoNotFoundError -- If no CSS info with the given name is found.

Return type:

None

reset_css() None#

Remove all applied CSS infos.

Return type:

None

reload_css(name: str) None#

Reload a CSS info by its name.

Parameters:

name (str) -- The name of the CSS info to reload.

Return type:

None

reload_all_css() None#

Reload all applied CSS infos.

Return type:

None

get_css_info_by_name(name: str) CssInfoPath | CssInfoString | None#

Get an applied CSS info by its name:

Parameters:

name (str) -- The name of the CSS info to get.

Return type:

CssInfoPath | CssInfoString | None

Returns:

The CSS info, or None if the CSS info with the given name is not applied.

list_css_infos() list[CssInfoString | CssInfoPath]#

List all applied CSS infos.

Return type:

list[CssInfoString | CssInfoPath]

Returns:

A list of all applied CSS infos.

list_css_info_names() list[str]#

List names of all applied CSS infos.

Return type:

list[str]

Returns:

A list of all applied CSS info names.

class ignis.css_manager.CssInfoBase(*, name: str, priority: Literal['application', 'fallback', 'settings', 'theme', 'user'] = 'application', compiler_function: Callable[[str], str] | None = None) None#

The base class for CSS infos.

You shouldn't use it, use CssInfoString or CssInfoPath instead.

name: str#

The name of the info by which you will be able to use CssManager functions.

priority: Literal['application', 'fallback', 'settings', 'theme', 'user'] = 'application'#

The style priority. Most likely you should use either "application" or "user".

  • "user" - you want to override styles defined in ~/.config/gtk-4.0/gtk.css

  • "application" (the default one) - you do not want to override it.

compiler_function: Callable[[str], str] | None = None#

A custom compiler function. It should receive only one argument:

It must return a string containing a valid CSS code.

class ignis.css_manager.CssInfoPath(*, name: str, priority: Literal['application', 'fallback', 'settings', 'theme', 'user'] = 'application', compiler_function: Callable[[str], str] | None = None, path: str, autoreload: bool = True, watch_dir: bool = True, watch_recursively: bool = True) None#

CSS info for a path.

path: str#

The path to the CSS file.

autoreload: bool = True#

Whether to automatically reload this info when the file changes.

watch_dir: bool = True#

Whether to additionally watch for the changes of the directory where the file is placed.

watch_recursively: bool = True#

Whether to watch the directory recursively.

class ignis.css_manager.CssInfoString(*, name: str, priority: Literal['application', 'fallback', 'settings', 'theme', 'user'] = 'application', compiler_function: Callable[[str], str] | None = None, string: str) None#

CSS info for a string.

string: str#

A string containing CSS code.