MCPcopy Create free account
hub / github.com/SLiCAP/SLiCAP_python / _on_reload_symbols

Method _on_reload_symbols

SLiCAP/schematic/window.py:402–456  ·  view source on GitHub ↗

Refresh the selected symbols with the most recent library definitions. Replaces the schematic's cached (frozen) definition of each selected symbol — and every instance of it on the canvas — with the live version from the symbol library. Pin positions may move, so connection

(self)

Source from the content-addressed store, hash-verified

400 QMessageBox.information(self, "Rename Components", msg)
401
402 def _on_reload_symbols(self):
403 """Refresh the selected symbols with the most recent library definitions.
404
405 Replaces the schematic's cached (frozen) definition of each selected
406 symbol — and every instance of it on the canvas — with the live version
407 from the symbol library. Pin positions may move, so connections can
408 break; restoring them is left to the user (per the warning)."""
409 from .component_item import ComponentItem
410 selected = [i for i in self._scene.selectedItems() if isinstance(i, ComponentItem)]
411 if not selected:
412 QMessageBox.information(
413 self, "Load symbols from library",
414 "Select one or more component symbols on the canvas first.",
415 )
416 return
417 names = sorted({i.symbol_name for i in selected})
418 ret = QMessageBox.warning(
419 self, "Load symbols from library",
420 "The cached definition of the selected symbol(s):\n\n"
421 f" {', '.join(names)}\n\n"
422 "and every instance of them on the canvas will be replaced with the "
423 "most recent version from the symbol library.\n\n"
424 "Pin positions may differ from the cached symbols, which can break "
425 "existing wire connections — restoring them is up to you.\n\nProceed?",
426 QMessageBox.Yes | QMessageBox.No, QMessageBox.No,
427 )
428 if ret != QMessageBox.Yes:
429 return
430
431 fresh = self._make_library(None) # live, un-frozen definitions
432 updated = self._library.update_symbols(fresh, names)
433 if updated:
434 self._library.inject_into_component_item()
435 for item in self._scene.items():
436 if isinstance(item, ComponentItem) and item.symbol_name in updated:
437 svg = self._library.svg_bytes(item.symbol_name)
438 if svg is not None:
439 item.reload_svg(svg)
440 self._scene._sync_junctions() # refresh pin/connection markers
441 self._dirty = True
442
443 missing = [n for n in names if n not in updated]
444 if missing:
445 QMessageBox.warning(
446 self, "Load symbols from library",
447 "These symbols were not found in the library and were left "
448 f"unchanged:\n\n {', '.join(missing)}",
449 )
450 elif updated:
451 QMessageBox.information(
452 self, "Load symbols from library",
453 f"Reloaded {len(updated)} symbol"
454 f"{'s' if len(updated) != 1 else ''} from the library.\n\n"
455 "Save the schematic to persist the updated symbol cache.",
456 )
457
458 def _on_update_symbols_from_library(self):
459 """Drop the whole frozen symbol cache and reload every symbol fresh from

Callers

nothing calls this directly

Calls 6

_make_libraryMethod · 0.95
update_symbolsMethod · 0.80
reload_svgMethod · 0.80
_sync_junctionsMethod · 0.80
svg_bytesMethod · 0.45

Tested by

no test coverage detected