Update preferences dialog and quotes selection dialog

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