forked from genewildish/Mainline
Implement pipeline hot-rebuild with state preservation
- Add save_state/restore_state methods to CameraStage - Add save_state/restore_state methods to DisplayStage - Extend Pipeline._copy_stage_state() to preserve camera/display state - Add save_state/restore_state methods to UIPanel for UI state preservation - Update pipeline_runner to preserve UI state across preset changes Camera state preserved: - Position (x, y) - Mode (feed, scroll, horizontal, etc.) - Speed, zoom, canvas dimensions - Internal timing state Display state preserved: - Initialization status - Dimensions - Reuse flag for display reinitialization UI Panel state preserved: - Stage enabled/disabled status - Parameter values - Selected stage and focused parameter - Scroll position This enables manual/event-driven rebuilds when inlet-outlet connections change, while preserving all relevant state across pipeline mutations.
This commit is contained in:
@@ -78,6 +78,58 @@ class UIPanel:
|
||||
self._show_panel: bool = True # UI panel visibility
|
||||
self._preset_scroll_offset: int = 0 # Scroll in preset list
|
||||
|
||||
def save_state(self) -> dict[str, Any]:
|
||||
"""Save UI panel state for restoration after pipeline rebuild.
|
||||
|
||||
Returns:
|
||||
Dictionary containing UI panel state that can be restored
|
||||
"""
|
||||
# Save stage control states (enabled, params, etc.)
|
||||
stage_states = {}
|
||||
for name, ctrl in self.stages.items():
|
||||
stage_states[name] = {
|
||||
"enabled": ctrl.enabled,
|
||||
"selected": ctrl.selected,
|
||||
"params": dict(ctrl.params), # Copy params dict
|
||||
}
|
||||
|
||||
return {
|
||||
"stage_states": stage_states,
|
||||
"scroll_offset": self.scroll_offset,
|
||||
"selected_stage": self.selected_stage,
|
||||
"_focused_param": self._focused_param,
|
||||
"_show_panel": self._show_panel,
|
||||
"_show_preset_picker": self._show_preset_picker,
|
||||
"_preset_scroll_offset": self._preset_scroll_offset,
|
||||
}
|
||||
|
||||
def restore_state(self, state: dict[str, Any]) -> None:
|
||||
"""Restore UI panel state from saved state.
|
||||
|
||||
Args:
|
||||
state: Dictionary containing UI panel state from save_state()
|
||||
"""
|
||||
# Restore stage control states
|
||||
stage_states = state.get("stage_states", {})
|
||||
for name, stage_state in stage_states.items():
|
||||
if name in self.stages:
|
||||
ctrl = self.stages[name]
|
||||
ctrl.enabled = stage_state.get("enabled", True)
|
||||
ctrl.selected = stage_state.get("selected", False)
|
||||
# Restore params
|
||||
saved_params = stage_state.get("params", {})
|
||||
for param_name, param_value in saved_params.items():
|
||||
if param_name in ctrl.params:
|
||||
ctrl.params[param_name] = param_value
|
||||
|
||||
# Restore UI panel state
|
||||
self.scroll_offset = state.get("scroll_offset", 0)
|
||||
self.selected_stage = state.get("selected_stage")
|
||||
self._focused_param = state.get("_focused_param")
|
||||
self._show_panel = state.get("_show_panel", True)
|
||||
self._show_preset_picker = state.get("_show_preset_picker", False)
|
||||
self._preset_scroll_offset = state.get("_preset_scroll_offset", 0)
|
||||
|
||||
def register_stage(self, stage: Any, enabled: bool = True) -> StageControl:
|
||||
"""Register a stage for UI control.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user