MCPcopy Index your code
hub / github.com/SLiCAP/SLiCAP_python / update_labels

Method update_labels

SLiCAP/schematic/component_item.py:613–664  ·  view source on GitHub ↗

Rebuild visible property labels from prop_display.

(self)

Source from the content-addressed store, hash-verified

611 self.prop_offsets[key] = (lbl.pos().x(), lbl.pos().y())
612
613 def update_labels(self) -> None:
614 """Rebuild visible property labels from prop_display."""
615 from .latex_label import is_expression, render_expression, render_name_eq_value
616
617 self._save_label_offsets()
618
619 for lbl in list(self._labels.values()):
620 lbl.setParentItem(None)
621 self._labels.clear()
622
623 # Ensure a default offset exists for every known property.
624 # Always use +label_x; the rendering side adapts for h_flip.
625 label_x = self._label_x()
626 for i, key in enumerate(self._all_prop_keys()):
627 if key not in self.prop_offsets:
628 self.prop_offsets[key] = (
629 label_x,
630 _DEFAULT_LABEL_Y0 + i * _DEFAULT_LABEL_STEP,
631 )
632
633 for key in self._all_prop_keys():
634 show_val, show_name = self.prop_display.get(key, (False, False))
635 if not show_val:
636 continue
637 raw_val = self._prop_value(key)
638 if not raw_val:
639 continue
640
641 lbl = _PropertyLabel(key, self)
642
643 # Parameter values are LaTeX expressions by default: the user enters
644 # the bare expression and the braces that mark it as an expression
645 # are added here for rendering (refdes/model/refs are left as-is).
646 # Power symbols' "name" param is a net name, not an expression.
647 is_param = key in self.params and self.symbol_name not in ("0", "port")
648 render_val = wrap_braces(raw_val) if is_param else raw_val
649
650 if is_expression(render_val):
651 if show_name:
652 svg = render_name_eq_value(key, render_val)
653 else:
654 svg = render_expression(render_val)
655 if svg is not None:
656 lbl.set_svg(svg)
657 else:
658 lbl.set_text(self._prop_text(key))
659 else:
660 lbl.set_text(self._prop_text(key))
661
662 lbl.setPos(QPointF(*self.prop_offsets[key]))
663 lbl.setTransform(_counter_transform(self.rotation(), self.h_flip, self.v_flip))
664 self._labels[key] = lbl
665
666 def refresh_svg_labels(self) -> None:
667 """Re-scale all SVG-mode labels using the current _LABEL/_PARAM_SVG_HEIGHT.

Callers 8

__init__Method · 0.95
reload_svgMethod · 0.95
from_dataMethod · 0.95
applyMethod · 0.80
applyMethod · 0.80
_commit_pasteMethod · 0.80
applyMethod · 0.80

Calls 14

_save_label_offsetsMethod · 0.95
_label_xMethod · 0.95
_all_prop_keysMethod · 0.95
_prop_valueMethod · 0.95
_prop_textMethod · 0.95
_PropertyLabelClass · 0.85
wrap_bracesFunction · 0.85
is_expressionFunction · 0.85
render_name_eq_valueFunction · 0.85
render_expressionFunction · 0.85
_counter_transformFunction · 0.85
clearMethod · 0.80

Tested by

no test coverage detected