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

Class LatexFragmentDialog

SLiCAP/schematic/latex_fragment_dialog.py:44–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44class LatexFragmentDialog(QDialog):
45 _PREVIEW_MAX_W = 500
46 _PREVIEW_MAX_H = 250
47
48 def __init__(self, latex_code: str = "",
49 preamble_path: str = "",
50 svg_bytes: bytes | None = None,
51 display_width: int | None = None,
52 display_height: int | None = None,
53 parent=None):
54 super().__init__(parent, Qt.Window)
55 self.setWindowTitle("LaTeX Fragment")
56 self.setMinimumWidth(560)
57 self._svg_bytes: bytes | None = svg_bytes
58 self._natural_w: int | None = None
59 self._natural_h: int | None = None
60
61 outer = QVBoxLayout(self)
62 outer.setSizeConstraint(QLayout.SetMinimumSize)
63
64 # ── preamble row ──────────────────────────────────────────────────────
65 prow = QHBoxLayout()
66 prow.addWidget(QLabel("Preamble:"))
67 self._preamble_edit = QLineEdit(preamble_path or _find_slicap_preamble())
68 self._preamble_edit.setReadOnly(True)
69 self._preamble_edit.setPlaceholderText("(default: amsmath + amssymb)")
70 self._preamble_edit.setMinimumWidth(280)
71 browse_btn = QPushButton("Browse…")
72 browse_btn.clicked.connect(self._browse_preamble)
73 clear_btn = QPushButton("Clear")
74 clear_btn.clicked.connect(self._clear_preamble)
75 prow.addWidget(self._preamble_edit, stretch=1)
76 prow.addWidget(browse_btn)
77 prow.addWidget(clear_btn)
78 outer.addLayout(prow)
79
80 # ── code editor ───────────────────────────────────────────────────────
81 mono = QFont("Courier New", 10)
82 mono.setStyleHint(QFont.Monospace)
83 self._code_edit = QPlainTextEdit()
84 self._code_edit.setFont(mono)
85 self._code_edit.setMinimumHeight(130)
86 self._code_edit.setPlainText(latex_code)
87 outer.addWidget(self._code_edit)
88
89 # ── preview button + status ───────────────────────────────────────────
90 prev_row = QHBoxLayout()
91 self._prev_btn = QPushButton("Preview")
92 self._prev_btn.clicked.connect(self._render)
93 self._status_lbl = QLabel("")
94 self._status_lbl.setWordWrap(True)
95 prev_row.addWidget(self._prev_btn)
96 prev_row.addWidget(self._status_lbl, stretch=1)
97 outer.addLayout(prev_row)
98
99 # ── preview area ──────────────────────────────────────────────────────
100 self._preview_lbl = QLabel("(click Preview to render)")
101 self._preview_lbl.setAlignment(Qt.AlignCenter)

Callers 2

mouseDoubleClickEventMethod · 0.85
_on_place_latexMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected