Binding Mixin¶
binding_mixin ¶
Shared mixin for event-binding helpers used by DuiCard and DuiKey.
BindingMixin ¶
Mixin providing bind, bind_range, bind_many, forward, and helpers.
Subclasses must provide the following attributes/methods:
_events: EventMap_subscriptions: list[tuple[AsyncEvent, AsyncHandler]]is_dirty: bool(property)request_refresh() -> Coroutineset(name, value)set_range(name, value, *, min_val, max_val)set_many(**kwargs)
Source code in src/deux/dui/binding_mixin.py
16 17 18 19 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 | |
on ¶
Decorator to register a handler for a named semantic event.
Examples:
::
@element.on("toggle")
async def handle():
...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
Semantic event name from the manifest. |
required |
Returns:
| Type | Description |
|---|---|
Callable
|
A decorator that registers the handler and returns it unchanged. |
Source code in src/deux/dui/binding_mixin.py
bind_event ¶
Imperatively register a handler for a named semantic event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
Semantic event name from the manifest. |
required |
handler
|
AsyncHandler
|
The async callable to invoke. |
required |
Source code in src/deux/dui/binding_mixin.py
bind ¶
Subscribe to event; on emit, write binding name and refresh.
This fuses three operations that otherwise repeat across every
controller: subscribe to a service AsyncEvent, translate
the emitted value into the binding's domain, and request a
refresh.
Without transform, the binding receives the first positional
argument from the event (args[0]). With transform, the
callable is invoked with all event args/kwargs and its
return value becomes the binding value.
The subscriber lives for the lifetime of the element unless
:meth:detach is called. Bind once during construction or
lifecycle hooks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Binding name as defined in the manifest. |
required |
event
|
AsyncEvent
|
The :class: |
required |
transform
|
Callable[..., Any] | None
|
Optional sync callable that maps event args to the binding
value. If |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
self, for method chaining. |
Source code in src/deux/dui/binding_mixin.py
bind_range ¶
bind_range(name: str, event: AsyncEvent, *, min_val: float = 0, max_val: float = 1, transform: Callable[..., float] | None = None) -> Self
Subscribe to event; on emit, write binding name via :meth:set_range.
Same shape as :meth:bind, but routes through :meth:set_range
so the emitted value can be in domain units (e.g. a 0--100
percentage).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Binding name (must be a |
required |
event
|
AsyncEvent
|
The :class: |
required |
min_val
|
float
|
Lower bound of the domain range. |
0
|
max_val
|
float
|
Upper bound of the domain range. |
1
|
transform
|
Callable[..., float] | None
|
Optional sync callable that maps event args to a numeric
value in domain units. If |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
self, for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If min_val equals max_val. |
Source code in src/deux/dui/binding_mixin.py
bind_many ¶
Subscribe to event; transform args into a dict and :meth:set_many it.
Use this when one event drives several bindings at once -- e.g.
a track_changed event populating artist, title,
album, and state from a single track dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
AsyncEvent
|
The :class: |
required |
transform
|
Callable[..., dict[str, Any]]
|
Required sync callable that maps event args to a dict of binding names to values. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
self, for method chaining. |
Source code in src/deux/dui/binding_mixin.py
detach ¶
Unsubscribe all handlers registered via :meth:bind and friends.
Call this during teardown to prevent leaked handlers accumulating across reconnect cycles.
Source code in src/deux/dui/binding_mixin.py
detach_events ¶
Unsubscribe only handlers bound to specific :class:AsyncEvent instances.
Use this for partial teardown — e.g. removing bindings to a
dying Deck's events while preserving service-owned bindings
that were established in the controller's __init__.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*events
|
Any
|
One or more :class: |
()
|
Source code in src/deux/dui/binding_mixin.py
forward ¶
Register target as the handler for manifest event event_name.
Sugar for the very common shape::
@element.on("toggle")
async def _h() -> None:
await svc.toggle()
which becomes::
element.forward("toggle", svc.toggle)
target may be an async function or any sync callable that returns an awaitable. All positional and keyword arguments emitted by the event are forwarded to target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_name
|
str
|
Semantic event name from the manifest. |
required |
target
|
Callable[..., Any]
|
Async-callable forwarding target. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
self, for method chaining. |