generated from LouisMazin/PythonApplicationTemplate
80 lines
3.3 KiB
Python
80 lines
3.3 KiB
Python
from PyQt6.QtWidgets import QMessageBox
|
|
from typing import Optional
|
|
|
|
class AlertManager:
|
|
|
|
def __init__(self, language_manager, theme_manager) -> None:
|
|
self.language_manager = language_manager
|
|
self.theme_manager = theme_manager
|
|
|
|
def show_info(self, info_text: str, parent=None) -> None:
|
|
info_title = self.language_manager.get_text("information")
|
|
|
|
QMessageBox.information(parent, info_title, info_text)
|
|
|
|
def show_success(self, success_key: str, parent=None) -> None:
|
|
success_title = self.language_manager.get_text("success")
|
|
success_text = self.language_manager.get_text(success_key)
|
|
|
|
QMessageBox.information(parent, success_title, success_text)
|
|
|
|
def show_error(self, error_key: str, parent=None) -> None:
|
|
|
|
error_title = self.language_manager.get_text("error")
|
|
error_text = self.language_manager.get_text(error_key)
|
|
|
|
QMessageBox.critical(parent, error_title, error_text)
|
|
|
|
def show_choice(self, message: str, parent=None) -> bool:
|
|
"""
|
|
Affiche une boîte de dialogue Oui/Non.
|
|
Si detailed_text est fourni, l'ajoute comme texte détaillé (affichable par l'utilisateur).
|
|
"""
|
|
box = QMessageBox(parent)
|
|
box.setWindowTitle(self.language_manager.get_text("confirmation"))
|
|
box.setText(message)
|
|
box.setIcon(QMessageBox.Icon.Question)
|
|
yes = box.addButton(QMessageBox.StandardButton.Yes)
|
|
no = box.addButton(QMessageBox.StandardButton.No)
|
|
yes.setText(self.language_manager.get_text("yes"))
|
|
no.setText(self.language_manager.get_text("no"))
|
|
box.setDefaultButton(yes)
|
|
box.exec()
|
|
return box.clickedButton() == yes
|
|
|
|
def show_choice_with_details(self, message: str, parent=None, details_callback=None) -> bool:
|
|
"""
|
|
Affiche une boîte de dialogue Oui/Non avec un bouton Détails.
|
|
Si detailed_text est fourni, l'ajoute comme texte détaillé (affichable par l'utilisateur).
|
|
Le callback details_callback est appelé lorsque l'utilisateur clique sur le bouton Détails.
|
|
"""
|
|
box = QMessageBox(parent)
|
|
box.setWindowTitle(self.language_manager.get_text("confirmation"))
|
|
box.setText(message)
|
|
box.setIcon(QMessageBox.Icon.Question)
|
|
yes = box.addButton(QMessageBox.StandardButton.Yes)
|
|
no = box.addButton(QMessageBox.StandardButton.No)
|
|
details = box.addButton(self.language_manager.get_text("details"), QMessageBox.ButtonRole.ActionRole)
|
|
yes.setText(self.language_manager.get_text("yes"))
|
|
no.setText(self.language_manager.get_text("no"))
|
|
box.setDefaultButton(yes)
|
|
|
|
def on_button_clicked(button):
|
|
if button == details and details_callback:
|
|
box.setResult(QMessageBox.StandardButton.NoButton)
|
|
details_callback()
|
|
if not box.isVisible():
|
|
box.show()
|
|
|
|
box.buttonClicked.connect(on_button_clicked)
|
|
|
|
while True:
|
|
box.exec()
|
|
clicked_button = box.clickedButton()
|
|
|
|
# Si c'est le bouton détails, on continue la boucle sans fermer
|
|
if clicked_button == details:
|
|
continue
|
|
# Sinon, on sort de la boucle et retourne le résultat
|
|
else:
|
|
return clicked_button == yes |