Clean up dialogs

This commit is contained in:
Veronica Berglyd Olsen
2023-11-27 17:10:29 +01:00
parent 93b36406f1
commit 4fa20273f7
10 changed files with 117 additions and 113 deletions
+27 -28
View File
@@ -29,7 +29,7 @@ import novelwriter
from datetime import datetime from datetime import datetime
from PyQt5.QtGui import QCursor from PyQt5.QtGui import QCursor
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
qApp, QDialog, QDialogButtonBox, QHBoxLayout, QLabel, QTabWidget, qApp, QDialog, QDialogButtonBox, QHBoxLayout, QLabel, QTabWidget,
QTextBrowser, QVBoxLayout, QWidget QTextBrowser, QVBoxLayout, QWidget
@@ -44,7 +44,7 @@ logger = logging.getLogger(__name__)
class GuiAbout(QDialog): class GuiAbout(QDialog):
def __init__(self, parent: QWidget): def __init__(self, parent: QWidget) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
logger.debug("Create: GuiAbout") logger.debug("Create: GuiAbout")
@@ -111,13 +111,12 @@ class GuiAbout(QDialog):
return return
def __del__(self): # pragma: no cover def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiAbout") logger.debug("Delete: GuiAbout")
return return
def populateGUI(self): def populateGUI(self) -> None:
"""Populate tabs with text. """Populate tabs with text."""
"""
qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
self._setStyleSheet() self._setStyleSheet()
self._fillAboutPage() self._fillAboutPage()
@@ -127,19 +126,27 @@ class GuiAbout(QDialog):
qApp.restoreOverrideCursor() qApp.restoreOverrideCursor()
return return
def showReleaseNotes(self): def showReleaseNotes(self) -> None:
"""Show the release notes. """Show the release notes."""
"""
self.tabBox.setCurrentWidget(self.pageNotes) self.tabBox.setCurrentWidget(self.pageNotes)
return return
##
# Private Slots
##
@pyqtSlot()
def _doClose(self) -> None:
"""Close the dialog"""
self.close()
return
## ##
# Internal Functions # Internal Functions
## ##
def _fillAboutPage(self): def _fillAboutPage(self) -> None:
"""Generate the content for the About page. """Generate the content for the About page."""
"""
aboutMsg = ( aboutMsg = (
"<h2>{title1}</h2>" "<h2>{title1}</h2>"
"<p>{copy}</p>" "<p>{copy}</p>"
@@ -181,9 +188,8 @@ class GuiAbout(QDialog):
return return
def _fillNotesPage(self): def _fillNotesPage(self) -> None:
"""Load the content for the Release Notes page. """Load the content for the Release Notes page."""
"""
docPath = CONFIG.assetPath("text") / "release_notes.htm" docPath = CONFIG.assetPath("text") / "release_notes.htm"
docText = readTextFile(docPath) docText = readTextFile(docPath)
if docText: if docText:
@@ -192,9 +198,8 @@ class GuiAbout(QDialog):
self.pageNotes.setHtml("Error loading release notes text ...") self.pageNotes.setHtml("Error loading release notes text ...")
return return
def _fillCreditsPage(self): def _fillCreditsPage(self) -> None:
"""Load the content for the Credits page. """Load the content for the Credits page."""
"""
docPath = CONFIG.assetPath("text") / "credits_en.htm" docPath = CONFIG.assetPath("text") / "credits_en.htm"
docText = readTextFile(docPath) docText = readTextFile(docPath)
if docText: if docText:
@@ -203,9 +208,8 @@ class GuiAbout(QDialog):
self.pageCredits.setHtml("Error loading credits text ...") self.pageCredits.setHtml("Error loading credits text ...")
return return
def _fillLicensePage(self): def _fillLicensePage(self) -> None:
"""Load the content for the Licence page. """Load the content for the Licence page."""
"""
docPath = CONFIG.assetPath("text") / "gplv3_en.htm" docPath = CONFIG.assetPath("text") / "gplv3_en.htm"
docText = readTextFile(docPath) docText = readTextFile(docPath)
if docText: if docText:
@@ -214,9 +218,8 @@ class GuiAbout(QDialog):
self.pageLicense.setHtml("Error loading licence text ...") self.pageLicense.setHtml("Error loading licence text ...")
return return
def _setStyleSheet(self): def _setStyleSheet(self) -> None:
"""Set stylesheet for all browser tabs """Set stylesheet for all browser tabs."""
"""
styleSheet = ( styleSheet = (
"h1, h2, h3, h4 {{" "h1, h2, h3, h4 {{"
" color: rgb({hColR},{hColG},{hColB});" " color: rgb({hColR},{hColG},{hColB});"
@@ -242,8 +245,4 @@ class GuiAbout(QDialog):
return return
def _doClose(self):
self.close()
return
# END Class GuiAbout # END Class GuiAbout
+8 -11
View File
@@ -108,13 +108,12 @@ class GuiDocMerge(QDialog):
return return
def __del__(self): # pragma: no cover def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiDocMerge") logger.debug("Delete: GuiDocMerge")
return return
def getData(self): def getData(self) -> dict:
"""Return the user's choices. """Return the user's choices."""
"""
finalItems = [] finalItems = []
for i in range(self.listBox.count()): for i in range(self.listBox.count()):
item = self.listBox.item(i) item = self.listBox.item(i)
@@ -127,12 +126,11 @@ class GuiDocMerge(QDialog):
return self._data return self._data
## ##
# Slots # Private Slots
## ##
def _resetList(self): def _resetList(self) -> None:
"""Reset the content of the list box to its original state. """Reset the content of the list box to its original state."""
"""
logger.debug("Resetting list box content") logger.debug("Resetting list box content")
sHandle = self._data.get("sHandle", None) sHandle = self._data.get("sHandle", None)
itemList = self._data.get("origItems", []) itemList = self._data.get("origItems", [])
@@ -143,9 +141,8 @@ class GuiDocMerge(QDialog):
# Internal Functions # Internal Functions
## ##
def _loadContent(self, sHandle, itemList): def _loadContent(self, sHandle: str, itemList: list[str]) -> None:
"""Load content from a given list of items. """Load content from a given list of items."""
"""
self._data = {} self._data = {}
self._data["sHandle"] = sHandle self._data["sHandle"] = sHandle
self._data["origItems"] = itemList self._data["origItems"] = itemList
+12 -13
View File
@@ -26,10 +26,10 @@ from __future__ import annotations
import logging import logging
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QDialog, QVBoxLayout, QComboBox, QListWidget, QAbstractItemView, QAbstractItemView, QComboBox, QDialog, QDialogButtonBox, QGridLayout,
QListWidgetItem, QDialogButtonBox, QLabel, QGridLayout QLabel, QListWidget, QListWidgetItem, QVBoxLayout, QWidget
) )
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
@@ -45,7 +45,7 @@ class GuiDocSplit(QDialog):
LEVEL_ROLE = Qt.ItemDataRole.UserRole + 1 LEVEL_ROLE = Qt.ItemDataRole.UserRole + 1
LABEL_ROLE = Qt.ItemDataRole.UserRole + 2 LABEL_ROLE = Qt.ItemDataRole.UserRole + 2
def __init__(self, parent, sHandle): def __init__(self, parent: QWidget, sHandle: str) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
logger.debug("Create: GuiDocSplit") logger.debug("Create: GuiDocSplit")
@@ -138,11 +138,11 @@ class GuiDocSplit(QDialog):
return return
def __del__(self): # pragma: no cover def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiDocSplit") logger.debug("Delete: GuiDocSplit")
return return
def getData(self): def getData(self) -> tuple[dict, list]:
"""Return the user's choices. Also save the users options for """Return the user's choices. Also save the users options for
the next time the dialog is used. the next time the dialog is used.
""" """
@@ -175,12 +175,12 @@ class GuiDocSplit(QDialog):
return self._data, self._text return self._data, self._text
## ##
# Slots # Private Slots
## ##
def _reloadList(self): @pyqtSlot()
"""Reload the content of the list box. def _reloadList(self) -> None:
""" """Reload the content of the list box."""
sHandle = self._data.get("sHandle", None) sHandle = self._data.get("sHandle", None)
self._loadContent(sHandle) self._loadContent(sHandle)
return return
@@ -189,9 +189,8 @@ class GuiDocSplit(QDialog):
# Internal Functions # Internal Functions
## ##
def _loadContent(self, sHandle): def _loadContent(self, sHandle: str) -> None:
"""Load content from a given source item. """Load content from a given source item."""
"""
self._data = {} self._data = {}
self._data["sHandle"] = sHandle self._data["sHandle"] = sHandle
+12 -4
View File
@@ -26,7 +26,8 @@ from __future__ import annotations
import logging import logging
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QDialog, QVBoxLayout, QLineEdit, QLabel, QDialogButtonBox, QHBoxLayout QDialog, QDialogButtonBox, QHBoxLayout, QLabel, QLineEdit, QVBoxLayout,
QWidget
) )
from novelwriter import CONFIG from novelwriter import CONFIG
@@ -36,9 +37,10 @@ logger = logging.getLogger(__name__)
class GuiEditLabel(QDialog): class GuiEditLabel(QDialog):
def __init__(self, parent, text=""): def __init__(self, parent: QWidget, text: str = "") -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
logger.debug("Create: GuiEditLabel")
self.setObjectName("GuiEditLabel") self.setObjectName("GuiEditLabel")
self.setWindowTitle(self.tr("Item Label")) self.setWindowTitle(self.tr("Item Label"))
@@ -70,14 +72,20 @@ class GuiEditLabel(QDialog):
self.setLayout(self.outerBox) self.setLayout(self.outerBox)
logger.debug("Ready: GuiEditLabel")
return
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiEditLabel")
return return
@property @property
def itemLabel(self): def itemLabel(self) -> str:
return self.labelValue.text() return self.labelValue.text()
@classmethod @classmethod
def getLabel(cls, parent, text): def getLabel(cls, parent: QWidget, text: str) -> tuple[str, bool]:
cls = GuiEditLabel(parent, text=text) cls = GuiEditLabel(parent, text=text)
cls.exec_() cls.exec_()
return cls.itemLabel, cls.result() == QDialog.Accepted return cls.itemLabel, cls.result() == QDialog.Accepted
+1 -1
View File
@@ -83,7 +83,7 @@ class GuiPreferences(NPagedDialog):
return return
def __del__(self): # pragma: no cover def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiPreferences") logger.debug("Delete: GuiPreferences")
return return
+23 -31
View File
@@ -26,8 +26,8 @@ from __future__ import annotations
import math import math
import logging import logging
from PyQt5.QtCore import Qt, QSize, pyqtSlot
from PyQt5.QtGui import QFont from PyQt5.QtGui import QFont
from PyQt5.QtCore import Qt, QSize, pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractItemView, QDialogButtonBox, QGridLayout, QHBoxLayout, QLabel, QAbstractItemView, QDialogButtonBox, QGridLayout, QHBoxLayout, QLabel,
QLineEdit, QSpinBox, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget QLineEdit, QSpinBox, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget
@@ -45,7 +45,7 @@ logger = logging.getLogger(__name__)
class GuiProjectDetails(NPagedDialog): class GuiProjectDetails(NPagedDialog):
def __init__(self, parent): def __init__(self, parent: QWidget) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
logger.debug("Create: GuiProjectDetails") logger.debug("Create: GuiProjectDetails")
@@ -79,24 +79,23 @@ class GuiProjectDetails(NPagedDialog):
return return
def __del__(self): # pragma: no cover def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiProjectDetails") logger.debug("Delete: GuiProjectDetails")
return return
def updateValues(self): def updateValues(self) -> None:
"""Set all the values of the pages. """Set all the values of the pages."""
"""
self.tabMain.updateValues() self.tabMain.updateValues()
self.tabContents.updateValues() self.tabContents.updateValues()
return return
## ##
# Slots # Private Slots
## ##
def _doClose(self): @pyqtSlot()
"""Save settings and close the dialog. def _doClose(self) -> None:
""" """Save settings and close the dialog."""
self._saveGuiSettings() self._saveGuiSettings()
self.close() self.close()
return return
@@ -105,9 +104,8 @@ class GuiProjectDetails(NPagedDialog):
# Internal Functions # Internal Functions
## ##
def _saveGuiSettings(self): def _saveGuiSettings(self) -> None:
"""Save GUI settings. """Save GUI settings."""
"""
winWidth = CONFIG.rpxInt(self.width()) winWidth = CONFIG.rpxInt(self.width())
winHeight = CONFIG.rpxInt(self.height()) winHeight = CONFIG.rpxInt(self.height())
@@ -141,7 +139,7 @@ class GuiProjectDetails(NPagedDialog):
class GuiProjectDetailsMain(QWidget): class GuiProjectDetailsMain(QWidget):
def __init__(self, parent): def __init__(self, parent: QWidget) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
fPx = SHARED.theme.fontPixelSize fPx = SHARED.theme.fontPixelSize
@@ -270,7 +268,7 @@ class GuiProjectDetailsContents(QWidget):
C_PAGE = 3 C_PAGE = 3
C_PROG = 4 C_PROG = 4
def __init__(self, parent): def __init__(self, parent: QWidget) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
# Internal # Internal
@@ -406,9 +404,8 @@ class GuiProjectDetailsContents(QWidget):
return return
def getColumnSizes(self): def getColumnSizes(self) -> list[int]:
"""Return the column widths for the tree columns. """Return the column widths for the tree columns."""
"""
retVals = [ retVals = [
self.tocTree.columnWidth(0), self.tocTree.columnWidth(0),
self.tocTree.columnWidth(1), self.tocTree.columnWidth(1),
@@ -418,24 +415,21 @@ class GuiProjectDetailsContents(QWidget):
] ]
return retVals return retVals
def updateValues(self): def updateValues(self) -> None:
"""Populate the tree. """Populate the tree."""
"""
self._currentRoot = None self._currentRoot = None
self.novelValue.updateList() self.novelValue.updateList()
self.novelValue.setHandle(self.novelValue.firstHandle) self.novelValue.setHandle(self.novelValue.firstHandle)
self._prepareData(self.novelValue.firstHandle) self._prepareData(self.novelValue.firstHandle)
self._populateTree() self._populateTree()
return return
## ##
# Internal Functions # Internal Functions
## ##
def _prepareData(self, rootHandle): def _prepareData(self, rootHandle: str) -> None:
"""Extract the information from the project index. """Extract the information from the project index."""
"""
logger.debug("Populating ToC from handle '%s'", rootHandle) logger.debug("Populating ToC from handle '%s'", rootHandle)
self._theToC = SHARED.project.index.getTableOfContents(rootHandle, 2) self._theToC = SHARED.project.index.getTableOfContents(rootHandle, 2)
self._theToC.append(("", 0, self.tr("END"), 0)) self._theToC.append(("", 0, self.tr("END"), 0))
@@ -446,9 +440,8 @@ class GuiProjectDetailsContents(QWidget):
## ##
@pyqtSlot(str) @pyqtSlot(str)
def _novelValueChanged(self, tHandle): def _novelValueChanged(self, tHandle: str) -> None:
"""Refresh the tree with another root item. """Refresh the tree with another root item."""
"""
if tHandle != self._currentRoot: if tHandle != self._currentRoot:
self._prepareData(tHandle) self._prepareData(tHandle)
self._populateTree() self._populateTree()
@@ -456,9 +449,8 @@ class GuiProjectDetailsContents(QWidget):
return return
@pyqtSlot() @pyqtSlot()
def _populateTree(self): def _populateTree(self) -> None:
"""Set the content of the chapter/page tree. """Set the content of the chapter/page tree."""
"""
dblPages = self.dblValue.isChecked() dblPages = self.dblValue.isChecked()
wpPage = self.wpValue.value() wpPage = self.wpValue.value()
fstPage = self.poValue.value() - 1 fstPage = self.poValue.value() - 1
+1 -1
View File
@@ -153,7 +153,7 @@ class GuiProjectLoad(QDialog):
return return
def __del__(self): # pragma: no cover def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiProjectLoad") logger.debug("Delete: GuiProjectLoad")
return return
+23 -14
View File
@@ -26,10 +26,10 @@ from __future__ import annotations
import logging import logging
from PyQt5.QtGui import QFontMetrics from PyQt5.QtGui import QFontMetrics
from PyQt5.QtCore import Qt, QSize from PyQt5.QtCore import QSize, Qt, pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QLabel, QVBoxLayout, QHBoxLayout, QDialog, QDialogButtonBox, QDialog, QDialogButtonBox, QFrame, QHBoxLayout, QLabel, QListWidget,
QListWidget, QListWidgetItem, QFrame QListWidgetItem, QVBoxLayout, QWidget
) )
from novelwriter import CONFIG from novelwriter import CONFIG
@@ -44,9 +44,12 @@ class GuiQuoteSelect(QDialog):
D_KEY = Qt.ItemDataRole.UserRole D_KEY = Qt.ItemDataRole.UserRole
def __init__(self, parent=None, currentQuote='"'): def __init__(self, parent: QWidget, currentQuote: str = '"') -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
logger.debug("Create: GuiQuoteSelect")
self.setObjectName("GuiQuoteSelect")
self.outerBox = QVBoxLayout() self.outerBox = QVBoxLayout()
self.innerBox = QHBoxLayout() self.innerBox = QHBoxLayout()
self.labelBox = QVBoxLayout() self.labelBox = QVBoxLayout()
@@ -102,15 +105,21 @@ class GuiQuoteSelect(QDialog):
self.setLayout(self.outerBox) self.setLayout(self.outerBox)
logger.debug("Ready: GuiQuoteSelect")
return
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiQuoteSelect")
return return
## ##
# Slots # Private Slots
## ##
def _selectedSymbol(self): @pyqtSlot()
"""Update the preview label and the selected quote style. def _selectedSymbol(self) -> None:
""" """Update the preview label and the selected quote style."""
selItems = self.listBox.selectedItems() selItems = self.listBox.selectedItems()
if selItems: if selItems:
theSymbol = selItems[0].data(self.D_KEY) theSymbol = selItems[0].data(self.D_KEY)
@@ -118,15 +127,15 @@ class GuiQuoteSelect(QDialog):
self.selectedQuote = theSymbol self.selectedQuote = theSymbol
return return
def _doAccept(self): @pyqtSlot()
"""Ok button clicked. def _doAccept(self) -> None:
""" """Handle Ok button clicked."""
self.accept() self.accept()
return return
def _doReject(self): @pyqtSlot()
"""Cancel button clicked. def _doReject(self) -> None:
""" """Handle Cancel button clicked."""
self.reject() self.reject()
return return
+9 -9
View File
@@ -44,7 +44,7 @@ logger = logging.getLogger(__name__)
class GuiWordList(QDialog): class GuiWordList(QDialog):
def __init__(self, mainGui: GuiMain): def __init__(self, mainGui: GuiMain) -> None:
super().__init__(parent=mainGui) super().__init__(parent=mainGui)
logger.debug("Create: GuiWordList") logger.debug("Create: GuiWordList")
@@ -108,7 +108,7 @@ class GuiWordList(QDialog):
return return
def __del__(self): # pragma: no cover def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiWordList") logger.debug("Delete: GuiWordList")
return return
@@ -116,7 +116,7 @@ class GuiWordList(QDialog):
# Slots # Slots
## ##
def _doAdd(self): def _doAdd(self) -> None:
"""Add a new word to the word list.""" """Add a new word to the word list."""
word = self.newEntry.text().strip() word = self.newEntry.text().strip()
if word == "": if word == "":
@@ -134,14 +134,14 @@ class GuiWordList(QDialog):
return return
def _doDelete(self): def _doDelete(self) -> None:
"""Delete the selected item.""" """Delete the selected item."""
selItem = self.listBox.selectedItems() selItem = self.listBox.selectedItems()
if selItem: if selItem:
self.listBox.takeItem(self.listBox.row(selItem[0])) self.listBox.takeItem(self.listBox.row(selItem[0]))
return return
def _doSave(self): def _doSave(self) -> None:
"""Save the new word list and close.""" """Save the new word list and close."""
self._saveGuiSettings() self._saveGuiSettings()
userDict = UserDictionary(SHARED.project) userDict = UserDictionary(SHARED.project)
@@ -153,9 +153,9 @@ class GuiWordList(QDialog):
userDict.add(word) userDict.add(word)
userDict.save() userDict.save()
self.accept() self.accept()
return True return
def _doClose(self): def _doClose(self) -> None:
"""Close without saving the word list.""" """Close without saving the word list."""
self._saveGuiSettings() self._saveGuiSettings()
self.reject() self.reject()
@@ -165,7 +165,7 @@ class GuiWordList(QDialog):
# Internal Functions # Internal Functions
## ##
def _loadWordList(self): def _loadWordList(self) -> None:
"""Load the project's word list, if it exists.""" """Load the project's word list, if it exists."""
userDict = UserDictionary(SHARED.project) userDict = UserDictionary(SHARED.project)
userDict.load() userDict.load()
@@ -175,7 +175,7 @@ class GuiWordList(QDialog):
self.listBox.addItem(word) self.listBox.addItem(word)
return return
def _saveGuiSettings(self): def _saveGuiSettings(self) -> None:
"""Save GUI settings.""" """Save GUI settings."""
winWidth = CONFIG.rpxInt(self.width()) winWidth = CONFIG.rpxInt(self.width())
winHeight = CONFIG.rpxInt(self.height()) winHeight = CONFIG.rpxInt(self.height())
+1 -1
View File
@@ -111,7 +111,7 @@ def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, projPath):
assert wList.listBox.item(0).text() == "word_a" assert wList.listBox.item(0).text() == "word_a"
# Save files # Save files
assert wList._doSave() wList._doSave()
userDict.load() userDict.load()
assert len(list(userDict)) == 6 assert len(list(userDict)) == 6
assert "word_a" in userDict assert "word_a" in userDict