Update preferences dialog and quotes selection dialog
This commit is contained in:
@@ -56,6 +56,9 @@ class nwConst:
|
||||
# Gui Settings
|
||||
STATUS_MSG_TIMEOUT = 15000 # milliseconds
|
||||
|
||||
# Dialogs
|
||||
DLG_FINISHED = 2
|
||||
|
||||
# END Class nwConst
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ from PyQt5.QtWidgets import (
|
||||
)
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.constants import nwConst, nwUnicode
|
||||
from novelwriter.dialogs.quotes import GuiQuoteSelect
|
||||
from novelwriter.extensions.switch import NSwitch
|
||||
from novelwriter.extensions.configlayout import NScrollableForm
|
||||
@@ -498,7 +499,7 @@ class GuiPreferences(QDialog):
|
||||
for tag, language in SHARED.spelling.listDictionaries():
|
||||
self.spellLanguage.addItem(language, tag)
|
||||
else:
|
||||
self.spellLanguage.addItem(self.tr("None"), "")
|
||||
self.spellLanguage.addItem(nwUnicode.U_EMDASH, "")
|
||||
self.spellLanguage.setEnabled(False)
|
||||
|
||||
if (idx := self.spellLanguage.findData(CONFIG.spellLanguage)) != -1:
|
||||
@@ -807,12 +808,13 @@ class GuiPreferences(QDialog):
|
||||
self._saveWindowSize()
|
||||
event.accept()
|
||||
qApp.processEvents()
|
||||
self.done(nwConst.DLG_FINISHED)
|
||||
self.deleteLater()
|
||||
return
|
||||
|
||||
def keyPressEvent(self, event: QKeyEvent) -> None:
|
||||
"""Overload keyPressEvent to block enter key to save."""
|
||||
if event.matches(QKeySequence.Cancel):
|
||||
if event.matches(QKeySequence.StandardKey.Cancel):
|
||||
self.close()
|
||||
event.ignore()
|
||||
return
|
||||
@@ -825,12 +827,12 @@ class GuiPreferences(QDialog):
|
||||
def _dialogButtonClicked(self, button: QAbstractButton) -> None:
|
||||
"""Handle button clicks from the dialog button box."""
|
||||
role = self.buttonBox.buttonRole(button)
|
||||
if role == QDialogButtonBox.ApplyRole:
|
||||
if role == QDialogButtonBox.ButtonRole.ApplyRole:
|
||||
self._saveValues()
|
||||
elif role == QDialogButtonBox.AcceptRole:
|
||||
elif role == QDialogButtonBox.ButtonRole.AcceptRole:
|
||||
self._saveValues()
|
||||
self.close()
|
||||
elif role == QDialogButtonBox.RejectRole:
|
||||
elif role == QDialogButtonBox.ButtonRole.RejectRole:
|
||||
self.close()
|
||||
return
|
||||
|
||||
@@ -874,7 +876,7 @@ class GuiPreferences(QDialog):
|
||||
def _backupFolder(self) -> None:
|
||||
"""Open a dialog to select the backup folder."""
|
||||
if path := QFileDialog.getExistingDirectory(
|
||||
self, self.tr("Backup Directory"), str(self.backupPath or ""),
|
||||
self, self.tr("Backup Directory"), str(self.backupPath) or "",
|
||||
options=QFileDialog.ShowDirsOnly
|
||||
):
|
||||
self.backupPath = path
|
||||
@@ -906,9 +908,9 @@ class GuiPreferences(QDialog):
|
||||
|
||||
def _getQuote(self, qType: str) -> None:
|
||||
"""Dialog for single quote open."""
|
||||
quote = GuiQuoteSelect(self, currentQuote=self.quoteSym[qType].text())
|
||||
if quote.exec_() == QDialog.Accepted:
|
||||
self.quoteSym[qType].setText(quote.selectedQuote)
|
||||
quote, status = GuiQuoteSelect.getQuote(self, current=self.quoteSym[qType].text())
|
||||
if status:
|
||||
self.quoteSym[qType].setText(quote)
|
||||
return
|
||||
|
||||
##
|
||||
|
||||
@@ -25,7 +25,7 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from PyQt5.QtGui import QCloseEvent, QFontMetrics
|
||||
from PyQt5.QtGui import QFontMetrics
|
||||
from PyQt5.QtCore import QSize, Qt, pyqtSlot
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialog, QDialogButtonBox, QFrame, QHBoxLayout, QLabel, QListWidget,
|
||||
@@ -40,11 +40,11 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class GuiQuoteSelect(QDialog):
|
||||
|
||||
selectedQuote = ""
|
||||
_selected = ""
|
||||
|
||||
D_KEY = Qt.ItemDataRole.UserRole
|
||||
|
||||
def __init__(self, parent: QWidget, currentQuote: str = '"') -> None:
|
||||
def __init__(self, parent: QWidget, current: str = '"') -> None:
|
||||
super().__init__(parent=parent)
|
||||
|
||||
logger.debug("Create: GuiQuoteSelect")
|
||||
@@ -54,7 +54,7 @@ class GuiQuoteSelect(QDialog):
|
||||
self.innerBox = QHBoxLayout()
|
||||
self.labelBox = QVBoxLayout()
|
||||
|
||||
self.selectedQuote = currentQuote
|
||||
self._selected = current
|
||||
|
||||
qMetrics = QFontMetrics(self.font())
|
||||
pxW = 7*qMetrics.boundingRectChar("M").width()
|
||||
@@ -65,7 +65,7 @@ class GuiQuoteSelect(QDialog):
|
||||
lblFont.setPointSizeF(4*lblFont.pointSizeF())
|
||||
|
||||
# Preview Label
|
||||
self.previewLabel = QLabel(currentQuote)
|
||||
self.previewLabel = QLabel(current)
|
||||
self.previewLabel.setFont(lblFont)
|
||||
self.previewLabel.setFixedSize(QSize(pxW, pxH))
|
||||
self.previewLabel.setAlignment(Qt.AlignCenter)
|
||||
@@ -82,7 +82,7 @@ class GuiQuoteSelect(QDialog):
|
||||
qtItem = QListWidgetItem(theText)
|
||||
qtItem.setData(self.D_KEY, sKey)
|
||||
self.listBox.addItem(qtItem)
|
||||
if sKey == currentQuote:
|
||||
if sKey == current:
|
||||
self.listBox.setCurrentItem(qtItem)
|
||||
|
||||
self.listBox.setMinimumWidth(minSize + CONFIG.pxInt(40))
|
||||
@@ -113,15 +113,20 @@ class GuiQuoteSelect(QDialog):
|
||||
logger.debug("Delete: GuiQuoteSelect")
|
||||
return
|
||||
|
||||
##
|
||||
# Events
|
||||
##
|
||||
@property
|
||||
def selectedQuote(self) -> str:
|
||||
"""Return the selected quote symbol."""
|
||||
return self._selected
|
||||
|
||||
def closeEvent(self, event: QCloseEvent) -> None:
|
||||
"""Capture the close event and perform cleanup."""
|
||||
event.accept()
|
||||
self.deleteLater()
|
||||
return
|
||||
@classmethod
|
||||
def getQuote(cls, parent: QWidget, current: str = "") -> tuple[str, bool]:
|
||||
"""Pop the dialog and return the result."""
|
||||
cls = GuiQuoteSelect(parent, current=current)
|
||||
cls.exec_()
|
||||
quote = cls._selected
|
||||
accepted = cls.result() == QDialog.DialogCode.Accepted
|
||||
cls.deleteLater()
|
||||
return quote, accepted
|
||||
|
||||
##
|
||||
# Private Slots
|
||||
@@ -130,11 +135,10 @@ class GuiQuoteSelect(QDialog):
|
||||
@pyqtSlot()
|
||||
def _selectedSymbol(self) -> None:
|
||||
"""Update the preview label and the selected quote style."""
|
||||
selItems = self.listBox.selectedItems()
|
||||
if selItems:
|
||||
theSymbol = selItems[0].data(self.D_KEY)
|
||||
self.previewLabel.setText(theSymbol)
|
||||
self.selectedQuote = theSymbol
|
||||
if items := self.listBox.selectedItems():
|
||||
quote = items[0].data(self.D_KEY)
|
||||
self.previewLabel.setText(quote)
|
||||
self._selected = quote
|
||||
return
|
||||
|
||||
# END Class GuiQuoteSelect
|
||||
|
||||
@@ -63,6 +63,10 @@ class NPagedSideBar(QToolBar):
|
||||
|
||||
return
|
||||
|
||||
def button(self, buttonId: int) -> _NPagedToolButton:
|
||||
"""Return a specific button."""
|
||||
return self._buttons[buttonId]
|
||||
|
||||
def setLabelColor(self, color: list | QColor) -> None:
|
||||
"""Set the text color for the labels."""
|
||||
self._labelCol = color if isinstance(color, QColor) else QColor(*color)
|
||||
|
||||
Reference in New Issue
Block a user