Update standard dialog boxes

This commit is contained in:
Veronica Berglyd Olsen
2025-10-25 21:38:30 +02:00
parent 096686457d
commit bb1d90213b
3 changed files with 42 additions and 15 deletions
+1
View File
@@ -262,3 +262,4 @@ class nwStandardButton(Enum):
LIST = 7 LIST = 7
NEW = 8 NEW = 8
CREATE = 9 CREATE = 9
RESET = 10
+11 -10
View File
@@ -57,16 +57,17 @@ STYLES_MIN_TOOLBUTTON = "minimalToolButton"
STYLES_BIG_TOOLBUTTON = "bigToolButton" STYLES_BIG_TOOLBUTTON = "bigToolButton"
STANDARD_BUTTONS = { STANDARD_BUTTONS = {
nwStandardButton.OK: (QT_TRANSLATE_NOOP("Button", "OK"), "bullet-on", "blue"), nwStandardButton.OK: (QT_TRANSLATE_NOOP("Button", "OK"), "btn_ok", "blue"),
nwStandardButton.CANCEL: (QT_TRANSLATE_NOOP("Button", "Cancel"), "cancel", "red"), nwStandardButton.CANCEL: (QT_TRANSLATE_NOOP("Button", "Cancel"), "btn_cancel", "red"),
nwStandardButton.YES: (QT_TRANSLATE_NOOP("Button", "Yes"), "bullet-on", "green"), nwStandardButton.YES: (QT_TRANSLATE_NOOP("Button", "Yes"), "btn_yes", "green"),
nwStandardButton.NO: (QT_TRANSLATE_NOOP("Button", "No"), "bullet-on", "red"), nwStandardButton.NO: (QT_TRANSLATE_NOOP("Button", "No"), "btn_no", "red"),
nwStandardButton.OPEN: (QT_TRANSLATE_NOOP("Button", "Open"), "open", "blue"), nwStandardButton.OPEN: (QT_TRANSLATE_NOOP("Button", "Open"), "btn_open", "blue"),
nwStandardButton.CLOSE: (QT_TRANSLATE_NOOP("Button", "Close"), "close", "default"), nwStandardButton.CLOSE: (QT_TRANSLATE_NOOP("Button", "Close"), "btn_close", "red"),
nwStandardButton.BROWSE: (QT_TRANSLATE_NOOP("Button", "Browse"), "browse", "yellow"), nwStandardButton.BROWSE: (QT_TRANSLATE_NOOP("Button", "Browse"), "btn_browse", "yellow"),
nwStandardButton.LIST: (QT_TRANSLATE_NOOP("Button", "List"), "list", "blue"), nwStandardButton.LIST: (QT_TRANSLATE_NOOP("Button", "List"), "btn_list", "blue"),
nwStandardButton.NEW: (QT_TRANSLATE_NOOP("Button", "New"), "add", "green"), nwStandardButton.NEW: (QT_TRANSLATE_NOOP("Button", "New"), "btn_new", "green"),
nwStandardButton.CREATE: (QT_TRANSLATE_NOOP("Button", "Create"), "star", "yellow"), nwStandardButton.CREATE: (QT_TRANSLATE_NOOP("Button", "Create"), "btn_create", "yellow"),
nwStandardButton.RESET: (QT_TRANSLATE_NOOP("Button", "Reset"), "btn_reset", "green"),
} }
+30 -5
View File
@@ -34,12 +34,12 @@ from typing import TYPE_CHECKING, TypeVar
from PyQt6.QtCore import QObject, QRunnable, QThreadPool, QTimer, QUrl, pyqtSignal, pyqtSlot from PyQt6.QtCore import QObject, QRunnable, QThreadPool, QTimer, QUrl, pyqtSignal, pyqtSlot
from PyQt6.QtGui import QDesktopServices, QFont, QScreen from PyQt6.QtGui import QDesktopServices, QFont, QScreen
from PyQt6.QtWidgets import QApplication, QFileDialog, QFontDialog, QMessageBox, QWidget from PyQt6.QtWidgets import QApplication, QDialog, QFileDialog, QFontDialog, QMessageBox, QWidget
from novelwriter.common import formatFileFilter from novelwriter.common import formatFileFilter
from novelwriter.constants import nwFiles from novelwriter.constants import nwFiles
from novelwriter.core.spellcheck import NWSpellEnchant from novelwriter.core.spellcheck import NWSpellEnchant
from novelwriter.enum import nwChange, nwItemClass from novelwriter.enum import nwChange, nwItemClass, nwStandardButton
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import Callable from collections.abc import Callable
@@ -422,7 +422,7 @@ class SharedData(QObject):
alert.setAlertType(_GuiAlert.WARN if warn else _GuiAlert.ASK, True) alert.setAlertType(_GuiAlert.WARN if warn else _GuiAlert.ASK, True)
self._lastAlert = alert.logMessage self._lastAlert = alert.logMessage
alert.exec() alert.exec()
return alert.result() == QMessageBox.StandardButton.Yes return alert.finalState
## ##
# Internal Functions # Internal Functions
@@ -469,6 +469,7 @@ class _GuiAlert(QMessageBox):
super().__init__(parent=parent) super().__init__(parent=parent)
self._theme = theme self._theme = theme
self._message = "" self._message = ""
self._state = False
logger.debug("Ready: _GuiAlert") logger.debug("Ready: _GuiAlert")
def __del__(self) -> None: # pragma: no cover def __del__(self) -> None: # pragma: no cover
@@ -478,6 +479,10 @@ class _GuiAlert(QMessageBox):
def logMessage(self) -> str: def logMessage(self) -> str:
return self._message return self._message
@property
def finalState(self) -> bool:
return self._state
def setMessage(self, text: str, info: str, details: str) -> None: def setMessage(self, text: str, info: str, details: str) -> None:
"""Set the alert box message.""" """Set the alert box message."""
self._message = " ".join(filter(None, [text, info, details])) self._message = " ".join(filter(None, [text, info, details]))
@@ -496,9 +501,17 @@ class _GuiAlert(QMessageBox):
Yes/No buttons or just an Ok button. Yes/No buttons or just an Ok button.
""" """
if isYesNo: if isYesNo:
self.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) self._btnYes = self._theme.getStandardButton(nwStandardButton.YES, self)
self._btnYes.clicked.connect(self._onAccept)
self._btnNo = self._theme.getStandardButton(nwStandardButton.NO, self)
self._btnNo.clicked.connect(self._onReject)
self.addButton(self._btnYes, QMessageBox.ButtonRole.YesRole)
self.addButton(self._btnNo, QMessageBox.ButtonRole.NoRole)
else: else:
self.setStandardButtons(QMessageBox.StandardButton.Ok) self._btnOk = self._theme.getStandardButton(nwStandardButton.OK, self)
self._btnOk.clicked.connect(self._onAccept)
self.addButton(self._btnOk, QMessageBox.ButtonRole.AcceptRole)
pSz = 2*self._theme.baseIconHeight pSz = 2*self._theme.baseIconHeight
if level == self.INFO: if level == self.INFO:
self.setIconPixmap(self._theme.getPixmap("alert_info", (pSz, pSz), "blue")) self.setIconPixmap(self._theme.getPixmap("alert_info", (pSz, pSz), "blue"))
@@ -512,3 +525,15 @@ class _GuiAlert(QMessageBox):
elif level == self.ASK: elif level == self.ASK:
self.setIconPixmap(self._theme.getPixmap("alert_question", (pSz, pSz), "blue")) self.setIconPixmap(self._theme.getPixmap("alert_question", (pSz, pSz), "blue"))
self.setWindowTitle(self.tr("Question")) self.setWindowTitle(self.tr("Question"))
@pyqtSlot()
def _onAccept(self) -> None:
"""Process accepted state."""
self._state = True
self.close()
@pyqtSlot()
def _onReject(self) -> None:
"""Process rejected state."""
self._state = False
self.setResult(QDialog.DialogCode.Rejected)