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

Class LibraryItem

SLiCAP/schematic/library_item.py:9–61  ·  view source on GitHub ↗

A .lib / .inc reference on the canvas. Displays the directive and filename on the schematic; the full path is written to the netlist. Double-click opens the library link dialog. Attributes ---------- directive : "lib" or "inc" simulator : "SLiCAP" or "SPICE" cor

Source from the content-addressed store, hash-verified

7
8
9class LibraryItem(QGraphicsTextItem):
10 """
11 A .lib / .inc reference on the canvas.
12
13 Displays the directive and filename on the schematic; the full path is
14 written to the netlist. Double-click opens the library link dialog.
15
16 Attributes
17 ----------
18 directive : "lib" or "inc"
19 simulator : "SLiCAP" or "SPICE"
20 corner : SPICE corner string (only used for SPICE .lib)
21 """
22
23 def __init__(self, file_path: str, pos: QPointF = QPointF(0, 0),
24 directive: str = "lib", simulator: str = "SLiCAP",
25 corner: str = ""):
26 super().__init__()
27 self.file_path: str = file_path
28 self.directive: str = directive # "lib" or "inc"
29 self.simulator: str = simulator # "SLiCAP" or "SPICE"
30 self.corner: str = corner
31 self._update_text()
32 self.setPos(pos)
33 self.setFont(COMMAND_FONT)
34 self.setDefaultTextColor(COMMAND_COLOR)
35 self.setFlag(QGraphicsItem.ItemIsSelectable)
36 self.setFlag(QGraphicsItem.ItemIsMovable)
37 self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
38 self.setTextInteractionFlags(Qt.NoTextInteraction)
39
40 def _update_text(self) -> None:
41 name = Path(self.file_path).name if self.file_path else ""
42 if self.corner:
43 self.setPlainText(f".{self.directive} {name} {self.corner}")
44 else:
45 self.setPlainText(f".{self.directive} {name}")
46 self.setToolTip(self.file_path)
47
48 def netlist_line(self) -> str:
49 """Return the netlist line for this library link."""
50 path = self.file_path
51 if " " in path:
52 path = f'"{path}"'
53 parts = [f".{self.directive}", path]
54 if self.corner:
55 parts.append(self.corner)
56 return " ".join(parts)
57
58 def itemChange(self, change, value):
59 if change == QGraphicsItem.ItemPositionChange:
60 return snap(value)
61 return super().itemChange(change, value)

Callers 3

from_dataMethod · 0.85
mousePressEventMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected