Presenter¶
Base classes¶
Bases: PPresenter, ABC
Presenter base class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Identity key of the presenter. Passed as positional-only argument. |
required |
devices
|
Mapping[str, Device]
|
Reference to the devices used in the presenter. |
required |
kwargs
|
Any
|
Additional keyword arguments for presenter subclasses. |
{}
|
Source code in src/redsun/presenter/_base.py
Bases: Protocol
Presenter protocol class.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Identity key of the presenter. |
devices |
Mapping[str, Device]
|
Reference to the devices used in the presenter. |
Notes
Access to the virtual container is optional and should be acquired
by implementing IsProvider or
IsInjectable.
Source code in src/redsun/presenter/_base.py
Plan specification¶
Plan specification: inspect a plan's signature into a structured PlanSpec.
This module provides create_plan_spec, which inspects a Bluesky
MsgGenerator function and returns a PlanSpec — a structured
description of the plan's parameters that the view layer can use to
automatically generate a parameter form.
The annotation dispatch system is table-driven: _ANN_HANDLER_MAP maps
(predicate, handler) pairs that convert raw type annotations into
ParamDescription fields (choices, device_proto, multiselect).
ParamKind
¶
Bases: IntEnum
Public mirror of inspect._ParameterKind as a stable IntEnum.
Using a dedicated enum keeps the public API stable and allows use in
match/case statements without importing private stdlib symbols.
Source code in src/redsun/presenter/plan_spec.py
UnresolvableAnnotationError
¶
Bases: TypeError
Raised when a plan parameter's annotation cannot be mapped to a widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan_name
|
str
|
Name of the plan that contains the unresolvable parameter. |
required |
param_name
|
str
|
Name of the parameter whose annotation could not be resolved. |
required |
annotation
|
Any
|
The annotation that could not be resolved. |
required |
Source code in src/redsun/presenter/plan_spec.py
create_plan_spec
¶
create_plan_spec(
plan: Callable[..., Generator[Any, Any, Any]],
devices: Mapping[str, PDevice],
) -> PlanSpec
Inspect plan and return a PlanSpec with one ParamDescription per parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan
|
Callable[..., Any]
|
The plan function (or bound method) to inspect.
Must be a generator function whose return annotation is a |
required |
devices
|
Mapping[str, PDevice]
|
Registry of active devices; used to compute |
required |
Returns:
| Type | Description |
|---|---|
PlanSpec
|
Fully populated plan specification. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If plan is not a generator function or its return type is not a
|
RuntimeError
|
If an unexpected |
Source code in src/redsun/presenter/plan_spec.py
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 565 566 567 568 569 570 571 572 573 574 575 576 577 | |
collect_arguments
¶
collect_arguments(
spec: PlanSpec, values: Mapping[str, Any]
) -> tuple[tuple[Any, ...], dict[str, Any]]
Build (args, kwargs) for calling a plan, driven by a PlanSpec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
PlanSpec
|
The plan specification. |
required |
values
|
Mapping[str, Any]
|
Mapping of parameter names to their resolved values. |
required |
Returns:
| Type | Description |
|---|---|
tuple[tuple[Any, ...], dict[str, Any]]
|
Positional and keyword arguments ready to be splatted into the plan. |
Notes
POSITIONAL_ONLYandPOSITIONAL_OR_KEYWORD→ go intoargsin declaration order.KEYWORD_ONLY→ go intokwargs.VAR_POSITIONAL(*args) → sequence is expanded intoargs.VAR_KEYWORD(**kwargs) → mapping is merged intokwargs.
Source code in src/redsun/presenter/plan_spec.py
resolve_arguments
¶
resolve_arguments(
spec: PlanSpec,
param_values: Mapping[str, Any],
devices: Mapping[str, PDevice],
) -> dict[str, Any]
Resolve raw UI parameter values into plan-callable values.
Handles:
* Action parameters — injected from metadata when absent from the UI.
* Model-backed parameters — string labels are resolved to live
PDevice instances via the devices registry.
* Everything else — passed through unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
PlanSpec
|
The plan specification containing parameter metadata. |
required |
param_values
|
Mapping[str, Any]
|
Raw parameter values from the UI. |
required |
devices
|
Mapping[str, PDevice]
|
Active device registry. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Resolved arguments ready for |
Source code in src/redsun/presenter/plan_spec.py
ParamDescription
dataclass
¶
Description of a single plan parameter.
Source code in src/redsun/presenter/plan_spec.py
annotation
instance-attribute
¶
Unwrapped type annotation; Annotated metadata has been stripped.
default
instance-attribute
¶
Default value of the parameter, or inspect.Parameter.empty if none.
choices
class-attribute
instance-attribute
¶
String labels for selectable values; used for Literal and PDevice-backed parameters.
multiselect
class-attribute
instance-attribute
¶
Whether the parameter allows multiple simultaneous selections (e.g. for Sequence[PDevice]).
hidden
class-attribute
instance-attribute
¶
Whether this parameter should be hidden from the UI (e.g. because it's only for metadata, not user input).
actions
class-attribute
instance-attribute
¶
Action metadata extracted from the parameter's default value, if any.
device_proto
class-attribute
instance-attribute
¶
The PDevice protocol/class for model-backed parameters, if any; used for device look-up during argument resolution.
PlanSpec
dataclass
¶
Structured description of a plan's signature and type hints.
Source code in src/redsun/presenter/plan_spec.py
docs
instance-attribute
¶
Plan docstring, or a default message if no docstring is available.
parameters
instance-attribute
¶
Ordered list of parameter descriptions, one per plan parameter.
togglable
class-attribute
instance-attribute
¶
Whether the plan runs as an infinite loop that can be stopped via a toggle button.
pausable
class-attribute
instance-attribute
¶
Whether a running togglable plan can be paused and resumed.
Utilities¶
Utility predicates and helpers for plan parameter inspection.
These functions are used by create_plan_spec to classify parameter
annotations and by resolve_arguments to resolve string device names
into live PDevice instances.
get_choice_list
¶
get_choice_list(
devices: Mapping[str, PDevice],
proto: type[P],
choices: Sequence[str],
) -> list[P]
Filter a device registry to those that match a protocol and are in choices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
devices
|
Mapping[str, PDevice]
|
Mapping of device names to device instances. |
required |
proto
|
type[P]
|
Protocol or class to match against via |
required |
choices
|
Sequence[str]
|
Subset of device names to consider. |
required |
Returns:
| Type | Description |
|---|---|
list[P]
|
Device instances whose name is in choices and that satisfy proto. |
Source code in src/redsun/presenter/utils.py
isdevice
¶
Return True if ann is a class or Protocol that subclasses PDevice.
Operates on type annotations (the class itself), not on instances.
isdevicesequence
¶
Return True if ann is Sequence[T] where T is a PDevice subtype.
issequence
¶
Return True if ann is a Sequence[...] generic alias.
Notes
str and bytes are sequences in the stdlib sense, but their
annotations are not generic aliases (get_origin(str) is None),
so they are naturally excluded.