- 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>
111 lines
3.4 KiB
Python
111 lines
3.4 KiB
Python
"""ComboBox de formats de page avec support personnalise."""
|
|
|
|
from PyQt6.QtWidgets import QComboBox
|
|
from app.engine.pdf_utils import PAGE_SIZES, mm_to_pt
|
|
from app.dialogs.custom_size_dialog import (CustomSizeDialog, load_custom_sizes,
|
|
save_custom_sizes)
|
|
|
|
|
|
SEP = "---"
|
|
CUSTOM_LABEL = "Personnalise..."
|
|
ADD_LABEL = "Ajouter un format..."
|
|
|
|
|
|
def populate_format_combo(combo, default="A4 Paysage"):
|
|
"""Remplir un combo avec les formats standard + custom + options.
|
|
|
|
Si default n'est pas un format standard, il est conserve en tete du combo.
|
|
"""
|
|
combo.blockSignals(True)
|
|
|
|
# Sauvegarder l'item par defaut s'il n'est pas un format standard
|
|
keep_first = None
|
|
if default and default not in PAGE_SIZES:
|
|
# Verifier s'il est deja dans le combo avec des data
|
|
idx = combo.findText(default)
|
|
if idx >= 0:
|
|
keep_first = (default, combo.itemData(idx))
|
|
|
|
combo.clear()
|
|
|
|
# Re-ajouter l'item special en tete si necessaire
|
|
if keep_first:
|
|
combo.addItem(keep_first[0], keep_first[1])
|
|
combo.insertSeparator(combo.count())
|
|
|
|
# Formats standard
|
|
for name in PAGE_SIZES:
|
|
combo.addItem(name, PAGE_SIZES[name])
|
|
|
|
# Formats custom sauvegardes
|
|
custom = load_custom_sizes()
|
|
if custom:
|
|
combo.insertSeparator(combo.count())
|
|
for name, size in custom.items():
|
|
combo.addItem(name, (size[0], size[1]))
|
|
|
|
# Options speciales
|
|
combo.insertSeparator(combo.count())
|
|
combo.addItem(CUSTOM_LABEL, None)
|
|
combo.addItem(ADD_LABEL, None)
|
|
|
|
# Selectionner le defaut
|
|
idx = combo.findText(default)
|
|
if idx >= 0:
|
|
combo.setCurrentIndex(idx)
|
|
|
|
combo.blockSignals(False)
|
|
|
|
|
|
def handle_format_selection(combo, parent=None):
|
|
"""Gerer la selection dans le combo. Retourne (w, h) en points ou None si annule."""
|
|
text = combo.currentText()
|
|
|
|
if text == CUSTOM_LABEL:
|
|
dlg = CustomSizeDialog(save_mode=False, parent=parent)
|
|
if dlg.exec():
|
|
size = dlg.get_size()
|
|
name = dlg.get_name()
|
|
# Ajouter temporairement dans le combo
|
|
combo.blockSignals(True)
|
|
combo.insertItem(combo.count() - 3, name, size)
|
|
combo.setCurrentText(name)
|
|
combo.blockSignals(False)
|
|
return size
|
|
# Annule — revenir au precedent
|
|
combo.blockSignals(True)
|
|
combo.setCurrentIndex(0)
|
|
combo.blockSignals(False)
|
|
return None
|
|
|
|
elif text == ADD_LABEL:
|
|
dlg = CustomSizeDialog(save_mode=True, parent=parent)
|
|
if dlg.exec():
|
|
name = dlg.get_name()
|
|
if not name:
|
|
name = dlg.get_name()
|
|
size = dlg.get_size()
|
|
# Sauvegarder
|
|
custom = load_custom_sizes()
|
|
w_mm, h_mm = dlg.get_size_mm()
|
|
custom[name] = [mm_to_pt(w_mm), mm_to_pt(h_mm)]
|
|
save_custom_sizes(custom)
|
|
# Recharger le combo
|
|
populate_format_combo(combo, name)
|
|
return size
|
|
combo.blockSignals(True)
|
|
combo.setCurrentIndex(0)
|
|
combo.blockSignals(False)
|
|
return None
|
|
|
|
else:
|
|
return combo.currentData()
|
|
|
|
|
|
def get_selected_size(combo):
|
|
"""Obtenir la taille selectionnee. Retourne (w, h) en points."""
|
|
data = combo.currentData()
|
|
if data:
|
|
return data
|
|
return PAGE_SIZES.get(combo.currentText(), (595.28, 841.89))
|