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 usingstyle_priority
. For more information about style priorities seeGtk.STYLE_PROVIDER_PRIORITY_APPLICATION
andCssInfoPath.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:
CssInfoAlreadyAppliedError -- If CSS info with the given name is already applied.
CssParsingError -- If a CSS parsing error occurs, usually due to invalid CSS.
- Return type:
- 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:
- 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:
- 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:
- Returns:
A list of all applied CSS infos.
- 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
orCssInfoPath
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:
CssInfoString
- the stringCssInfoPath
- the path
It must return a string containing a valid CSS code.
-
name:
- 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.