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

Function print_scene

SLiCAP/schematic/export.py:685–787  ·  view source on GitHub ↗
(scene, parent=None)

Source from the content-addressed store, hash-verified

683
684
685def print_scene(scene, parent=None) -> None:
686 import os, tempfile
687 import cairosvg
688 from PySide6.QtPrintSupport import QPrinter, QPrintDialog
689 from PySide6.QtPdf import QPdfDocument
690 from PySide6.QtGui import QPainter
691 from PySide6.QtCore import QSize
692 from PySide6.QtWidgets import (
693 QDialog, QVBoxLayout, QHBoxLayout, QLabel,
694 QDoubleSpinBox, QCheckBox, QDialogButtonBox,
695 )
696
697 # ── step 1: printer / paper ───────────────────────────────────────────────
698 printer = QPrinter(QPrinter.HighResolution)
699 if QPrintDialog(printer, parent).exec() != QPrintDialog.Accepted:
700 return
701
702 # ── step 2: scale options ─────────────────────────────────────────────────
703 bounds = export_bounds(scene)
704 svg_w, svg_h = bounds.width(), bounds.height()
705
706 page_rect = QRectF(printer.pageRect(QPrinter.DevicePixel))
707 dpmm = printer.resolution() / 25.4
708 nat_w = svg_w / _SCENE_UNITS_PER_MM * dpmm
709 nat_h = svg_h / _SCENE_UNITS_PER_MM * dpmm
710
711 fit_pct = 0.0
712 if nat_w > 0 and nat_h > 0:
713 fit_pct = min(page_rect.width() / nat_w,
714 page_rect.height() / nat_h) * 100.0
715
716 from PySide6.QtCore import Qt
717 scale_dlg = QDialog(parent, Qt.Window)
718 scale_dlg.setWindowTitle("Print Scale")
719 vlay = QVBoxLayout(scale_dlg)
720
721 fit_cb = QCheckBox("Fit to page")
722 fit_cb.setChecked(True)
723 vlay.addWidget(fit_cb)
724
725 hlay = QHBoxLayout()
726 hlay.addWidget(QLabel("Scale:"))
727 scale_sb = QDoubleSpinBox()
728 scale_sb.setRange(10.0, 500.0)
729 scale_sb.setSingleStep(5.0)
730 scale_sb.setDecimals(1)
731 scale_sb.setSuffix(" %")
732 scale_sb.setValue(round(fit_pct, 1) if fit_pct > 0 else 100.0)
733 scale_sb.setEnabled(False)
734 hlay.addWidget(scale_sb)
735 if fit_pct > 0:
736 hlay.addWidget(QLabel(f"(fit = {fit_pct:.1f} %)"))
737 vlay.addLayout(hlay)
738
739 fit_cb.toggled.connect(lambda checked: scale_sb.setEnabled(not checked))
740
741 btns = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
742 btns.accepted.connect(scale_dlg.accept)

Callers 1

_on_printMethod · 0.85

Calls 4

export_boundsFunction · 0.85
_build_svgFunction · 0.85
writeMethod · 0.80
loadMethod · 0.80

Tested by

no test coverage detected