Dialog for placing or editing an image on the schematic. A single Scale % spinbox controls the display size relative to the image's natural pixel dimensions. Width and Height in scene units are shown as read-only feedback.
| 17 | |
| 18 | |
| 19 | class ImageDialog(QDialog): |
| 20 | """ |
| 21 | Dialog for placing or editing an image on the schematic. |
| 22 | |
| 23 | A single Scale % spinbox controls the display size relative to the |
| 24 | image's natural pixel dimensions. Width and Height in scene units |
| 25 | are shown as read-only feedback. |
| 26 | """ |
| 27 | |
| 28 | def __init__(self, file_path: str = "", display_width: int = 200, |
| 29 | display_height: int = 200, parent=None): |
| 30 | super().__init__(parent, Qt.Window) |
| 31 | self.setWindowTitle("Image") |
| 32 | self._natural_w: int | None = None |
| 33 | self._natural_h: int | None = None |
| 34 | |
| 35 | outer = QVBoxLayout() |
| 36 | outer.setSizeConstraint(QLayout.SetFixedSize) |
| 37 | self.setLayout(outer) |
| 38 | |
| 39 | # ── file picker ─────────────────────────────────────────────────────── |
| 40 | file_row = QHBoxLayout() |
| 41 | self._path_edit = QLineEdit(file_path) |
| 42 | self._path_edit.setReadOnly(True) |
| 43 | self._path_edit.setMinimumWidth(300) |
| 44 | browse_btn = QPushButton("Browse…") |
| 45 | browse_btn.clicked.connect(self._browse) |
| 46 | file_row.addWidget(self._path_edit) |
| 47 | file_row.addWidget(browse_btn) |
| 48 | outer.addLayout(file_row) |
| 49 | |
| 50 | # ── scale row ───────────────────────────────────────────────────────── |
| 51 | from .config import SCALE_IMAGE |
| 52 | # For an existing image, load natural size and back-calculate scale. |
| 53 | if file_path: |
| 54 | self._load_natural_size(file_path) |
| 55 | if self._natural_w and self._natural_w > 0: |
| 56 | init_scale = max(1, round(display_width / self._natural_w * 100)) |
| 57 | else: |
| 58 | init_scale = SCALE_IMAGE |
| 59 | |
| 60 | scale_row = QHBoxLayout() |
| 61 | scale_row.addWidget(QLabel("Scale:")) |
| 62 | self._scale_spin = QSpinBox() |
| 63 | self._scale_spin.setRange(1, 1000) |
| 64 | self._scale_spin.setValue(init_scale) |
| 65 | self._scale_spin.setSuffix(" %") |
| 66 | scale_row.addWidget(self._scale_spin) |
| 67 | scale_row.addSpacing(16) |
| 68 | self._size_lbl = QLabel() |
| 69 | scale_row.addWidget(self._size_lbl) |
| 70 | scale_row.addSpacing(10) |
| 71 | hint = QLabel("(1 grid square = 5 units, resistor pin-to-pin = 50 units)") |
| 72 | hint.setStyleSheet("color: grey; font-size: 9pt;") |
| 73 | scale_row.addWidget(hint) |
| 74 | scale_row.addStretch(1) |
| 75 | outer.addLayout(scale_row) |
| 76 |
no outgoing calls
no test coverage detected