Presenter¶
Base classes¶
Bases: ABC
Presenter base class.
Deliberately does not inherit PPresenter:
the protocol's read-only property descriptors would shadow the instance
attributes assigned here. Instances satisfy the protocol structurally - which is also how any non-ABC presenter is expected to comply.
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.
Members are declared as read-only properties: the framework only
ever reads them, so implementers may satisfy the protocol with plain
instance attributes, class attributes, or properties, and devices
may be any Mapping subtype (e.g. a plain dict). Declaring them
read-write would force implementers to expose settable, invariantly
typed attributes, ruling out property-based classes.
Notes
Access to the virtual container is optional and should be acquired
by implementing IsProvider or
IsInjectable.
Compliance is enforced at build time via isinstance - class-level
checks cannot see attributes assigned in __init__.
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, 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) to inspect.
Must be a generator function whose return annotation is a |
required |
devices
|
Mapping[str, Device]
|
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
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 | |
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->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]
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
OADevice 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, Device]
|
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.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the parameter, as declared in the plan signature. |
kind |
ParamKind
|
Kind of the parameter, mirroring |
annotation |
Any
|
Unwrapped type annotation; |
default |
Any
|
Default value of the parameter, or |
choices |
list[str] | None
|
String labels for selectable values; used for |
multiselect |
bool
|
Whether the parameter allows multiple simultaneous selections (e.g. for |
hidden |
bool
|
Whether this parameter should be hidden from the UI (e.g. because it's only for metadata, not user input). |
actions |
Sequence[Action] | Action | None
|
Action metadata extracted from the parameter's default value, if any. |
device_proto |
type[Any] | None
|
The device class or runtime-checkable protocol for model-backed parameters, if any; used for device look-up during argument resolution. |
Source code in src/redsun/presenter/plan_spec.py
PlanSpec
dataclass
¶
Structured description of a plan's signature and type hints.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Plan name ( |
docs |
str
|
Plan docstring, or a default message if no docstring is available. |
parameters |
list[ParamDescription]
|
Ordered list of parameter descriptions, one per plan parameter. |
togglable |
bool
|
Whether the plan runs as an infinite loop that can be stopped via 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¶
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 Device instances.
get_choice_list
¶
get_choice_list(
devices: Mapping[str, Device],
proto: type[D],
choices: Sequence[str],
) -> list[D]
Filter a device registry to those that match a protocol and are in choices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
devices
|
Mapping[str, Device]
|
Mapping of device names to device instances. |
required |
proto
|
type[D]
|
Class to match against via |
required |
choices
|
Sequence[str]
|
Subset of device names to consider. |
required |
Returns:
| Type | Description |
|---|---|
list[D]
|
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 that subclasses Device.
Operates on type annotations (the class itself), not on instances.
isdevicesequence
¶
Return True if ann is Sequence[T] where T is a Device subtype.
Source code in src/redsun/presenter/utils.py
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.
Source code in src/redsun/presenter/utils.py
Built-ins¶
Application-level control point for the session path provider.
Owns the SessionPathProvider and
binds it to PATH_PROVIDER on the virtual container, so every view and
presenter resolves the same instance. Storage instances get it at
construction; devices only ever see
BaseStorage.
Exposes two slots the application connects to whatever announces plan lifecycle:
set_plan(str): filenames adopt the plan name of the upcoming run;reset_plan: the plan returns to"unknown", so bursts arriving after a run are not attributed to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Identity key of the presenter. |
required |
devices
|
Mapping[str, Device]
|
Available devices (unused; accepted for the presenter contract). |
required |
base_dir
|
str | None
|
Base directory for storage paths. YAML-friendly string; |
None
|
max_digits
|
int
|
Zero-padding width for the burst counter. Defaults to 5. |
5
|
Source code in src/redsun/presenter/builtins.py
path_provider
property
¶
The owned provider. Available after register_providers.
register_providers
¶
Create the provider (session-scoped) and register it for DI.