Presenter¶
Base classes¶
Bases: ABC
Base presenter class.
Does not inherit PPresenter, whose
read-only properties would shadow the instance attributes set here.
Instances satisfy the protocol by shape, like any other presenter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Identity key of the presenter, positional-only. |
required |
devices
|
Mapping[str, Device]
|
The session's devices. |
required |
kwargs
|
Any
|
Additional keyword arguments for presenter subclasses. |
{}
|
Source code in src/redsun/presenter/_base.py
Bases: Protocol
Protocol of a presenter component.
Members are read-only properties, so instance attributes, class attributes
or properties satisfy them, and devices may be any Mapping, such
as a dict.
Notes
A presenter reaches the virtual container by implementing
IsProvider or
IsInjectable.
Checked with isinstance on the built instance, since attributes
assigned in __init__ do not exist on the class.
Source code in src/redsun/presenter/_base.py
Plan specification¶
Describe a plan's signature as a PlanSpec.
create_plan_spec inspects a bluesky MsgGenerator function and returns
a PlanSpec describing its parameters, from which a view builds a parameter
form.
_ANN_HANDLER_MAP lists (predicate, handler) pairs turning annotations into
ParamDescription fields (choices, device_proto, multiselect).
ParamKind
¶
Bases: IntEnum
inspect._ParameterKind as a public IntEnum.
Usable in match/case without importing private standard library
names.
Source code in src/redsun/presenter/plan_spec.py
UnresolvableAnnotationError
¶
Bases: TypeError
Raised when a plan parameter's annotation maps to no widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan_name
|
str
|
Name of the plan. |
required |
param_name
|
str
|
Name of the parameter. |
required |
annotation
|
Any
|
The unresolvable annotation. |
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, Device],
) -> 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, a generator function annotated to
return a |
required |
devices
|
Mapping[str, Device]
|
The session's devices, giving |
required |
Returns:
| Type | Description |
|---|---|
PlanSpec
|
The plan specification. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If plan is not a generator function or its return type is not a
|
UnresolvableAnnotationError
|
If an annotation names something missing at runtime, or no view can build a control for it. |
RuntimeError
|
On an unexpected |
Source code in src/redsun/presenter/plan_spec.py
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 | |
collect_arguments
¶
collect_arguments(
spec: PlanSpec, values: Mapping[str, Any]
) -> tuple[tuple[Any, ...], dict[str, Any]]
Build the (args, kwargs) calling a plan, from its PlanSpec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
PlanSpec
|
The plan specification. |
required |
values
|
Mapping[str, Any]
|
Resolved values by parameter name. |
required |
Returns:
| Type | Description |
|---|---|
tuple[tuple[Any, ...], dict[str, Any]]
|
Positional and keyword arguments for the plan. |
Notes
POSITIONAL_ONLYandPOSITIONAL_OR_KEYWORD->args, in declaration order.KEYWORD_ONLY->kwargs.VAR_POSITIONAL(*args) -> sequence expanded intoargs.VAR_KEYWORD(**kwargs) -> mapping 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, Device],
) -> dict[str, Any]
Turn parameter values from the interface into values a plan takes.
- Action parameters are filled from the spec when the interface lacks them.
- Device parameters: names become
OADeviceinstances fromdevices. - Everything else passes unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
PlanSpec
|
The plan specification. |
required |
param_values
|
Mapping[str, Any]
|
Parameter values from the interface. |
required |
devices
|
Mapping[str, Device]
|
The session's devices. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Resolved arguments for |
Source code in src/redsun/presenter/plan_spec.py
ParamDescription
dataclass
¶
Description of one plan parameter.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the parameter in the plan signature. |
kind |
ParamKind
|
Kind of the parameter, as |
annotation |
Any
|
Type annotation, without |
default |
Any
|
Default value of the parameter, or |
choices |
list[str] | None
|
Labels of selectable values, for |
multiselect |
bool
|
Whether several values can be selected, as for |
hidden |
bool
|
Whether the parameter is hidden from the interface, as for metadata only. |
actions |
Sequence[Action] | Action | None
|
Actions taken from the parameter's default value, if any. |
device_proto |
type[Any] | None
|
Device class or runtime-checkable protocol of a device parameter, used to look devices up when resolving arguments. |
Source code in src/redsun/presenter/plan_spec.py
PlanSpec
dataclass
¶
Description of a plan's signature and type hints.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Plan name, the callable's |
docs |
str
|
Plan docstring, or a default message without one. |
parameters |
list[ParamDescription]
|
One description per parameter, in order. |
togglable |
bool
|
Whether the plan loops until stopped with a toggle button. |
pausable |
bool
|
Whether a running togglable plan can be paused and resumed. |
Source code in src/redsun/presenter/plan_spec.py
Utilities¶
Predicates and helpers inspecting plan parameters.
create_plan_spec uses them to classify annotations, and resolve_arguments
to turn device names into Device instances.
get_choice_list
¶
get_choice_list(
devices: Mapping[str, Device],
proto: type[D],
choices: Sequence[str],
) -> list[D]
Return the devices named in choices that are instances of proto.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
devices
|
Mapping[str, Device]
|
Devices by name. |
required |
proto
|
type[D]
|
Class checked with |
required |
choices
|
Sequence[str]
|
Names of the devices to consider. |
required |
Returns:
| Type | Description |
|---|---|
list[D]
|
The matching devices. |
Source code in src/redsun/presenter/utils.py
isdevice
¶
issequence
¶
Return True if ann is a Sequence[...] generic alias.
Notes
str and bytes are sequences, but not generic aliases
(get_origin(str) is None), so they are excluded.