Update standard dialog boxes
This commit is contained in:
+30
-5
@@ -34,12 +34,12 @@ from typing import TYPE_CHECKING, TypeVar
|
||||
|
||||
from PyQt6.QtCore import QObject, QRunnable, QThreadPool, QTimer, QUrl, pyqtSignal, pyqtSlot
|
||||
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.constants import nwFiles
|
||||
from novelwriter.core.spellcheck import NWSpellEnchant
|
||||
from novelwriter.enum import nwChange, nwItemClass
|
||||
from novelwriter.enum import nwChange, nwItemClass, nwStandardButton
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
@@ -422,7 +422,7 @@ class SharedData(QObject):
|
||||
alert.setAlertType(_GuiAlert.WARN if warn else _GuiAlert.ASK, True)
|
||||
self._lastAlert = alert.logMessage
|
||||
alert.exec()
|
||||
return alert.result() == QMessageBox.StandardButton.Yes
|
||||
return alert.finalState
|
||||
|
||||
##
|
||||
# Internal Functions
|
||||
@@ -469,6 +469,7 @@ class _GuiAlert(QMessageBox):
|
||||
super().__init__(parent=parent)
|
||||
self._theme = theme
|
||||
self._message = ""
|
||||
self._state = False
|
||||
logger.debug("Ready: _GuiAlert")
|
||||
|
||||
def __del__(self) -> None: # pragma: no cover
|
||||
@@ -478,6 +479,10 @@ class _GuiAlert(QMessageBox):
|
||||
def logMessage(self) -> str:
|
||||
return self._message
|
||||
|
||||
@property
|
||||
def finalState(self) -> bool:
|
||||
return self._state
|
||||
|
||||
def setMessage(self, text: str, info: str, details: str) -> None:
|
||||
"""Set the alert box message."""
|
||||
self._message = " ".join(filter(None, [text, info, details]))
|
||||
@@ -496,9 +501,17 @@ class _GuiAlert(QMessageBox):
|
||||
Yes/No buttons or just an Ok button.
|
||||
"""
|
||||
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:
|
||||
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
|
||||
if level == self.INFO:
|
||||
self.setIconPixmap(self._theme.getPixmap("alert_info", (pSz, pSz), "blue"))
|
||||
@@ -512,3 +525,15 @@ class _GuiAlert(QMessageBox):
|
||||
elif level == self.ASK:
|
||||
self.setIconPixmap(self._theme.getPixmap("alert_question", (pSz, pSz), "blue"))
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user