"""Dialogue Repetition (Step & Repeat).""" from PyQt6.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QGroupBox, QSpinBox, QCheckBox, QDialogButtonBox, QDoubleSpinBox) 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 StepRepeatDialog(QDialog): def __init__(self, parent=None): super().__init__(parent) self.setWindowTitle("Repetition (Step & Repeat)") self.setMinimumWidth(400) self._setup_ui() def _setup_ui(self): layout = QVBoxLayout(self) 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, "A3 Paysage") self.combo_sheet.activated.connect(lambda: handle_format_selection(self.combo_sheet, self)) sl.addWidget(self.combo_sheet) layout.addWidget(grp_sheet) grp_copies = QGroupBox("Nombre de copies") cl = QVBoxLayout(grp_copies) self.chk_auto = QCheckBox("Automatique (remplir la feuille)") self.chk_auto.setChecked(True) cl.addWidget(self.chk_auto) manual = QHBoxLayout() manual.addWidget(QLabel("Horizontal :")) self.spin_h = QSpinBox() self.spin_h.setRange(1, 20) self.spin_h.setValue(2) self.spin_h.setEnabled(False) manual.addWidget(self.spin_h) manual.addWidget(QLabel("Vertical :")) self.spin_v = QSpinBox() self.spin_v.setRange(1, 20) self.spin_v.setValue(2) self.spin_v.setEnabled(False) manual.addWidget(self.spin_v) cl.addLayout(manual) layout.addWidget(grp_copies) self.chk_auto.toggled.connect(lambda c: self.spin_h.setEnabled(not c)) self.chk_auto.toggled.connect(lambda c: self.spin_v.setEnabled(not c)) 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(0) spin.setSuffix(" mm") ml.addWidget(spin) self.margins[label.lower()] = spin layout.addWidget(grp_margins) grp_spacing = QGroupBox("Espacement entre copies (mm)") spl = QHBoxLayout(grp_spacing) spl.addWidget(QLabel("Horizontal :")) self.spin_sp_h = QDoubleSpinBox() self.spin_sp_h.setRange(0, 50) self.spin_sp_h.setValue(0) self.spin_sp_h.setSuffix(" mm") spl.addWidget(self.spin_sp_h) spl.addWidget(QLabel("Vertical :")) self.spin_sp_v = QDoubleSpinBox() self.spin_sp_v.setRange(0, 50) self.spin_sp_v.setValue(0) self.spin_sp_v.setSuffix(" mm") spl.addWidget(self.spin_sp_v) layout.addWidget(grp_spacing) self.chk_crop = QCheckBox("Reperes de coupe") layout.addWidget(self.chk_crop) buttons = QDialogButtonBox( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel ) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject) layout.addWidget(buttons) def get_settings(self): return { "sheet_size": get_selected_size(self.combo_sheet), "copies_h": None if self.chk_auto.isChecked() else self.spin_h.value(), "copies_v": None if self.chk_auto.isChecked() else self.spin_v.value(), "spacing_h": mm_to_pt(self.spin_sp_h.value()), "spacing_v": mm_to_pt(self.spin_sp_v.value()), "crop_marks": self.chk_crop.isChecked(), }