Fix tree expand in live mode: use focused item and run IO in background
_on_tree_open used tree.selection() which may differ from the opened node; switched to tree.focus(). Network calls in _live_tree_expand now run in a daemon thread so the UI stays responsive during lazy loading. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it.
|
|||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
|
|
||||||
VERSION = "0.0.0.078"
|
VERSION = "0.0.0.079"
|
||||||
PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties")
|
PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties")
|
||||||
DEFAULT_GRID_SIZE = 10
|
DEFAULT_GRID_SIZE = 10
|
||||||
DEFAULT_ADD_TIMESTAMP = True
|
DEFAULT_ADD_TIMESTAMP = True
|
||||||
|
|||||||
@@ -1352,13 +1352,13 @@ def attach_tree_scrollbars(container, tree):
|
|||||||
def _on_tree_open(event):
|
def _on_tree_open(event):
|
||||||
tree.after_idle(fit_tree_column, tree)
|
tree.after_idle(fit_tree_column, tree)
|
||||||
if app_state.live_mode:
|
if app_state.live_mode:
|
||||||
sel = tree.selection()
|
opened = tree.focus()
|
||||||
if sel:
|
if opened:
|
||||||
elem = app_state.tree_element_map.get(sel[0])
|
elem = app_state.tree_element_map.get(opened)
|
||||||
if elem is not None:
|
if elem is not None:
|
||||||
cid = elem.get("id")
|
cid = elem.get("id")
|
||||||
if cid is not None:
|
if cid is not None:
|
||||||
_live_tree_expand(int(cid))
|
_live_tree_expand(int(cid), opened)
|
||||||
|
|
||||||
tree.bind("<<TreeviewOpen>>", _on_tree_open, add="+")
|
tree.bind("<<TreeviewOpen>>", _on_tree_open, add="+")
|
||||||
tree.bind("<<TreeviewClose>>", lambda event: tree.after_idle(fit_tree_column, tree), add="+")
|
tree.bind("<<TreeviewClose>>", lambda event: tree.after_idle(fit_tree_column, tree), add="+")
|
||||||
@@ -2041,20 +2041,42 @@ def _start_cov_polling():
|
|||||||
_cov_poll_id = app_state.window.after(100, poll)
|
_cov_poll_id = app_state.window.after(100, poll)
|
||||||
|
|
||||||
|
|
||||||
def _live_tree_expand(comp_id):
|
def _live_tree_expand(comp_id, tree_item_id):
|
||||||
"""Called when user expands a tree node in live mode to lazy-load children."""
|
"""Called when user expands a tree node in live mode to lazy-load children."""
|
||||||
ds = app_state.device_session
|
ds = app_state.device_session
|
||||||
if ds is None or not ds.is_connected:
|
if ds is None or not ds.is_connected:
|
||||||
return
|
return
|
||||||
|
|
||||||
children = ds.load_children(comp_id)
|
app_state.set_status("Loading children...")
|
||||||
if not children:
|
|
||||||
return
|
|
||||||
|
|
||||||
sax_root = ds.build_dom_tree(ds.sox_client.cache_get(0))
|
def _bg():
|
||||||
ds.build_links_elements(sax_root)
|
try:
|
||||||
app_state.xml_root_element = sax_root
|
children = ds.load_children(comp_id)
|
||||||
sax_file.refresh_treeview_from_dom(sax_root)
|
if not children:
|
||||||
|
app_state.window.after(0, lambda: app_state.set_status("No children"))
|
||||||
|
return
|
||||||
|
sax_root = ds.build_dom_tree(ds.sox_client.cache_get(0))
|
||||||
|
ds.build_links_elements(sax_root)
|
||||||
|
|
||||||
|
def _ui():
|
||||||
|
app_state.xml_root_element = sax_root
|
||||||
|
sax_file.refresh_treeview_from_dom(sax_root)
|
||||||
|
# Re-open and select the node the user clicked
|
||||||
|
for iid, elem in app_state.tree_element_map.items():
|
||||||
|
if elem.get("id") == str(comp_id):
|
||||||
|
tree.item(iid, open=True)
|
||||||
|
tree.selection_set(iid)
|
||||||
|
tree.see(iid)
|
||||||
|
break
|
||||||
|
app_state.set_status(f"Loaded {len(children)} children")
|
||||||
|
|
||||||
|
app_state.window.after(0, _ui)
|
||||||
|
except Exception as exc:
|
||||||
|
app_state.window.after(
|
||||||
|
0, lambda: app_state.set_status(f"Load error: {exc}", warn=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
threading.Thread(target=_bg, daemon=True).start()
|
||||||
|
|
||||||
|
|
||||||
# --- UI Setup ---
|
# --- UI Setup ---
|
||||||
|
|||||||
Reference in New Issue
Block a user