Files
copydev-imposing-tool/app/dialogs/custom_size_dialog.py
Jules 202834a794 V3.6.0 — Demonter pages, masquage visuel, regles, bleeds, corrections
- Demonter les pages : couper en 2 sans reordonner (sous Delivretiser)
- Masquage visuel : selection au curseur sur l'apercu + plage de pages
- Regles horizontale/verticale en mm (menu Affichage)
- Fonds perdus : filigrane rouge pour visualiser les bleeds
- Reperes de coupe : marques a l'exterieur (page agrandie), 2 traits/coin
- Numerotation : couleur configurable via selecteur
- Decalage : Trim & Shift renomme en francais, creep -> chasse
- Recadrages multiples cumulatifs (plages differentes)
- Fix spinbox format personnalise (fleches aleatoires)
- Fix combo livret : option Automatique preservee

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 22:12:54 +02:00

111 lines
3.5 KiB
Python

"""Dialogue pour saisir un format personnalise."""
import os
import sys
import json
from PyQt6.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QLabel,
QDoubleSpinBox, QLineEdit, QDialogButtonBox,
QGroupBox, QCheckBox)
from app.engine.pdf_utils import mm_to_pt
CUSTOM_SIZES_FILE = os.path.join(
os.path.dirname(sys.executable) if getattr(sys, 'frozen', False)
else os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
".custom_sizes.json"
)
def load_custom_sizes():
"""Charger les formats personnalises sauvegardes."""
if not os.path.exists(CUSTOM_SIZES_FILE):
return {}
try:
with open(CUSTOM_SIZES_FILE, "r") as f:
return json.load(f)
except Exception:
return {}
def save_custom_sizes(sizes):
"""Sauvegarder les formats personnalises."""
try:
with open(CUSTOM_SIZES_FILE, "w") as f:
json.dump(sizes, f, indent=2)
except Exception:
pass
class CustomSizeDialog(QDialog):
"""Dialogue pour saisir une taille personnalisee."""
def __init__(self, save_mode=False, parent=None):
super().__init__(parent)
self.setWindowTitle("Ajouter un format" if save_mode else "Format personnalise")
self.setMinimumWidth(350)
self._save_mode = save_mode
self._setup_ui()
def _setup_ui(self):
layout = QVBoxLayout(self)
if self._save_mode:
name_layout = QHBoxLayout()
name_layout.addWidget(QLabel("Nom du format :"))
self.edit_name = QLineEdit()
self.edit_name.setPlaceholderText("ex: Carte de visite")
name_layout.addWidget(self.edit_name)
layout.addLayout(name_layout)
layout.addSpacing(10)
grp = QGroupBox("Dimensions (mm)")
gl = QHBoxLayout(grp)
gl.addWidget(QLabel("Largeur :"))
self.spin_w = QDoubleSpinBox()
self.spin_w.setRange(10, 5000)
self.spin_w.setValue(210)
self.spin_w.setSuffix(" mm")
self.spin_w.setDecimals(1)
self.spin_w.setSingleStep(1.0)
self.spin_w.setMinimumWidth(100)
gl.addWidget(self.spin_w)
gl.addWidget(QLabel("Hauteur :"))
self.spin_h = QDoubleSpinBox()
self.spin_h.setRange(10, 5000)
self.spin_h.setValue(297)
self.spin_h.setSuffix(" mm")
self.spin_h.setDecimals(1)
self.spin_h.setSingleStep(1.0)
self.spin_h.setMinimumWidth(100)
gl.addWidget(self.spin_h)
layout.addWidget(grp)
self.chk_landscape = QCheckBox("Paysage (inverser largeur/hauteur)")
layout.addWidget(self.chk_landscape)
buttons = QDialogButtonBox(
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
)
buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)
layout.addWidget(buttons)
def get_size(self):
"""Retourne (largeur, hauteur) en points."""
w = mm_to_pt(self.spin_w.value())
h = mm_to_pt(self.spin_h.value())
if self.chk_landscape.isChecked():
w, h = h, w
return (w, h)
def get_name(self):
if self._save_mode:
return self.edit_name.text().strip()
return f"{self.spin_w.value():.0f}x{self.spin_h.value():.0f}mm"
def get_size_mm(self):
w = self.spin_w.value()
h = self.spin_h.value()
if self.chk_landscape.isChecked():
w, h = h, w
return (w, h)