redsun.view.qt gives you Qt widgets to use in the views of a session: the
controls of a plan, buttons for the actions of a running plan, and a tree of a
device's settings.
create_plan_widget builds a plan widget from a
PlanSpec: an input per parameter and a Run button, plus, for a continuous
plan, a toggle, a pause button and a button per action. It returns a
PlanWidget, a frozen dataclass owning the widget tree, whose group_box
your view adds to its layout:
A plan widget, its view and the presenter
A plan widget runs nothing itself. Step through what happens when the user presses Run.
plan widgetviewpresentercalls backplan name andPlanWidget.parametersstarted, paused,endedtoggle, pause
The plan widget calls the view back.
plan widgetviewpresentercalls backplan name andPlanWidget.parametersstarted, paused,endedtoggle, pause
plan widgetviewpresentercalls backplan name andPlanWidget.parametersstarted, paused,endedtoggle, pause
The view sends the plan's name and PlanWidget.parameters to the presenter, which runs the plan.
plan widgetviewpresenterThe presenter runs the plan.calls backplan name andPlanWidget.parametersstarted, paused,endedtoggle, pauseThe presenter runs the plan.
plan widgetviewpresenterThe presenter runs the plan.calls backplan name andPlanWidget.parametersstarted, paused,endedtoggle, pauseThe presenter runs the plan.
The presenter reports back that the plan started, paused or ended.
plan widgetviewpresenterThe presenter runs the plan.calls backplan name andPlanWidget.parametersstarted, paused,endedtoggle, pauseThe presenter runs the plan.
plan widgetviewpresenterThe presenter runs the plan.calls backplan name andPlanWidget.parametersstarted, paused,endedtoggle, pauseThe presenter runs the plan.
The view follows it on the widget, with toggle and pause.
plan widgetviewpresenterThe presenter runs the plan.calls backplan name andPlanWidget.parametersstarted, paused,endedtoggle, pauseThe presenter runs the plan.
plan widgetviewpresenterThe presenter runs the plan.calls backplan name andPlanWidget.parametersstarted, paused,endedtoggle, pauseThe presenter runs the plan.
Each input starts from its default and returns a value of the annotated type.
Inputs nest, so a dict[str, list[float]] becomes a table whose values are
lists. While an input holds a value the plan can't take, such as a repeated
key or no device chosen, Run stays disabled and the first of
PlanWidget.problems shows under the parameters.
How to run a plan from a presenter,
How to write a plan that runs until stopped
and How to choose the inputs of a plan
show them in use.
The plan's own callbacks come first, checked and fixed; each shows its name
in available_callbacks, else its name attribute or class name, and appears
once even when also available. The user checks and reorders the others.
callbacks returns the checked ones in order and attached_callbacks the
names the user attached; with attached_callbacks=None every available one
starts checked, and a name no longer available is ignored. A plan with no
callback that isn't extendable gets no group. The widget only reports the
choice; the presenter subscribes the callbacks to the
RunEngine.
create_param_widget turns each parameter's ParamDescription into a widget
from magicgui, a package that builds widgets from Python types, by asking
fixed questions in order:
How create_param_widget picks a widget
create_param_widget asks these questions in order and builds the widget of the first one answered yes. Step through four parameters.
a parameterhidden, or does itcarry actions?placeholderline editA plan widget leaves these parameters out, so the placeholder is never shown in one.a sequence or set ofdevices, or *args?a list ofcheckboxesOne checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.a device?a combo boxof the devicesThe devices of the session that match the annotation, in the Devices group of the plan widget.a Literal?a combo boxof the choicesanything elsean input builtfrom its typeA list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.nonononoyesyesyesyesA plan widget leaves these parameters out, so the placeholder is never shown in one.One checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.The devices of the session that match the annotation, in the Devices group of the plan widget.A list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.
a parameterhidden, or does itcarry actions?placeholderline editA plan widget leaves these parameters out, so the placeholder is never shown in one.a sequence or set ofdevices, or *args?a list ofcheckboxesOne checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.a device?a combo boxof the devicesThe devices of the session that match the annotation, in the Devices group of the plan widget.a Literal?a combo boxof the choicesanything elsean input builtfrom its typeA list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.nonononoyesyesyesyesA plan widget leaves these parameters out, so the placeholder is never shown in one.One checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.The devices of the session that match the annotation, in the Devices group of the plan widget.A list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.
detectors: Sequence[MyCamera] is a sequence of devices, so it gets a list of checkboxes, one per matching device.
detectors: Sequence[MyCamera]hidden, or does itcarry actions?placeholderline editA plan widget leaves these parameters out, so the placeholder is never shown in one.a sequence or set ofdevices, or *args?a list ofcheckboxesOne checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.a device?a combo boxof the devicesThe devices of the session that match the annotation, in the Devices group of the plan widget.a Literal?a combo boxof the choicesanything elsean input builtfrom its typeA list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.nonononoyesyesyesyesA plan widget leaves these parameters out, so the placeholder is never shown in one.One checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.The devices of the session that match the annotation, in the Devices group of the plan widget.A list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.
detectors: Sequence[MyCamera]hidden, or does itcarry actions?placeholderline editA plan widget leaves these parameters out, so the placeholder is never shown in one.a sequence or set ofdevices, or *args?a list ofcheckboxesOne checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.a device?a combo boxof the devicesThe devices of the session that match the annotation, in the Devices group of the plan widget.a Literal?a combo boxof the choicesanything elsean input builtfrom its typeA list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.nonononoyesyesyesyesA plan widget leaves these parameters out, so the placeholder is never shown in one.One checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.The devices of the session that match the annotation, in the Devices group of the plan widget.A list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.
camera: MyCamera is one device, so it gets a combo box of the session's matching devices.
camera: MyCamerahidden, or does itcarry actions?placeholderline editA plan widget leaves these parameters out, so the placeholder is never shown in one.a sequence or set ofdevices, or *args?a list ofcheckboxesOne checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.a device?a combo boxof the devicesThe devices of the session that match the annotation, in the Devices group of the plan widget.a Literal?a combo boxof the choicesanything elsean input builtfrom its typeA list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.nonononoyesyesyesyesA plan widget leaves these parameters out, so the placeholder is never shown in one.One checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.The devices of the session that match the annotation, in the Devices group of the plan widget.A list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.
camera: MyCamerahidden, or does itcarry actions?placeholderline editA plan widget leaves these parameters out, so the placeholder is never shown in one.a sequence or set ofdevices, or *args?a list ofcheckboxesOne checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.a device?a combo boxof the devicesThe devices of the session that match the annotation, in the Devices group of the plan widget.a Literal?a combo boxof the choicesanything elsean input builtfrom its typeA list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.nonononoyesyesyesyesA plan widget leaves these parameters out, so the placeholder is never shown in one.One checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.The devices of the session that match the annotation, in the Devices group of the plan widget.A list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.
mode: Literal["fast", "slow"] gets a combo box of its choices.
mode: Literal["fast", "slow"]hidden, or does itcarry actions?placeholderline editA plan widget leaves these parameters out, so the placeholder is never shown in one.a sequence or set ofdevices, or *args?a list ofcheckboxesOne checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.a device?a combo boxof the devicesThe devices of the session that match the annotation, in the Devices group of the plan widget.a Literal?a combo boxof the choicesanything elsean input builtfrom its typeA list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.nonononoyesyesyesyesA plan widget leaves these parameters out, so the placeholder is never shown in one.One checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.The devices of the session that match the annotation, in the Devices group of the plan widget.A list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.
mode: Literal["fast", "slow"]hidden, or does itcarry actions?placeholderline editA plan widget leaves these parameters out, so the placeholder is never shown in one.a sequence or set ofdevices, or *args?a list ofcheckboxesOne checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.a device?a combo boxof the devicesThe devices of the session that match the annotation, in the Devices group of the plan widget.a Literal?a combo boxof the choicesanything elsean input builtfrom its typeA list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.nonononoyesyesyesyesA plan widget leaves these parameters out, so the placeholder is never shown in one.One checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.The devices of the session that match the annotation, in the Devices group of the plan widget.A list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.
positions: list[float] is none of these, so it gets an input built from its type: a list of float inputs.
positions: list[float]hidden, or does itcarry actions?placeholderline editA plan widget leaves these parameters out, so the placeholder is never shown in one.a sequence or set ofdevices, or *args?a list ofcheckboxesOne checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.a device?a combo boxof the devicesThe devices of the session that match the annotation, in the Devices group of the plan widget.a Literal?a combo boxof the choicesanything elsean input builtfrom its typeA list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.nonononoyesyesyesyesA plan widget leaves these parameters out, so the placeholder is never shown in one.One checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.The devices of the session that match the annotation, in the Devices group of the plan widget.A list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.
positions: list[float]hidden, or does itcarry actions?placeholderline editA plan widget leaves these parameters out, so the placeholder is never shown in one.a sequence or set ofdevices, or *args?a list ofcheckboxesOne checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.a device?a combo boxof the devicesThe devices of the session that match the annotation, in the Devices group of the plan widget.a Literal?a combo boxof the choicesanything elsean input builtfrom its typeA list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.nonononoyesyesyesyesA plan widget leaves these parameters out, so the placeholder is never shown in one.One checkbox per device of the session that matches the annotation, in the Devices group of the plan widget.The devices of the session that match the annotation, in the Devices group of the plan widget.A list, set, mapping, fixed-length tuple, optional value or union gets an input built from the inputs of its parts. Anything else gets the magicgui widget for its type.
DescriptorTreeView shows a device's describe_configuration and
read_configuration as an editable two-column tree. It reports edits but
writes nothing; a presenter does, through Deferrals while a plan runs
(How to change a device setting while a plan runs):
Rows are grouped by their name-property key, with one header per device
name. A property whose name holds a dash of its own gets a second header under
that one, so cam-properties-Binning shows as Binning under properties
under cam. A property whose source ends in :readonly shows as a greyed
label.
An edit is only a request. The tree emits sig_property_changed and keeps the
edit pending, showing what was typed, until it's told how the request ended:
An edit in the tree
treeviewpresenterdeviceif the device took itif the device refused itsig_property_changed,the edit stays pendingthe requestset the valueread it backannounce the value,or that the device refused itset_valuerevert
treeviewpresenterdeviceif the device took itif the device refused itsig_property_changed,the edit stays pendingthe requestset the valueread it backannounce the value,or that the device refused itset_valuerevert
tree.set_value("stage-position",12.5)# what the device read backtree.revert("stage-position")# the device refused: show the value before
set_value shows the value it's given, which may differ from what was typed
when the device rounds or clips it, and neither call emits
sig_property_changed, so the tree only ever shows values the device
reported.