wijjit.styling.theme.Theme
- class wijjit.styling.theme.Theme(name, styles)[source]
A named collection of style definitions for UI elements.
Themes provide consistent styling across all UI elements by defining styles for element classes and pseudo-classes (focus, hover, disabled).
- Parameters:
- Variables:
Examples
Create a simple theme:
>>> theme = Theme('custom', { ... 'button': Style(bg_color=(0, 100, 200)), ... 'button:focus': Style(bg_color=(0, 120, 255), bold=True) ... }) >>> theme.get_style('button').bg_color (0, 100, 200)
Get focused button style:
>>> focus_style = theme.get_style('button:focus') >>> focus_style.bold True
Methods
__init__(name, styles)from_css(filepath[, name])Create a Theme from a CSS file.
get_style(class_name)Get style for an element class.
set_style(class_name, style)Set style for an element class.
- get_style(class_name)[source]
Get style for an element class.
- Parameters:
class_name (
str) – Element class name (e.g., ‘button’, ‘button:focus’)- Returns:
Style for the class, or default empty style if not defined
- Return type:
Style
Notes
Returns an empty Style if the class is not defined in the theme, ensuring graceful fallback behavior.
Examples
>>> theme = Theme('test', {'button': Style(bold=True)}) >>> style = theme.get_style('button') >>> style.bold True >>> unknown = theme.get_style('unknown') >>> bool(unknown) False
- set_style(class_name, style)[source]
Set style for an element class.
- Parameters:
class_name (
str) – Element class namestyle (
Style) – Style to set
- Return type:
None
Notes
Allows runtime modification of themes for customization.
Examples
>>> theme = Theme('custom', {}) >>> theme.set_style('button', Style(bold=True)) >>> theme.get_style('button').bold True
- classmethod from_css(filepath, name='custom')[source]
Create a Theme from a CSS file.
- Parameters:
- Returns:
New Theme instance with styles loaded from CSS
- Return type:
Notes
The CSS file should use Wijjit-compatible property names and values. See CSSParser documentation for supported CSS syntax.
Examples
Load theme from CSS file:
>>> theme = Theme.from_css("my_theme.css", "my_theme")
Or combine with built-in theme:
>>> from wijjit.styling.theme import DefaultTheme >>> base_theme = DefaultTheme() >>> custom_styles = Theme.from_css("overrides.css") >>> # Merge custom styles into base theme >>> base_theme.styles.update(custom_styles.styles)