Files
copydev-imposing-tool/app/dialogs/nup_dialog.py
Jules c9212a30ea V2.1.0 — Formats personnalises + reperes de coupe
- Formats personnalises dans tous les menus deroulants de format :
  - "Personnalise..." : saisie libre largeur x hauteur en mm
  - "Ajouter un format..." : sauvegarder un format custom (persistant)
  - Formats custom affiches dans le dropdown avec separateur
- Reperes de coupe (Annotations > Reperes de coupe) :
  - Longueur, distance du bord, epaisseur configurables
  - Couleur : noir, gris, CMYK
  - Reperes de centrage optionnels
  - Appliquer a : toutes, paires, impaires, page courante
  - Enlever les reperes de coupe (menu)
- Step & Repeat : ajout des marges (haut, bas, gauche, droite)
- Tous les dialogues de format migres vers format_combo

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 08:00:55 +01:00

123 lines
4.7 KiB
Python

"""Dialogue N pages par feuille."""
from PyQt6.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QLabel,
QComboBox, QGroupBox, QSpinBox, QCheckBox,
QDialogButtonBox, QDoubleSpinBox, QFileDialog,
QPushButton)
from app.engine.pdf_utils import mm_to_pt
from app.dialogs.format_combo import populate_format_combo, get_selected_size, handle_format_selection
class NupDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("N pages par feuille")
self.setMinimumWidth(450)
self._bg_path = None
self._setup_ui()
def _setup_ui(self):
layout = QVBoxLayout(self)
grp_grid = QGroupBox("Disposition")
gl = QHBoxLayout(grp_grid)
gl.addWidget(QLabel("Colonnes :"))
self.spin_cols = QSpinBox()
self.spin_cols.setRange(1, 10)
self.spin_cols.setValue(2)
gl.addWidget(self.spin_cols)
gl.addWidget(QLabel("Lignes :"))
self.spin_rows = QSpinBox()
self.spin_rows.setRange(1, 10)
self.spin_rows.setValue(2)
gl.addWidget(self.spin_rows)
layout.addWidget(grp_grid)
grp_sheet = QGroupBox("Taille de la feuille")
sl = QHBoxLayout(grp_sheet)
sl.addWidget(QLabel("Format :"))
self.combo_sheet = QComboBox()
populate_format_combo(self.combo_sheet, "A4 Paysage")
self.combo_sheet.activated.connect(lambda: handle_format_selection(self.combo_sheet, self))
sl.addWidget(self.combo_sheet)
layout.addWidget(grp_sheet)
grp_margins = QGroupBox("Marges (mm)")
ml = QHBoxLayout(grp_margins)
self.margins = {}
for label in ["Haut", "Bas", "Gauche", "Droite"]:
ml.addWidget(QLabel(f"{label}:"))
spin = QDoubleSpinBox()
spin.setRange(0, 100)
spin.setValue(5)
spin.setSuffix(" mm")
ml.addWidget(spin)
self.margins[label.lower()] = spin
layout.addWidget(grp_margins)
grp_gutter = QGroupBox("Gouttiere (mm)")
gutl = QHBoxLayout(grp_gutter)
gutl.addWidget(QLabel("Horizontale :"))
self.spin_gutter_h = QDoubleSpinBox()
self.spin_gutter_h.setRange(0, 50)
self.spin_gutter_h.setValue(0)
self.spin_gutter_h.setSuffix(" mm")
gutl.addWidget(self.spin_gutter_h)
gutl.addWidget(QLabel("Verticale :"))
self.spin_gutter_v = QDoubleSpinBox()
self.spin_gutter_v.setRange(0, 50)
self.spin_gutter_v.setValue(0)
self.spin_gutter_v.setSuffix(" mm")
gutl.addWidget(self.spin_gutter_v)
layout.addWidget(grp_gutter)
grp_opts = QGroupBox("Options")
ol = QVBoxLayout(grp_opts)
self.chk_fit = QCheckBox("Ajuster les pages a la cellule")
self.chk_fit.setChecked(True)
ol.addWidget(self.chk_fit)
self.chk_crop = QCheckBox("Reperes de coupe")
ol.addWidget(self.chk_crop)
bg_layout = QHBoxLayout()
self.chk_bg = QCheckBox("Fond PDF :")
bg_layout.addWidget(self.chk_bg)
self.lbl_bg = QLabel("Aucun")
bg_layout.addWidget(self.lbl_bg)
btn_bg = QPushButton("Choisir...")
btn_bg.clicked.connect(self._choose_bg)
bg_layout.addWidget(btn_bg)
bg_layout.addStretch()
ol.addLayout(bg_layout)
layout.addWidget(grp_opts)
buttons = QDialogButtonBox(
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
)
buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)
layout.addWidget(buttons)
def _choose_bg(self):
path, _ = QFileDialog.getOpenFileName(self, "Choisir un fond PDF", "", "PDF (*.pdf)")
if path:
self._bg_path = path
self.lbl_bg.setText(path.split("/")[-1].split("\\")[-1])
self.chk_bg.setChecked(True)
def get_settings(self):
return {
"cols": self.spin_cols.value(),
"rows": self.spin_rows.value(),
"sheet_size": get_selected_size(self.combo_sheet),
"margin_top": mm_to_pt(self.margins["haut"].value()),
"margin_bottom": mm_to_pt(self.margins["bas"].value()),
"margin_left": mm_to_pt(self.margins["gauche"].value()),
"margin_right": mm_to_pt(self.margins["droite"].value()),
"gutter_h": mm_to_pt(self.spin_gutter_h.value()),
"gutter_v": mm_to_pt(self.spin_gutter_v.value()),
"scale_mode": "fit" if self.chk_fit.isChecked() else "none",
"crop_marks": self.chk_crop.isChecked(),
"background_path": self._bg_path if self.chk_bg.isChecked() else None,
}