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