Outil d'imposition PDF desktop (PyQt6) remplacant Quite Imposing Plus. 9 fonctions : livret, n-up, step & repeat, imposition manuelle, jointure pages, pages blanches, numerotation, masquage, fonds perdus. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
113 lines
3.6 KiB
Python
113 lines
3.6 KiB
Python
"""Dialogue Masquage (rectangles blancs)."""
|
|
|
|
from PyQt6.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QLabel,
|
|
QGroupBox, QComboBox, QDoubleSpinBox,
|
|
QDialogButtonBox, QPushButton, QListWidget,
|
|
QListWidgetItem)
|
|
from app.engine.pdf_utils import mm_to_pt
|
|
|
|
|
|
class MaskingDialog(QDialog):
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self.setWindowTitle("Masquage (ruban blanc)")
|
|
self.setMinimumWidth(450)
|
|
self._rectangles = []
|
|
self._setup_ui()
|
|
|
|
def _setup_ui(self):
|
|
layout = QVBoxLayout(self)
|
|
|
|
# Definition rectangle
|
|
grp_rect = QGroupBox("Definir un rectangle de masquage (mm)")
|
|
rl = QHBoxLayout(grp_rect)
|
|
|
|
rl.addWidget(QLabel("X:"))
|
|
self.spin_x = QDoubleSpinBox()
|
|
self.spin_x.setRange(0, 1000)
|
|
self.spin_x.setSuffix(" mm")
|
|
rl.addWidget(self.spin_x)
|
|
|
|
rl.addWidget(QLabel("Y:"))
|
|
self.spin_y = QDoubleSpinBox()
|
|
self.spin_y.setRange(0, 1000)
|
|
self.spin_y.setSuffix(" mm")
|
|
rl.addWidget(self.spin_y)
|
|
|
|
rl.addWidget(QLabel("L:"))
|
|
self.spin_w = QDoubleSpinBox()
|
|
self.spin_w.setRange(1, 1000)
|
|
self.spin_w.setValue(50)
|
|
self.spin_w.setSuffix(" mm")
|
|
rl.addWidget(self.spin_w)
|
|
|
|
rl.addWidget(QLabel("H:"))
|
|
self.spin_h = QDoubleSpinBox()
|
|
self.spin_h.setRange(1, 1000)
|
|
self.spin_h.setValue(10)
|
|
self.spin_h.setSuffix(" mm")
|
|
rl.addWidget(self.spin_h)
|
|
|
|
layout.addWidget(grp_rect)
|
|
|
|
# Boutons ajouter/supprimer
|
|
btn_layout = QHBoxLayout()
|
|
btn_add = QPushButton("Ajouter")
|
|
btn_add.clicked.connect(self._add_rect)
|
|
btn_layout.addWidget(btn_add)
|
|
btn_del = QPushButton("Supprimer")
|
|
btn_del.clicked.connect(self._del_rect)
|
|
btn_layout.addWidget(btn_del)
|
|
btn_layout.addStretch()
|
|
layout.addLayout(btn_layout)
|
|
|
|
# Liste des rectangles
|
|
self.list_rects = QListWidget()
|
|
layout.addWidget(self.list_rects)
|
|
|
|
# Appliquer a
|
|
grp_apply = QGroupBox("Appliquer a")
|
|
al = QHBoxLayout(grp_apply)
|
|
self.combo_apply = QComboBox()
|
|
self.combo_apply.addItems(["Toutes les pages", "Pages paires", "Pages impaires"])
|
|
al.addWidget(self.combo_apply)
|
|
layout.addWidget(grp_apply)
|
|
|
|
# Boutons
|
|
buttons = QDialogButtonBox(
|
|
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
|
|
)
|
|
buttons.accepted.connect(self.accept)
|
|
buttons.rejected.connect(self.reject)
|
|
layout.addWidget(buttons)
|
|
|
|
def _add_rect(self):
|
|
rect = {
|
|
"x": mm_to_pt(self.spin_x.value()),
|
|
"y": mm_to_pt(self.spin_y.value()),
|
|
"width": mm_to_pt(self.spin_w.value()),
|
|
"height": mm_to_pt(self.spin_h.value()),
|
|
}
|
|
self._rectangles.append(rect)
|
|
self.list_rects.addItem(
|
|
f"X={self.spin_x.value():.1f} Y={self.spin_y.value():.1f} "
|
|
f"L={self.spin_w.value():.1f} H={self.spin_h.value():.1f} mm"
|
|
)
|
|
|
|
def _del_rect(self):
|
|
row = self.list_rects.currentRow()
|
|
if row >= 0:
|
|
self.list_rects.takeItem(row)
|
|
self._rectangles.pop(row)
|
|
|
|
def get_settings(self):
|
|
apply_map = {
|
|
"Toutes les pages": "all",
|
|
"Pages paires": "even",
|
|
"Pages impaires": "odd"
|
|
}
|
|
return {
|
|
"rectangles": self._rectangles,
|
|
"apply_to": apply_map[self.combo_apply.currentText()],
|
|
}
|