Config saving of pipeline in/out

This commit is contained in:
2025-08-03 17:16:13 +02:00
parent 9801f69d0b
commit ac33ec5d8d
9 changed files with 303 additions and 136 deletions

View File

@ -20,12 +20,15 @@ class LayoutManager:
def save_layout(self):
self.logger.info("Saving layout...")
dpg.save_init_file(self.INI_PATH)
widget_data = [
{"widget_type": type(w).__name__, "config": w.get_config()}
for w in self.manager.widgets
]
layout_data = {
"pipeline_order" : { k:v for k, v in self.manager.pipeline.stages.items() },
"widgets": [
{"widget_type": type(w).__name__, "config": w.get_config()}
for w in self.manager.widgets
]
}
with open(self.WIDGET_DATA_PATH, "w") as f:
json.dump(widget_data, f, indent=4)
json.dump(layout_data, f, indent=4)
self.logger.info("Layout saved successfully.")
def load_layout(self):
@ -33,10 +36,17 @@ class LayoutManager:
if not os.path.exists(self.WIDGET_DATA_PATH):
return
with open(self.WIDGET_DATA_PATH, "r") as f:
widget_data = json.load(f)
layout_data = json.load(f)
# Load all widgets
widget_data = layout_data["widgets"]
for data in widget_data:
if data.get("widget_type") in self.manager.widget_classes:
self.manager._add_widget(widget_type=data.get("widget_type"))
self.manager._add_widget(widget_type=data.get("widget_type"), config=data.get("config"))
# Reset the image pipeline and reload it
pipelinestages = { int(k):v for k, v in layout_data["pipeline_order"].items() }
self.manager.pipeline.load_stages(pipelinestages)
if os.path.exists(self.INI_PATH):
dpg.configure_app(init_file=self.INI_PATH)