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
+46 -6
View File
@@ -518,6 +518,8 @@ class PropertiesPanel:
# sibling nothing at all.
self._build_header(comp_type)
self._build_footer()
if app_state.live_mode and app_state.device_session is not None:
self._refresh_from_device()
self._loading = True
self._build_rows_area()
self._loading = False
@@ -1056,7 +1058,13 @@ class PropertiesPanel:
# -- the two buttons --
def refresh(self):
"""Re-reads every value from the DOM, discarding edits that were not saved."""
"""Re-reads every value from the DOM, discarding edits that were not saved.
In live mode, fetches fresh values from the device first.
"""
if app_state.live_mode and app_state.device_session is not None:
self._refresh_from_device()
self._loading = True
for row in self.rows:
self._load_row(row)
@@ -1066,7 +1074,30 @@ class PropertiesPanel:
self._load_meta_row()
self._load_path()
self._update_tint()
self.status_var.set("Refreshed from the document.")
if app_state.live_mode:
self.status_var.set("Refreshed from device.")
else:
self.status_var.set("Refreshed from the document.")
def _refresh_from_device(self):
"""Reads fresh config+runtime values from the device into the DOM element."""
from sox import CONFIG, RUNTIME
ds = app_state.device_session
comp_id = self.comp.get("id")
if comp_id is None:
return
try:
comp_id = int(comp_id)
except ValueError:
return
sox_comp = ds.sox_client.cache_get(comp_id)
if sox_comp is None:
return
try:
ds.sox_client.update([sox_comp], CONFIG | RUNTIME)
except Exception:
pass
ds.update_element_from_cache(comp_id, app_state.xml_root_element)
def save(self):
"""Writes the edited rows back, as one undoable step.
@@ -1137,9 +1168,9 @@ class PropertiesPanel:
for element, prop_name, _before, after in changes:
if prop_name != "meta":
set_prop_value(element, prop_name, after)
if live_hooks.is_live():
if not live_hooks.live_set_prop_value(element, prop_name, after):
live_failures.append(prop_name)
if live_hooks.is_live():
if not live_hooks.live_set_prop_value(element, prop_name, after):
live_failures.append(prop_name)
if not app_state.live_mode:
undo.push(undo.SlotValueCommand(list(changes)))
@@ -1174,7 +1205,16 @@ class PropertiesPanel:
root = app_state.xml_root_element
if root is None:
return False
return any(element is self.comp for element in root.iter())
if any(element is self.comp for element in root.iter()):
return True
if app_state.live_mode:
comp_id = self.comp.get("id")
if comp_id is not None:
for element in root.iter():
if element.get("id") == comp_id:
self.comp = element
return True
return False
def _sync_bar(self, bar, first, last):
"""Moves a scrollbar's thumb, and hides the bar entirely when it spans the whole."""