Palette: drag onto the tree to add inside a component; hover opens branches
A palette drag dropped on a tree row adds the component inside that row's component, placed under its lowest child. The row under the pointer is highlighted, and resting on a collapsed branch opens it, loading it from the device when live without moving the selection or the open sheet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+33
-3
@@ -16,6 +16,7 @@ from sax_dom import (
|
||||
find_component_by_path,
|
||||
find_parent_element,
|
||||
get_component_path,
|
||||
read_meta_property,
|
||||
restore_children,
|
||||
snapshot_children,
|
||||
update_meta_property,
|
||||
@@ -936,9 +937,38 @@ def build_config_values(full_type, overrides=None, device_values=None):
|
||||
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()
|
||||
def grid_position_below_children(parent):
|
||||
"""A spot for a component added without a drop point: under the parent's lowest child.
|
||||
|
||||
Used when a component is placed from the tree, where there is no point on the sheet
|
||||
to drop it at. Lining it up on the left margin below everything already there keeps
|
||||
it clear of the existing boxes in the common case; Tidy sorts out the rest.
|
||||
"""
|
||||
min_step = wiresheet.layout_margin(app_state.meta_scale) // app_state.meta_scale
|
||||
lowest = None
|
||||
for child in parent:
|
||||
if child.tag != "comp":
|
||||
continue
|
||||
meta_prop = child.find("prop[@name='meta']")
|
||||
y = read_meta_property(meta_prop.get("val") if meta_prop is not None else None)[1]
|
||||
lowest = y if lowest is None else max(lowest, y)
|
||||
|
||||
if lowest is None:
|
||||
return min_step, min_step
|
||||
return min_step, max(min_step, min(wiresheet.META_COORD_MAX, lowest + TREE_DROP_GAP))
|
||||
|
||||
|
||||
# Meta steps between the lowest existing box and one added under it from the tree.
|
||||
TREE_DROP_GAP = 8
|
||||
|
||||
|
||||
def add_component(kit_name, type_name, grid_x, grid_y, parent=None):
|
||||
"""Places a new component of kit::type at a grid position. Returns the element.
|
||||
|
||||
parent is the component it goes inside; None means the sheet that is open.
|
||||
"""
|
||||
if parent is None:
|
||||
parent = current_sheet_container()
|
||||
if parent is None:
|
||||
messagebox.showwarning("Add Component", "Open a SAX file first.")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user