Theme Manager¶
The ThemeManager is a QObject that allows for Trace to achieve a uniform look/feel throughout the application. It determines if the app should display a light or a dark theme and manages color palettes for each.
Theme
¶
Bases: Enum
Theme enumeration for light and dark modes.
IconColors
¶
Constants for icon color types.
ThemeManager(app, parent=None)
¶
Bases: QObject
Theme manager for Qt applications with icon support. It manages both Qt palette themes and icon colors, providing a unified interface for light/dark mode switching with persistent settings.
Attributes:
| Name | Type | Description |
|---|---|---|
theme_changed |
Signal
|
Signal emitted when theme changes, passes Theme enum value. |
current_theme |
Theme
|
Currently active theme. |
app |
QApplication
|
Qt application instance. |
light_palette |
QPalette
|
Palette configuration for light theme. |
dark_palette |
QPalette
|
Palette configuration for dark theme. |
light_icon_colors |
IconColorDict
|
Icon color mapping for light theme. |
dark_icon_colors |
IconColorDict
|
Icon color mapping for dark theme. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
QApplication
|
The Qt application instance to manage themes for. |
required |
parent
|
QObject | None
|
Parent QObject for memory management, by default None. |
None
|
Examples:
>>> app = QApplication(sys.argv)
>>> theme_manager = IntegratedThemeManager(app)
>>> theme_manager.set_theme(Theme.DARK)
Source code in trace/services/theme_manager.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
set_theme(theme)
¶
Set the application theme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theme
|
Theme
|
The theme to apply (Theme.LIGHT or Theme.DARK). |
required |
Examples:
>>> theme_manager.set_theme(Theme.DARK)
>>> theme_manager.set_theme(Theme.LIGHT)
Source code in trace/services/theme_manager.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
toggle_theme()
¶
Toggle between light and dark themes.
Switches from light to dark or dark to light, whichever is opposite to the current theme.
Examples:
>>> theme_manager.toggle_theme() # Switches to opposite theme
Source code in trace/services/theme_manager.py
202 203 204 205 206 207 208 209 210 211 212 213 214 | |
get_current_theme()
¶
Get the current theme.
Returns:
| Type | Description |
|---|---|
Theme
|
The currently active theme. |
Source code in trace/services/theme_manager.py
216 217 218 219 220 221 222 223 224 225 | |
get_icon_color(color_type=IconColors.PRIMARY)
¶
Get icon color for the current theme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color_type
|
str
|
The type of icon color to retrieve, by default IconColors.PRIMARY. Must be one of the IconColors constants. |
PRIMARY
|
Returns:
| Type | Description |
|---|---|
ColorHex
|
Hex color string (e.g., '#ffffff') appropriate for the current theme. |
Examples:
>>> color = theme_manager.get_icon_color(IconColors.PRIMARY)
>>> warning_color = theme_manager.get_icon_color(IconColors.WARNING)
Source code in trace/services/theme_manager.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
create_icon(icon_name, color_type=IconColors.PRIMARY, scale_factor=1.0, custom_color=None)
¶
Create a themed icon using qtawesome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
icon_name
|
str
|
The qtawesome icon name (e.g., 'fa.home', 'mdi.gear'). |
required |
color_type
|
str
|
The type of icon color to use, by default IconColors.PRIMARY. |
PRIMARY
|
scale_factor
|
float
|
Scale factor for icon size, by default 1.0. |
1.0
|
custom_color
|
ColorHex | None
|
Custom hex color to override theme color, by default None. |
None
|
Returns:
| Type | Description |
|---|---|
QIcon | None
|
The created icon, or None if qtawesome is not available. |
Examples:
>>> icon = theme_manager.create_icon('fa.home')
>>> warning_icon = theme_manager.create_icon('fa.exclamation-triangle', IconColors.WARNING)
>>> custom_icon = theme_manager.create_icon('fa.gear', custom_color='#ff0000')
Source code in trace/services/theme_manager.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
get_all_icon_colors()
¶
Get all available icon colors for the current theme.
Returns:
| Type | Description |
|---|---|
IconColorDict
|
Dictionary mapping color type names to hex color strings. |
Examples:
>>> colors = theme_manager.get_all_icon_colors()
>>> primary_color = colors[IconColors.PRIMARY]
Source code in trace/services/theme_manager.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |