pywry.state_mixins¶
Shared mixins for unified state management across rendering paths. These provide a consistent API for Grid, Plotly, and Toolbar interactions regardless of the rendering backend (native window, inline IFrame, or Jupyter widget).
Base¶
pywry.state_mixins.EmittingWidget
¶
Base class for state mixins, providing the emit interface.
Functions¶
emit
¶
Emit an event to the JavaScript side.
This method must be implemented by the consuming class (e.g., PyWryWidget).
alert
¶
alert(message: str, alert_type: Literal['info', 'success', 'warning', 'error', 'confirm'] = 'info', title: str | None = None, duration: int | None = None, callback_event: str | None = None, position: Literal['top-right', 'top-left', 'bottom-right', 'bottom-left'] = 'top-right') -> None
Show a toast notification.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The message to display.
TYPE:
|
alert_type
|
Alert type: 'info', 'success', 'warning', 'error', or 'confirm'.
TYPE:
|
title
|
Optional title for the toast.
TYPE:
|
duration
|
Auto-dismiss duration in ms. Defaults based on type.
TYPE:
|
callback_event
|
Event name to emit when confirm dialog is answered.
TYPE:
|
position
|
Toast position: 'top-right', 'top-left', 'bottom-right', 'bottom-left'.
TYPE:
|
Grid Mixin¶
pywry.state_mixins.GridStateMixin
¶
Bases: EmittingWidget
Mixin for AG Grid state management.
Functions¶
request_grid_state
¶
Request the current state of the grid (sort, filter, columns, etc.).
The frontend will respond with a 'grid:state-response' event.
| PARAMETER | DESCRIPTION |
|---|---|
context
|
Context data to include in the response. This is echoed back unchanged in the state_response event, useful for tracking which request triggered the response (e.g., view switching).
TYPE:
|
grid_id
|
The ID of the grid to query.
TYPE:
|
restore_state
¶
Restore the grid state from a previous state object.
reset_state
¶
Reset the grid state to default values.
| PARAMETER | DESCRIPTION |
|---|---|
grid_id
|
The ID of the grid to reset.
TYPE:
|
hard
|
If True, completely destroys and recreates the grid instance. If False (default), only resets state columns/filters/sort.
TYPE:
|
update_cell
¶
Update a single cell value.
update_data
¶
Update grid data rows.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
List of row data dictionaries.
TYPE:
|
grid_id
|
The ID of the grid.
TYPE:
|
strategy
|
Update strategy ('set', 'append', 'update'). 'set' replaces all data.
TYPE:
|
update_columns
¶
Update column definitions.
update_grid
¶
update_grid(data: list[dict[str, Any]] | Any | None = None, columns: list[dict[str, Any]] | None = None, restore_state: dict[str, Any] | None = None, grid_id: str | None = None) -> None
Update the grid with new data, columns, and/or restore saved state.
This is the primary method for switching views or making bulk updates. It combines data, column, and state updates into a single operation to minimize UI flicker.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
New row data. If a DataFrame, it will be converted to records.
TYPE:
|
columns
|
New column definitions.
TYPE:
|
restore_state
|
Previously saved grid state to restore (from grid:state-response). Contains columnState, filterModel, sortModel.
TYPE:
|
grid_id
|
The ID of the grid to update.
TYPE:
|
Plotly Mixin¶
pywry.state_mixins.PlotlyStateMixin
¶
Bases: EmittingWidget
Mixin for Plotly chart state management.
Functions¶
update_figure
¶
update_figure(figure: Any, chart_id: str | None = None, animate: bool = False, config: dict[str, Any] | None = None) -> None
Update the entire chart figure (data and layout).
update_layout
¶
Update specific layout properties (Plotly.relayout).
update_traces
¶
update_traces(patch: dict[str, Any], indices: list[int] | None = None, chart_id: str | None = None) -> None
Update specific trace properties (Plotly.restyle).
request_plotly_state
¶
Request current chart state (viewport, zoom, selections).
set_zoom
¶
set_zoom(xaxis_range: tuple[Any, Any] | None = None, yaxis_range: tuple[Any, Any] | None = None, chart_id: str | None = None) -> None
Set specific zoom ranges for axes.
set_trace_visibility
¶
set_trace_visibility(visible: bool | str | list[bool | str], indices: list[int] | None = None, chart_id: str | None = None) -> None
Set visibility for specific traces.
Toolbar Mixin¶
pywry.state_mixins.ToolbarStateMixin
¶
Bases: EmittingWidget
Mixin for Toolbar state interactions.
Functions¶
request_toolbar_state
¶
Request values of all toolbar inputs.
set_toolbar_value
¶
set_toolbar_value(component_id: str, value: Any = _UNSET, toolbar_id: str | None = None, **attrs: Any) -> None
Set a toolbar component's value and/or attributes.
| PARAMETER | DESCRIPTION |
|---|---|
component_id
|
The component_id of the toolbar item to update.
TYPE:
|
value
|
The new value for the component.
TYPE:
|
toolbar_id
|
The toolbar ID (if applicable).
TYPE:
|
**attrs
|
Additional attributes to set on the component: - label/text: Update text content - disabled: Enable/disable the component - variant: Button variant (primary, secondary, danger, etc.) - tooltip/description: Update tooltip text - options: Update dropdown/select options - style: Inline styles (str or dict) - className/class: Add/remove CSS classes - placeholder, min, max, step: Input constraints
TYPE:
|
set_toolbar_values
¶
Set multiple toolbar input values at once.