Dui¶
dui ¶
Declarative UI packages for deux (.dui).
Load SVG + YAML packages and use them as touchscreen cards or physical keys without writing any Python rendering code.
Examples:
::
from deux import DuiCard, DuiKey
# Resolve by name — uses the built-in DUI repository
card = DuiCard("DashboardCard")
key = DuiKey("IconKey")
key.set("label", "Power")
@card.on("toggle_play_pause")
async def handle():
...
# Add a custom search path for your own packages
from deux import add_dui_path
add_dui_path("~/my-dui-packages")
VALID_CATEGORIES
module-attribute
¶
VALID_CATEGORIES = frozenset({'media', 'productivity', 'system', 'gaming', 'social', 'development', 'utilities', 'streaming', 'home-automation', 'communication'})
Controlled vocabulary for the category manifest field.
SpinnerAnimator ¶
Drive frame-by-frame spinner animation on an asyncio event loop.
The animator cycles through pre-rendered frames at a fixed interval, pushing each frame to the device via the provided push_fn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
list[bytes]
|
List of encoded image bytes (one per frame). |
required |
interval_ms
|
int
|
Milliseconds between frame updates. |
required |
push_fn
|
PushFn
|
Async callable |
required |
Source code in src/deux/dui/animator.py
start
async
¶
Begin the animation loop.
If already running, this is a no-op.
stop
async
¶
Stop the animation loop.
Cancels the running task and waits for it to finish.
Source code in src/deux/dui/animator.py
DuiCard ¶
Bases: BindingMixin, Card
A touchscreen card whose layout and events are defined by a .dui package.
Instead of writing a Python class with imperative Pillow rendering, you describe the UI in an SVG layout and a YAML manifest. The card loads the package, lets you set binding values, and renders the SVG into a PIL Image for the Stream Deck touchscreen.
Examples:
::
from deux import DuiCard
# Resolve by name from the DUI repository
card = DuiCard("AudioCard")
card.set("artist", "Ash Walker")
@card.on("toggle_play_pause")
async def handle():
...
You can also pass a pre-loaded :class:~deux.dui.schema.PackageSpec
directly::
from deux.dui import load_package, DuiCard
spec = load_package("./AudioCard.dui")
card = DuiCard(spec)
The card index is assigned automatically when you install the card
on a screen with :meth:~deux.ui.screen.Screen.set_card.
Source code in src/deux/dui/card.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 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 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
__init__ ¶
Construct a DUI-backed touchscreen card.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
PackageSpec or str
|
Either a pre-validated
:class: |
required |
Raises:
| Type | Description |
|---|---|
PackageError
|
If spec is a string and no matching package is found in any registered search path. |
Notes
Construction performs no rendering and no device I/O. The
underlying :class:~deux.dui.svg_renderer.SvgRenderer and
:class:~deux.dui.events.EventMap are built eagerly from
spec; binding values, push callbacks, and background tiles
are configured later via the corresponding setters.
Source code in src/deux/dui/card.py
set_push_fn ¶
Set the async function used to push animation frames to the device.
This must be called before spinner animations can play.
Typically set by :class:~deux.runtime.deck.Deck.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
push_fn
|
PushFn
|
Async callable |
required |
panel_size
|
tuple[int, int]
|
|
required |
Source code in src/deux/dui/card.py
set_bg_tile ¶
Set the background tile for compositing spinner frames.
When a touchstrip background SVG is active, the corresponding pre-sliced tile (PNG bytes) is passed here so that spinner animations can composite each frame onto the background.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
bytes | None
|
PNG-encoded background tile bytes, or |
required |
Source code in src/deux/dui/card.py
set_background_layer ¶
set_background_layer(bg_root: Element, card_index: int, panel_width: int, panel_height: int) -> None
Set a background SVG layer underneath the card content.
The background SVG's viewBox is sliced to the region for
card_index and composed as a layer beneath the card's own
SVG. The composed tree is cached so subsequent renders only
need to apply bindings and rasterise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bg_root
|
Element
|
The full-width background |
required |
card_index
|
int
|
Zero-based panel index. |
required |
panel_width
|
int
|
Width of a single panel in pixels. |
required |
panel_height
|
int
|
Height of a single panel in pixels. |
required |
Source code in src/deux/dui/card.py
clear_background_layer ¶
Remove the background layer and revert to the card's own SVG.
render_bytes ¶
render_bytes(*, panel_width: int, panel_height: int, image_format: str = 'JPEG', background: str = 'black') -> bytes
Render the card directly to encoded image bytes.
Uses the SVG-native pipeline: background compositing happens at the SVG level (if a background layer is set), dimensions are set for vector scaling, and the output is rasterised directly to the requested format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
panel_width
|
int
|
Target panel width in pixels. |
required |
panel_height
|
int
|
Target panel height in pixels. |
required |
image_format
|
str
|
Image encoding format ( |
"JPEG"
|
background
|
str
|
Fallback background colour (used when no background SVG layer is set). |
"black"
|
Returns:
| Type | Description |
|---|---|
bytes
|
Encoded image bytes ready to send to the device. |
Source code in src/deux/dui/card.py
render_panel_bytes ¶
render_panel_bytes(*, metrics: RenderMetrics, card_index: int, bg_tile: bytes | None, background: str = 'black', image_format: str = 'JPEG') -> bytes
Render the card to encoded image bytes using the SVG-native pipeline.
Overrides the base :meth:Card.render_panel_bytes to use
SVG-level background compositing and direct rasterisation,
avoiding the legacy Pillow compositing path entirely.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
RenderMetrics
|
Device metrics (panel dimensions, etc.). |
required |
card_index
|
int
|
The zero-based position of this card on the touch strip. |
required |
bg_tile
|
Image or None
|
Cropped background tile for this card's panel, or |
required |
background
|
str
|
Fallback background colour. |
"black"
|
image_format
|
str
|
Image encoding format ( |
"JPEG"
|
Returns:
| Type | Description |
|---|---|
bytes
|
Encoded image bytes ready to send to the device. |
Source code in src/deux/dui/card.py
set ¶
Set a binding value. Marks the card dirty if changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Binding name as defined in the manifest. |
required |
value
|
Any
|
New value (type depends on binding kind). |
required |
Returns:
| Type | Description |
|---|---|
DuiCard
|
self, for method chaining. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
Source code in src/deux/dui/card.py
set_many ¶
get ¶
Get the current value of a binding.
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
collect_icon_names ¶
Return all Iconify icon identifiers needed by this card.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of |
Source code in src/deux/dui/card.py
set_rendering_context ¶
Set the explicit rendering context for this card.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
RenderingContext or None
|
The rendering context to apply, or |
required |
Source code in src/deux/dui/card.py
set_range ¶
Set a range/slider binding using a domain-scale value.
Normalises value from [min_val, max_val] to [0.0, 1.0]
and delegates to :meth:set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Binding name (must be a |
required |
value
|
float
|
Value in domain units (e.g. 0–100 for a percentage). |
required |
min_val
|
float
|
Lower bound of the domain range. |
0
|
max_val
|
float
|
Upper bound of the domain range. |
1
|
Returns:
| Type | Description |
|---|---|
DuiCard
|
self, for method chaining. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
ValueError
|
If min_val equals max_val. |
Source code in src/deux/dui/card.py
adjust_range ¶
Adjust a range/slider binding by delta domain-scale units.
Reads the current normalised value, denormalises it, adds delta,
clamps, re-normalises, and calls :meth:set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Binding name (must be a |
required |
delta
|
float
|
Amount to add in domain units (negative to decrease). |
required |
min_val
|
float
|
Lower bound of the domain range. |
0
|
max_val
|
float
|
Upper bound of the domain range. |
1
|
Returns:
| Type | Description |
|---|---|
float
|
The new value in domain units (clamped to
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
ValueError
|
If min_val equals max_val. |
Source code in src/deux/dui/card.py
get_range ¶
Get a range/slider binding denormalised to domain units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Binding name. |
required |
min_val
|
float
|
Lower bound of the domain range. |
0
|
max_val
|
float
|
Upper bound of the domain range. |
1
|
Returns:
| Type | Description |
|---|---|
float
|
The current value in domain units. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
ValueError
|
If min_val equals max_val. |
Source code in src/deux/dui/card.py
render ¶
Render the SVG layout with current bindings to a PIL Image.
Returns:
| Type | Description |
|---|---|
Image
|
A panel-sized RGB :class: |
Source code in src/deux/dui/card.py
prepare_assets
async
¶
handle_encoder_turn ¶
Route encoder turn through the event map.
handle_encoder_press ¶
handle_encoder_release ¶
dispatch_touch
async
¶
Dispatch touch events through regions and the event map.
Falls back to the base Card touch handlers (on_tap, etc.) if the event map doesn't handle the event.
Source code in src/deux/dui/card.py
start_busy
async
¶
Enter the busy state and start the spinner animation.
While busy, the card suppresses further start_busy() calls.
The spinner keeps running until :meth:finish_busy is called.
If no spinner is configured in the manifest the busy flag is still set (suppressing duplicate calls) but no animation plays.
Source code in src/deux/dui/card.py
finish_busy
async
¶
Stop the spinner and exit the busy state.
Call this from your application code when the asynchronous work is truly complete (e.g. after receiving a state update from an external system).
If the card is not currently busy this is a no-op.
Source code in src/deux/dui/card.py
EventMap ¶
Map physical hardware events to named semantic events.
Handles simple mappings (encoder_press → semantic name) as well as compound gestures:
encoder_press_release: fires only if the press duration is withinmax_duration_ms.encoder_hold/key_hold: starts a timer on press and fires the handler afterhold_mswhile the key/encoder is still held. Suppresses anypress_releaseorreleaseevent for that press–release cycle.encoder_turn: fires turn events only while the encoder is not pressed. Turning while pressed never falls through to this mapping. Immediately after releasing a press cycle that included at least one turn,encoder_turnis suppressed forrelease_turn_grace_msto debounce the spurious tick a finger often produces while lifting off the dial.encoder_press_turn: fires turn events only while the encoder is held down. When declared with a direction filter, mismatching turns while pressed are silent — there is no fallback toencoder_turn. Any turn while pressed cancels a pendingencoder_holdregardless of whether a handler fires.- Direction filtering:
encoder_turnwithdirection: leftonly fires for counter-clockwise turns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
tuple[EventMapping, ...]
|
Event mappings from the package manifest. |
required |
regions
|
tuple[Region, ...]
|
Touch regions from the package manifest. |
()
|
release_turn_grace_ms
|
int
|
Suppression window (in milliseconds) applied to plain
|
DEFAULT_RELEASE_TURN_GRACE_MS
|
Source code in src/deux/dui/event_map.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 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 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
on ¶
Register a handler for a named semantic event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
The semantic event name (as defined in the manifest). |
required |
handler
|
AsyncHandler
|
An async callable to invoke when the event fires.
For accumulated events the handler signature must accept
a single |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If event_name is not defined in the manifest. |
Source code in src/deux/dui/event_map.py
cancel_accumulators
async
¶
handle_encoder_turn ¶
Match an encoder turn to a semantic event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
int
|
Positive for clockwise, negative for counter-clockwise. |
required |
Returns:
| Type | Description |
|---|---|
AsyncHandler or None
|
The matched handler, or |
Source code in src/deux/dui/event_map.py
handle_encoder_press ¶
Match an encoder press to semantic events.
Records the press timestamp for gesture detection and starts
a hold timer if an encoder_hold mapping exists.
Returns:
| Type | Description |
|---|---|
list[AsyncHandler]
|
A list of matched handlers (may be empty). |
Source code in src/deux/dui/event_map.py
handle_encoder_release ¶
Match an encoder release to semantic events.
Cancels any running hold timer. The simple encoder_release
event always fires regardless of whether a hold fired.
encoder_press_release is suppressed when a hold already
fired for this press–release cycle (since the interaction was
a hold, not a press-release gesture).
If at least one turn occurred during the press cycle, opens a
release_turn_grace_ms window during which subsequent plain
encoder_turn events are ignored.
Returns:
| Type | Description |
|---|---|
list[AsyncHandler]
|
A list of matched handlers (may be empty). |
Source code in src/deux/dui/event_map.py
handle_key_press ¶
Match a key press to semantic events.
Records the press timestamp and starts a hold timer if a
key_hold mapping exists.
Returns:
| Type | Description |
|---|---|
list[AsyncHandler]
|
A list of matched handlers (may be empty). |
Source code in src/deux/dui/event_map.py
handle_key_release ¶
Match a key release to semantic events.
Cancels any running hold timer. The simple key_release
event always fires regardless of whether a hold fired.
key_press_release is suppressed when a hold already
fired for this press–release cycle (since the interaction was
a hold, not a press-release gesture).
Returns:
| Type | Description |
|---|---|
list[AsyncHandler]
|
A list of matched handlers (may be empty). |
Source code in src/deux/dui/event_map.py
handle_touch ¶
Match a touch event to a semantic event via regions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_type
|
EventType
|
The touch event type (TOUCH_SHORT or TOUCH_LONG). |
required |
x
|
int
|
Touch x coordinate (relative to card origin). |
required |
y
|
int
|
Touch y coordinate (relative to card origin). |
required |
Returns:
| Type | Description |
|---|---|
AsyncHandler or None
|
The matched handler, or |
Source code in src/deux/dui/event_map.py
IconifyError ¶
DuiKey ¶
Bases: BindingMixin, KeySlot
A physical key whose layout and events are defined by a .dui package.
DuiKey extends :class:~deux.ui.controls.key_slot.KeySlot
so that it is accepted wherever a KeySlot is expected. It
replaces the icon + label rendering with SVG-based rendering from
a .dui package.
Examples:
::
from deux import DuiKey
# Resolve by name from the DUI repository
key = DuiKey("IconKey")
key.set("label", "Shutdown")
@key.on("activate")
async def handle():
...
You can also pass a pre-loaded :class:~deux.dui.schema.PackageSpec
directly::
from deux.dui import load_package, DuiKey
spec = load_package("./PowerKey.dui")
key = DuiKey(spec)
The key index is assigned automatically when you install the key
on a screen with :meth:~deux.ui.screen.Screen.set_key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
PackageSpec or str
|
A validated :class: |
required |
Source code in src/deux/dui/key.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 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 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
set_push_fn ¶
Set the async function used to push animation frames to the device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
push_fn
|
PushFn
|
Async callable |
required |
key_size
|
tuple[int, int]
|
|
required |
Source code in src/deux/dui/key.py
set ¶
Set a binding value. Marks the key dirty if changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Binding name as defined in the manifest. |
required |
value
|
Any
|
New value (type depends on binding kind). |
required |
Returns:
| Type | Description |
|---|---|
DuiKey
|
self, for method chaining. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
Source code in src/deux/dui/key.py
set_many ¶
get ¶
Get the current value of a binding.
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
collect_icon_names ¶
Return all Iconify icon identifiers needed by this key.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of |
Source code in src/deux/dui/key.py
set_rendering_context ¶
Set the explicit rendering context for this key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
RenderingContext or None
|
The rendering context to apply, or |
required |
Source code in src/deux/dui/key.py
set_range ¶
Set a range/slider binding using a domain-scale value.
Normalises value from [min_val, max_val] to [0.0, 1.0]
and delegates to :meth:set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Binding name (must be a |
required |
value
|
float
|
Value in domain units (e.g. 0–100 for a percentage). |
required |
min_val
|
float
|
Lower bound of the domain range. |
0
|
max_val
|
float
|
Upper bound of the domain range. |
1
|
Returns:
| Type | Description |
|---|---|
DuiKey
|
self, for method chaining. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
ValueError
|
If min_val equals max_val. |
Source code in src/deux/dui/key.py
adjust_range ¶
Adjust a range/slider binding by delta domain-scale units.
Reads the current normalised value, denormalises it, adds delta,
clamps, re-normalises, and calls :meth:set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Binding name (must be a |
required |
delta
|
float
|
Amount to add in domain units (negative to decrease). |
required |
min_val
|
float
|
Lower bound of the domain range. |
0
|
max_val
|
float
|
Upper bound of the domain range. |
1
|
Returns:
| Type | Description |
|---|---|
float
|
The new value in domain units (clamped to
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
ValueError
|
If min_val equals max_val. |
Source code in src/deux/dui/key.py
get_range ¶
Get a range/slider binding denormalised to domain units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Binding name. |
required |
min_val
|
float
|
Lower bound of the domain range. |
0
|
max_val
|
float
|
Upper bound of the domain range. |
1
|
Returns:
| Type | Description |
|---|---|
float
|
The current value in domain units. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
ValueError
|
If min_val equals max_val. |
Source code in src/deux/dui/key.py
render_image ¶
Render the SVG layout to image bytes for the key.
Uses the SVG-native pipeline: the SVG is rasterised at
key_size directly (vector scaling via viewBox) with a
black background injected at the SVG level. No Pillow resize
or compositing is needed.
Falls back to the legacy Pillow path for BMP format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_size
|
tuple[int, int]
|
Target key dimensions |
required |
image_format
|
str
|
Image encoding format ( |
'JPEG'
|
Returns:
| Type | Description |
|---|---|
bytes
|
Encoded image bytes. |
Source code in src/deux/dui/key.py
start_busy
async
¶
Enter the busy state and start the spinner animation.
While busy, the key suppresses further start_busy() calls.
The spinner keeps running until :meth:finish_busy is called.
If no spinner is configured in the manifest the busy flag is still set (suppressing duplicate calls) but no animation plays.
Source code in src/deux/dui/key.py
finish_busy
async
¶
Stop the spinner and exit the busy state.
Call this from your application code when the asynchronous work is truly complete (e.g. after receiving a state update from an external system).
If the key is not currently busy this is a no-op.
Source code in src/deux/dui/key.py
PackageError ¶
DuiRepository ¶
Registry of .dui package search paths with in-memory caching.
Directories are searched in priority order — the most recently added path wins when two directories contain a package with the same name. The bundled packages directory is always present as the lowest-priority source and cannot be removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_bundled
|
bool
|
Whether to include the bundled packages directory. Set to
|
True
|
Examples:
::
repo = DuiRepository()
repo.add_path("/home/user/my-packages")
spec = repo.resolve("IconKey")
Source code in src/deux/dui/repository.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
add_path ¶
Register a directory as a DUI package source.
The directory is inserted at the highest priority position.
If it is already registered it is moved to the top. The
in-memory cache is cleared so that subsequent :meth:resolve
calls pick up any overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Directory containing |
required |
Raises:
| Type | Description |
|---|---|
PackageError
|
If path does not exist or is not a directory. |
Source code in src/deux/dui/repository.py
remove_path ¶
Unregister a directory. Clears the cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Previously registered directory. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If path is not currently registered. |
Source code in src/deux/dui/repository.py
list_paths ¶
Return registered search paths in priority order (highest first).
The bundled directory is included at the end when
include_bundled is True.
Returns:
| Type | Description |
|---|---|
list[Path]
|
Ordered list of directories. |
Source code in src/deux/dui/repository.py
resolve ¶
Look up a package by name and return a cached spec.
Search order: user paths (most recently added first), then
bundled packages. The result is cached so that repeated calls
with the same name return the identical :class:PackageSpec
object without re-reading the filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Package name without the |
required |
Returns:
| Type | Description |
|---|---|
PackageSpec
|
A validated, frozen package specification. |
Raises:
| Type | Description |
|---|---|
PackageError
|
If no package with that name exists in any registered path. |
Source code in src/deux/dui/repository.py
clear_cache ¶
Drop all cached :class:PackageSpec objects.
Subsequent :meth:resolve calls will re-read packages from
disk.
Source code in src/deux/dui/repository.py
invalidate ¶
Remove a single package from the cache.
Use this after editing a .dui package on disk to force
:meth:resolve to reload it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Package name to invalidate. |
required |
Source code in src/deux/dui/repository.py
list_packages ¶
List all package names visible across all search paths.
Packages are returned in alphabetical order. If the same name exists in multiple paths only one entry is returned.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted package names (without the |
Source code in src/deux/dui/repository.py
BindingType ¶
Bases: Enum
Supported binding types for SVG node manipulation.
Source code in src/deux/dui/schema.py
ColorBinding
dataclass
¶
Bind a colour value to an SVG element's fill, stroke, or color.
Source code in src/deux/dui/schema.py
CssClassBinding
dataclass
¶
Bind a CSS class string to an SVG element's class attribute.
The binding replaces the entire class attribute value on the
target node. Setting an empty string removes the attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
str
|
ID of the SVG element whose |
required |
default
|
str
|
Initial class value applied when no explicit value has been set. |
''
|
Source code in src/deux/dui/schema.py
EventMapping
dataclass
¶
Map a physical input to a named semantic event.
Source code in src/deux/dui/schema.py
IconifyBinding
dataclass
¶
Load an Iconify icon by name and embed it into an SVG <g> element.
The icon name follows the Iconify convention <prefix>:<name> (for
example line-md:home). Icons are fetched from
https://api.iconify.design on first use and cached in-process.
The resolved icon SVG is inserted as children of the target <g>
node, scaled to a size × size square. Setting the binding
value to None or an empty string removes any previously embedded
icon from the node.
Source code in src/deux/dui/schema.py
ImageBinding
dataclass
¶
Bind a PIL Image to an
Source code in src/deux/dui/schema.py
ImageFit ¶
OverflowMode ¶
PackageSpec
dataclass
¶
Fully validated, immutable representation of a loaded .dui package.
Source code in src/deux/dui/schema.py
PackageType ¶
RangeBinding
dataclass
¶
Scale an SVG element's width or height proportional to a 0–1 value.
Source code in src/deux/dui/schema.py
RangeDirection ¶
Region
dataclass
¶
A touchscreen hit-test region for touch events.
Source code in src/deux/dui/schema.py
RotateTransform
dataclass
¶
Rotate an SVG element between two angles proportional to a 0–1 value.
The element is rotated by interpolating linearly between from_angle and to_angle based on the binding's current value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_angle
|
float
|
Rotation angle (degrees) when the value is 0.0. |
0.0
|
to_angle
|
float
|
Rotation angle (degrees) when the value is 1.0. |
360.0
|
origin
|
str
|
Rotation origin. |
'center'
|
Source code in src/deux/dui/schema.py
SliderBinding
dataclass
¶
Translate an SVG element between two positions proportional to a 0–1 value.
Source code in src/deux/dui/schema.py
SpinnerSpec
dataclass
¶
Configuration for a spinner animation.
The spinner is started and stopped explicitly by the application
via :meth:~deux.dui.card.DuiCard.start_busy /
:meth:~deux.dui.card.DuiCard.finish_busy (and the equivalent
methods on :class:~deux.dui.key.DuiKey). It provides visual
feedback by cycling pre-rendered animation frames on the key or
card panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
SpinnerType
|
Animation strategy: |
required |
node
|
str | None
|
SVG element ID to animate (required for |
None
|
frames
|
int
|
Number of frames per animation cycle. |
DEFAULT_SPINNER_FRAMES
|
interval_ms
|
int
|
Milliseconds between frames. |
DEFAULT_SPINNER_INTERVAL_MS
|
background_node
|
str | None
|
Optional SVG element ID shown behind the spinner during busy
state. The node is made visible when the spinner is active and
hidden at rest, but it is not animated (no rotation, pulse,
or opacity changes are applied to it). Ignored for |
None
|
Source code in src/deux/dui/schema.py
SpinnerType ¶
TextBinding
dataclass
¶
Bind a value to a <text> SVG element's content.
When wrap is True the renderer word-wraps the text into
multiple <tspan> lines that each fit within max_width pixels.
Font metrics are auto-detected from the SVG <text> element.
If the wrapped text exceeds max_height, the last visible line is
truncated according to overflow.
Source code in src/deux/dui/schema.py
ToggleBinding
dataclass
¶
Switch between two SVG elements based on a boolean value.
When the value is truthy, node_on is visible and node_off
is hidden. When falsy, the opposite applies.
Source code in src/deux/dui/schema.py
TransformBinding
dataclass
¶
Apply one or more SVG transforms to a node proportional to a 0–1 value.
Each entry in transforms produces an SVG transform attribute
fragment; multiple transforms are composed (space-separated) in order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
str
|
ID of the SVG element to transform. |
required |
default
|
float
|
Initial normalised value (0.0–1.0). |
0.0
|
transforms
|
tuple[TransformSpec, ...]
|
Ordered sequence of transform specifications applied to the node. |
()
|
Source code in src/deux/dui/schema.py
TransformKind ¶
VisibilityBinding
dataclass
¶
Toggle the display attribute of an SVG element.
Source code in src/deux/dui/schema.py
SpinnerFrames ¶
Pre-renders spinner animation frames from an SVG template.
Frames are generated lazily on first access and cached for the lifetime of the instance.
When a bg_tile is provided, each frame is composited onto the background tile before encoding so that transparent regions of the spinner reveal the touchstrip background underneath.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
PackageSpec
|
The package specification containing the SVG source and spinner config. |
required |
width
|
int
|
Target image width in pixels. |
required |
height
|
int
|
Target image height in pixels. |
required |
image_format
|
str
|
Encoding format ( |
'JPEG'
|
rendered_svg
|
str | None
|
Optional pre-rendered SVG source with bindings already applied. |
None
|
bg_tile
|
bytes | Image | None
|
Optional RGB background tile to composite frames onto. |
None
|
Source code in src/deux/dui/spinner.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 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 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
SvgRenderer ¶
Render a .dui SVG layout with live data bindings.
The renderer holds a parsed copy of the SVG template. Each call
to :meth:render clones the template, applies current binding
values, inlines image assets, and rasterises to a PIL Image via
CairoSVG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
PackageSpec
|
The validated package specification. |
required |
Source code in src/deux/dui/svg_renderer.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 | |
rendering_context
property
¶
The explicit rendering context, or None for global defaults.
Returns:
| Type | Description |
|---|---|
RenderingContext or None
|
The context set via :meth: |
set ¶
Set a binding value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Binding name as defined in the manifest. |
required |
value
|
Any
|
The new value. Type depends on the binding:
text → |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
Source code in src/deux/dui/svg_renderer.py
set_many ¶
Set multiple binding values at once.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/deux/dui/svg_renderer.py
get ¶
Get the current value of a binding.
Raises:
| Type | Description |
|---|---|
KeyError
|
If name is not a known binding. |
Source code in src/deux/dui/svg_renderer.py
set_target_size ¶
Set the target rasterisation dimensions.
When set, the SVG width and height attributes are
overridden to these values before rasterisation, enabling
vector-level scaling from the viewBox design canvas to the
device's native pixel dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Target width in pixels. |
required |
height
|
int
|
Target height in pixels. |
required |
Source code in src/deux/dui/svg_renderer.py
set_rendering_context ¶
Set an explicit rendering context for this renderer.
When set, the context's stylesheet and backend override the
module-level globals during rasterisation. Pass None to
revert to the global defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
RenderingContext or None
|
The rendering context to use, or |
required |
Source code in src/deux/dui/svg_renderer.py
collect_icon_names ¶
Return all Iconify icon identifiers needed by this renderer.
Scans bindings for :class:IconifyBinding defaults and current
values, as well as :class:ListBinding items prefixed with
icon:. The result includes both default and currently-bound
icon names so that a caller can prefetch everything before the
first render.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of |
Source code in src/deux/dui/svg_renderer.py
set_base_layer ¶
Set a background SVG layer underneath the card content.
The background SVG's viewBox is sliced to the region
corresponding to card_index, then composed as a layer beneath
the card's own SVG template. The composed tree replaces
_base_root so that subsequent :meth:render calls produce
a single SVG document with both layers.
Call this when the background SVG or the card's slot assignment changes — not on every render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bg_root
|
Element
|
The full-width background |
required |
card_index
|
int
|
Zero-based panel index. |
required |
panel_width
|
int
|
Width of a single panel in pixels. |
required |
panel_height
|
int
|
Height of a single panel in pixels. |
required |
Source code in src/deux/dui/svg_renderer.py
clear_base_layer ¶
Remove the background layer and revert to the original SVG template.
After calling this, :meth:render will produce output from the
card's own SVG only, without any background layer.
Source code in src/deux/dui/svg_renderer.py
render ¶
Rasterise the SVG with current binding values to a PIL Image.
Returns:
| Type | Description |
|---|---|
Image
|
An RGBA :class: |
Source code in src/deux/dui/svg_renderer.py
render_bytes ¶
render_bytes(*, output_format: str = 'jpeg', background: str | None = None, quality: int = 90) -> bytes
Rasterise the SVG directly to encoded image bytes.
This is the SVG-native pipeline entry point. It applies bindings, optionally injects a background colour, sets the target dimensions, and rasterises to the requested format in a single pass — no intermediate PIL Image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_format
|
str
|
Target image format: |
"jpeg"
|
background
|
str or None
|
CSS colour for a solid background rect injected under all
content. When |
None
|
quality
|
int
|
JPEG quality (ignored for other formats). |
90
|
Returns:
| Type | Description |
|---|---|
bytes
|
Encoded image bytes ready to send to the device. |
Source code in src/deux/dui/svg_renderer.py
render_svg ¶
Return the SVG source with current bindings applied (not rasterised).
This is used by the spinner system to generate frames that reflect the current binding state rather than the raw template.
Returns:
| Type | Description |
|---|---|
str
|
SVG markup as a Unicode string. |
Source code in src/deux/dui/svg_renderer.py
fetch_icon ¶
Fetch an Iconify icon by prefix:icon name.
The lookup order is: in-memory cache, disk cache, network. Successful fetches are stored in both caches. Negative lookups (404 / network failure) are cached in memory only so a restart retries previously-failed icons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Icon identifier in |
required |
Returns:
| Type | Description |
|---|---|
str
|
The raw SVG source string as served by the Iconify API. |
Raises:
| Type | Description |
|---|---|
IconifyError
|
If the name is malformed, the icon does not exist, or the network request fails. |
SSRFError
|
If the constructed API URL resolves to a private address and private URLs have not been explicitly allowed. |
Source code in src/deux/dui/iconify.py
prefetch_icons
async
¶
Fetch multiple Iconify icons concurrently, warming the cache.
Each icon is fetched in a separate thread via
:func:asyncio.to_thread, so network I/O runs in parallel without
blocking the event loop. Icons that are already cached (in memory
or on disk) return immediately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
Iterable[str]
|
Icon identifiers in |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str | None]
|
Mapping of icon name to SVG string on success, or |
Source code in src/deux/dui/iconify.py
clear_iconify_cache ¶
Drop all cached Iconify icons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
persistent
|
bool
|
When |
False
|
Source code in src/deux/dui/iconify.py
load_all_packages ¶
Load all .dui packages from a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str | Path
|
Path to scan for |
required |
Returns:
| Type | Description |
|---|---|
dict[str, PackageSpec]
|
A dict mapping package names to their specs. |
Raises:
| Type | Description |
|---|---|
PackageError
|
If any package fails validation. |
Source code in src/deux/dui/loader.py
load_package ¶
Load a .dui package directory into a validated PackageSpec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the |
required |
strict
|
bool
|
When |
True
|
Returns:
| Type | Description |
|---|---|
PackageSpec
|
A frozen :class: |
Raises:
| Type | Description |
|---|---|
PackageError
|
If the package is invalid or incomplete. |
Source code in src/deux/dui/loader.py
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 | |
add_dui_path ¶
Register a directory as a DUI package source.
The directory is inserted at the highest priority position. Packages in this directory will override bundled packages and packages from previously added directories when names collide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Directory containing |
required |
Raises:
| Type | Description |
|---|---|
PackageError
|
If path does not exist or is not a directory. |
Examples:
::
import deux
deux.add_dui_path("/home/user/my-packages")
card = deux.DuiCard("MyCustomCard")
Source code in src/deux/dui/repository.py
clear_dui_cache ¶
Drop all cached package specs from the default repository.
Subsequent DuiCard("name") / DuiKey("name") calls will
re-read packages from disk.
list_dui_packages ¶
List all DUI package names visible across all search paths.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted package names (without the |
Source code in src/deux/dui/repository.py
remove_dui_path ¶
Unregister a previously added DUI package directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Previously registered directory. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If path is not currently registered. |
Source code in src/deux/dui/repository.py
resolve_dui ¶
Look up a DUI package by name and return its spec.
This is the function called internally when DuiCard("name")
or DuiKey("name") receive a string argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Package name without the |
required |
Returns:
| Type | Description |
|---|---|
PackageSpec
|
A validated, frozen package specification. |
Raises:
| Type | Description |
|---|---|
PackageError
|
If no package with that name exists in any registered path. |