Use manifest defaults when adding components and refresh properties from device

- Populate prop elements with manifest default values when adding
  components in both offline and live mode
- Send config values from manifest in SOX add command for live devices
- Refresh button in properties panel now fetches fresh values from
  the connected device before re-reading the DOM
- Properties panel fetches device values on open in live mode

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-20 00:14:52 +03:00
co-authored by Claude Opus 4.6
parent 2530bbd92c
commit abdafef7cb
6 changed files with 122 additions and 17 deletions
+45 -1
View File
@@ -8,6 +8,7 @@ import xml.etree.ElementTree as ET
import app_state
import live_hooks
import palette
import properties
import schema
import undo
import wiresheet
@@ -69,6 +70,7 @@ def refresh_treeview_from_dom(xml_root):
app_element = xml_root.find("app")
if app_element is not None:
app_state.tree_element_map[root_node] = app_element
parse_xml_to_tree(tree, root_node, app_element)
else:
parse_xml_to_tree(tree, root_node, xml_root)
@@ -754,6 +756,28 @@ def reconcile_schema_kits_before_save():
return True
def _build_config_values(full_type):
"""Builds SOX config_values list from manifest defaults for an add command."""
from sox import type_id_for_slot
from live_hooks import _coerce_value
slots = app_state.final_components_registry.get(full_type, [])
config_values = []
for slot in slots:
if "c" not in slot["flags"]:
continue
if slot["type"] == "void":
continue
val = slot["default"]
if val is None:
val = properties.type_zero(slot["type"])
if val is None:
continue
tid = type_id_for_slot(slot["type"])
config_values.append((tid, _coerce_value(tid, val)))
return config_values
def add_component(kit_name, type_name, grid_x, grid_y):
"""Places a new component of kit::type at a grid position. Returns the element."""
parent = current_sheet_container()
@@ -784,7 +808,10 @@ def add_component(kit_name, type_name, grid_x, grid_y):
comp_name = unique_child_name(parent, type_name)
if live_hooks.is_live():
new_id = live_hooks.live_add_component(parent, kit_name, type_name, comp_name)
full_type = f"{kit_name}::{type_name}"
config_values = _build_config_values(full_type)
new_id = live_hooks.live_add_component(
parent, kit_name, type_name, comp_name, config_values or None)
if new_id is None:
return None
comp_id = new_id
@@ -796,6 +823,23 @@ def add_component(kit_name, type_name, grid_x, grid_y):
element.set("id", str(comp_id))
element.set("type", f"{kit_name}::{type_name}")
full_type = f"{kit_name}::{type_name}"
slots = app_state.final_components_registry.get(full_type, [])
for slot in slots:
flags = slot["flags"]
if "a" in flags or "r" in flags:
continue
if slot["type"] == "void":
continue
val = slot["default"]
if val is None:
val = properties.type_zero(slot["type"])
if val is None:
continue
prop = ET.SubElement(element, "prop")
prop.set("name", slot["name"])
prop.set("val", val)
index = len(list(parent))
parent.append(element)