Workflows¶
Workflow¶
Workflow
¶
Manage a sequence of steps for one session controller.
run_current_step
¶
Run a manually triggered processing step or custom step action.
WorkflowStep¶
WorkflowStep
¶
Bases: ABC
Base class for workflow state and presentation.
clone
¶
Return an unbound copy of this step, ready to bind to a new workflow.
Relies on subclasses resetting mutable fields to fresh objects (not
mutating in place) in reset_state/reset_workflow_state.
on_data_model_changed
¶
React to session data changes while this step is active.
reset_workflow_state
¶
Reset state and any history retained across step navigation.
StepUIType¶
StepUIType
¶
Bases: str, Enum
Built-in steps¶
| Step | Purpose |
|---|---|
MessageStep |
Show instructional text |
InputSelectionStep |
Load datasets and assign them to named roles |
ParameterStep |
Collect typed parameter values |
ProcessingStep |
Run a callback and publish results |
BrushStep |
Edit a label map with the smart brush |
AnnotationStep |
Collect points, lines, boxes, or angles from the user |
ValidationStep |
Accept or reject a result before continuing |
ExportStep |
Export session data in chosen formats |
CustomStep |
Compose custom panel content from UI elements |
InputSelectionStep
¶
InputSelectionStep(
title="Select Inputs",
inputs=None,
allow_upload=True,
allow_sample_datasets=None,
message="Load datasets, then assign each input role.",
step_id=None,
depends_on=None,
)
Bases: WorkflowStep
ParameterStep
¶
ProcessingStep
¶
ProcessingStep(
title="Processing",
callback=None,
inputs_from=None,
parameters_from=None,
auto_proceed=False,
auto_run=True,
run_label="Run",
step_id=None,
depends_on=None,
)
BrushStep
¶
BrushStep(
title="Edit Label Map",
message="Start the brush, paint in the viewer, then stop it to save your edits.",
image_from=None,
label_map_from=None,
image_role=None,
label_map_role=None,
radius_mm=10.0,
adaptiveness=0.5,
allow_radius_change=True,
allow_adaptiveness_change=True,
labels=(1,),
label_map_name="Label Map",
step_id=None,
depends_on=None,
)
AnnotationStep
¶
AnnotationStep(
title="Place Annotation",
message="Press Place, then draw the annotation in the viewer.",
annotation_type=AnnotationType.RECTANGLE,
image_from=None,
image_role=None,
image_roles=None,
labels=None,
count=1,
color=None,
required=True,
keep_annotations=True,
views=None,
show_measurements=False,
on_finished=None,
step_id=None,
depends_on=None,
)
Bases: WorkflowStep
Ask the user to place annotations, then hand the geometry to Python.
One annotation is collected per entry in labels (or per count) for
each role in image_roles. Placement is armed explicitly, by a button in
the panel, so the first click on the canvas cannot become an annotation
while the user is still navigating to the anatomy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Step title shown in the workflow panel. |
'Place Annotation'
|
message
|
str
|
Instruction shown above the placement controls. |
'Press Place, then draw the annotation in the viewer.'
|
annotation_type
|
AnnotationType
|
Shape the user places. |
RECTANGLE
|
image_from
|
Optional[str]
|
Step id providing the dataset to annotate, either an
|
None
|
image_role
|
Optional[str]
|
Input role in |
None
|
image_roles
|
Optional[Sequence[str]]
|
Annotate one dataset per role, for example a fixed and a
moving image. Each role names an input role in |
None
|
labels
|
Optional[Sequence[str]]
|
One prompt per annotation, drawn next to it in the viewer and shown in the panel. Its length sets how many are collected. |
None
|
count
|
int
|
How many annotations to collect, when they need no labels. |
1
|
color
|
Optional[Sequence[float]]
|
Fixed RGB or RGBA colour. Roles get distinct colours by default. |
None
|
required
|
bool
|
Whether the step blocks until every annotation is placed. |
True
|
keep_annotations
|
bool
|
Leave the annotations in the viewer after the step. They are reused if the user comes back. Turn this off for geometry that stops being meaningful later, such as a landmark on an image a later step registers, because an annotation does not follow its dataset's transform. |
True
|
views
|
Optional[Sequence[ViewType]]
|
Views the user may annotate in. Defaults to the slice views, plus the 3D view for point and box annotations. |
None
|
show_measurements
|
bool
|
Show a line's length and an angle's angle. |
False
|
on_finished
|
Optional[Callable[..., Any]]
|
Called once every annotation is placed, with no arguments or with the step, whichever the callback declares. |
None
|
step_id
|
Optional[str]
|
Explicit id, for other steps to reference. |
None
|
depends_on
|
Optional[List[str]]
|
Extra step ids that invalidate this one; |
None
|
clear
¶
Remove the collected annotations from the viewer.
Worth calling once the geometry has been consumed: an annotation does not follow its dataset's transform, so after a registration moves the image the annotation sits visibly detached from what it marked.
ValidationStep
¶
ValidationStep(
title="Review Result",
message="Is this result acceptable?",
step_id=None,
depends_on=None,
)
Bases: WorkflowStep
ExportStep
¶
ExportStep(
title="Export",
message="Export your results",
formats=None,
step_id=None,
depends_on=None,
require_export_before_finish=True,
)
Bases: WorkflowStep
CustomStep
¶
CustomStep(
title="Custom",
body=None,
step_id=None,
depends_on=None,
require_completion=False,
completion_message="Complete this step before continuing",
)
Bases: WorkflowStep
Step whose contents are described with :mod:~imfusion_webappkit.ui_elements.
Pass a static body for a fixed layout, or subclass and override
:meth:body to rebuild the elements from the current session state every
time the browser refreshes. Subclasses handle button presses by overriding
:meth:on_action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Step title shown in the workflow panel. |
'Custom'
|
body
|
Optional[Sequence[UIElement]]
|
Elements displayed for the step. |
None
|
step_id
|
Optional[str]
|
Stable identifier. Defaults to |
None
|
depends_on
|
Optional[List[str]]
|
Identifiers of steps that invalidate this one. |
None
|
require_completion
|
bool
|
Block Next until the step sets
:attr: |
False
|
completion_message
|
str
|
Reason shown while completion is still required. |
'Complete this step before continuing'
|
UI elements¶
UIElement
¶
Bases: ABC
Base class for the elements a custom step can display.
Text
¶
Bases: UIElement
Markdown paragraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
Markdown source. Raw HTML is not rendered. |
required |
Alert
¶
Bases: UIElement
Short highlighted message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
Plain text shown in the callout. |
required |
level
|
str
|
One of |
'info'
|
Metrics
¶
Bases: UIElement
Grid of labelled values such as scores, counts, or volumes.
Values are displayed exactly as provided, so round or format them before passing them in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Union[Mapping[str, Any], Sequence[Metric]]
|
Either a mapping of label to value, or a sequence of
:class: |
required |
Table
¶
Bases: UIElement
Small tabular result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
Sequence[Union[Mapping[str, CellValue], Sequence[CellValue]]]
|
Either mappings keyed by column name, or sequences of cells that
match |
required |
columns
|
Optional[Sequence[str]]
|
Column headers. Required for sequence rows; derived from the first mapping row otherwise. |
None
|
caption
|
Optional[str]
|
Optional description shown below the table. |
None
|
Series
dataclass
¶
One named sequence of values in a :class:Chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Name shown in the chart legend. |
required |
values
|
Sequence[float]
|
Value of each point. |
required |
x
|
Optional[Sequence[Position]]
|
Optional position or category name of each point. Positions must be either all numbers or all strings, and default to the point index. |
None
|
Chart
¶
Bases: UIElement
Plot of one or more numeric series, drawn to the width of the panel.
Charts summarize a result; they are not a substitute for the viewer. Use string positions for categories such as label names, and numeric positions for measured quantities such as histogram bins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variant
|
str
|
One of |
required |
series
|
Union[Series, Sequence[Series], Mapping[str, Sequence[float]]]
|
A single :class: |
required |
x_label
|
Optional[str]
|
Optional name of the horizontal axis. |
None
|
y_label
|
Optional[str]
|
Optional name of the vertical axis. |
None
|
caption
|
Optional[str]
|
Optional description shown below the chart. |
None
|
Image
¶
Bases: UIElement
Raster image such as a rendered plot or an external screenshot.
The encoded image is part of every workflow state update, so keep it small. Images belong to a step's description of its result; data that has a position in space belongs in the session data model instead, where the viewer can display it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Union[bytes, bytearray, memoryview, str, Path]
|
PNG, JPEG, or WebP data, or the path of such a file. |
required |
caption
|
Optional[str]
|
Optional description shown below the image. |
None
|
alt
|
Optional[str]
|
Alternative text for assistive technologies. Defaults to the caption. |
None
|
Fields
¶
Bases: UIElement
Editable values using the same typed parameters as actions.
Values are validated by the server and are available as step.values,
keyed by parameter name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Sequence[ParameterDefinition]
|
Parameter descriptors such as
:class: |
required |
submit_action
|
Optional[str]
|
Action to dispatch, as if a :class: |
None
|
Button
¶
Bases: UIElement
Button that calls the step's on_action hook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
Identifier passed to |
required |
label
|
Optional[str]
|
Button text. Defaults to a title-cased |
None
|
style
|
str
|
One of |
'default'
|
job
|
bool
|
Run the handler as a correlated job so it reports progress and can be cancelled. Required for handlers that do more than update step state, because other work stays blocked while they run. |
False
|
disabled
|
bool
|
Show the button but reject presses, in the browser and on the server. |
False
|
AnnotationField
¶
AnnotationField(
annotations,
*,
label=None,
place_action=None,
clear_action=None,
prompts=None,
show_measurements=False
)
Bases: UIElement
Live state of annotations the step is collecting, with its own controls.
For steps that mix annotation placement with other input — measure a
distance in a field, then place a box using it — where
:class:~imfusion_webappkit.workflow.AnnotationStep does not apply. The
step drives app.annotation_model from on_action and this element
shows the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotations
|
Sequence[Any]
|
The annotations to display, in the order the user places
them. Usually |
required |
label
|
Optional[str]
|
Optional heading above the list. |
None
|
place_action
|
Optional[str]
|
Action dispatched by the Place button; omit for a read-only readout. |
None
|
clear_action
|
Optional[str]
|
Action dispatched by the Clear button. |
None
|
prompts
|
Optional[Sequence[str]]
|
Optional per-annotation prompt, shown instead of the annotation's own label. |
None
|
show_measurements
|
bool
|
Show a line's length and an angle's angle. |
False
|