Update linting for main code

This commit is contained in:
Veronica Berglyd Olsen
2025-08-27 21:00:09 +02:00
parent 84ff1f4640
commit c174f8f931
80 changed files with 461 additions and 1653 deletions
+2 -7
View File
@@ -20,7 +20,7 @@ General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
""" # noqa
from __future__ import annotations
import logging
@@ -45,6 +45,7 @@ logger = logging.getLogger(__name__)
class GuiAbout(NDialog):
"""GUI: About novelWriter Dialog."""
def __init__(self, parent: QWidget) -> None:
super().__init__(parent=parent)
@@ -109,11 +110,8 @@ class GuiAbout(NDialog):
logger.debug("Ready: GuiAbout")
return
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiAbout")
return
##
# Events
@@ -123,7 +121,6 @@ class GuiAbout(NDialog):
"""Capture the close event and perform cleanup."""
event.accept()
self.softDelete()
return
##
# Internal Functions
@@ -135,7 +132,6 @@ class GuiAbout(NDialog):
self.txtCredits.setHtml(html)
else:
self.txtCredits.setHtml("Error loading credits text ...")
return
def _setStyleSheet(self) -> None:
"""Set stylesheet text document."""
@@ -143,4 +139,3 @@ class GuiAbout(NDialog):
self.txtCredits.setStyleSheet(
f"QTextBrowser {{border: none; background: {baseCol};}} "
)
return
+2 -6
View File
@@ -21,7 +21,7 @@ General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
""" # noqa
from __future__ import annotations
import logging
@@ -42,6 +42,7 @@ logger = logging.getLogger(__name__)
class GuiDocMerge(NDialog):
"""GUI: Document Merge Tool."""
D_HANDLE = QtUserRole
@@ -110,11 +111,8 @@ class GuiDocMerge(NDialog):
logger.debug("Ready: GuiDocMerge")
return
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiDocMerge")
return
def data(self) -> dict:
"""Return the user's choices."""
@@ -150,7 +148,6 @@ class GuiDocMerge(NDialog):
if sHandle := self._data.get("sHandle"):
itemList = self._data.get("origItems", [])
self._loadContent(sHandle, itemList)
return
##
# Internal Functions
@@ -170,4 +167,3 @@ class GuiDocMerge(NDialog):
item.setData(self.D_HANDLE, tHandle)
item.setCheckState(Qt.CheckState.Checked)
self.listBox.addItem(item)
return
+2 -5
View File
@@ -21,7 +21,7 @@ General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
""" # noqa
from __future__ import annotations
import logging
@@ -42,6 +42,7 @@ logger = logging.getLogger(__name__)
class GuiDocSplit(NDialog):
"""GUI: Document Split Tool."""
LINE_ROLE = QtUserRole
LEVEL_ROLE = QtUserRole + 1
@@ -139,11 +140,8 @@ class GuiDocSplit(NDialog):
logger.debug("Ready: GuiDocSplit")
return
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiDocSplit")
return
def data(self) -> tuple[dict, list[str]]:
"""Return the user's choices. Also save the users options for
@@ -197,7 +195,6 @@ class GuiDocSplit(NDialog):
"""Reload the content of the list box."""
if sHandle := self._data.get("sHandle"):
self._loadContent(sHandle)
return
##
# Internal Functions
+2 -4
View File
@@ -20,7 +20,7 @@ General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
""" # noqa
from __future__ import annotations
import logging
@@ -34,6 +34,7 @@ logger = logging.getLogger(__name__)
class GuiEditLabel(NDialog):
"""GUI: Edit Item Label Dialog."""
def __init__(self, parent: QWidget, text: str = "") -> None:
super().__init__(parent=parent)
@@ -72,11 +73,8 @@ class GuiEditLabel(NDialog):
logger.debug("Ready: GuiEditLabel")
return
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiEditLabel")
return
@property
def itemLabel(self) -> str:
+2 -23
View File
@@ -21,7 +21,7 @@ General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
""" # noqa
from __future__ import annotations
import logging
@@ -50,6 +50,7 @@ logger = logging.getLogger(__name__)
class GuiPreferences(NDialog):
"""GUI: Preferences Dialog."""
newPreferencesReady = pyqtSignal(bool, bool, bool, bool)
@@ -125,11 +126,8 @@ class GuiPreferences(NDialog):
logger.debug("Ready: GuiPreferences")
return
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiPreferences")
return
def buildForm(self) -> None:
"""Build the settings form."""
@@ -856,8 +854,6 @@ class GuiPreferences(NDialog):
self.mainForm.finalise()
self.sidebar.setSelected(1)
return
##
# Events
##
@@ -868,7 +864,6 @@ class GuiPreferences(NDialog):
self._saveWindowSize()
event.accept()
self.softDelete()
return
def keyPressEvent(self, event: QKeyEvent) -> None:
"""Overload keyPressEvent and only accept escape. The main
@@ -878,7 +873,6 @@ class GuiPreferences(NDialog):
if event.matches(QKeySequence.StandardKey.Cancel):
self.close()
event.ignore()
return
##
# Private Slots
@@ -888,13 +882,11 @@ class GuiPreferences(NDialog):
def _sidebarClicked(self, section: int) -> None:
"""Process a user request to switch page."""
self.mainForm.scrollToSection(section)
return
@pyqtSlot()
def _gotoSearch(self) -> None:
"""Go to the setting indicated by the search text."""
self.mainForm.scrollToLabel(self.searchText.text().strip())
return
@pyqtSlot()
def _selectGuiFont(self) -> None:
@@ -904,7 +896,6 @@ class GuiPreferences(NDialog):
self.guiFont.setText(describeFont(font))
self.guiFont.setCursorPosition(0)
self._guiFont = font
return
@pyqtSlot()
def _selectTextFont(self) -> None:
@@ -914,7 +905,6 @@ class GuiPreferences(NDialog):
self.textFont.setText(describeFont(font))
self.textFont.setCursorPosition(0)
self._textFont = font
return
@pyqtSlot()
def _backupFolder(self) -> None:
@@ -925,13 +915,11 @@ class GuiPreferences(NDialog):
):
self.backupPath = path
self.mainForm.setHelpText("backupPath", self.tr("Path: {0}").format(path))
return
@pyqtSlot(bool)
def _toggledBackupOnClose(self, state: bool) -> None:
"""Toggle switch that depends on the backup on close switch."""
self.askBeforeBackup.setEnabled(state)
return
@pyqtSlot(str)
def _insertDialogLineSymbol(self, symbol: str) -> None:
@@ -939,7 +927,6 @@ class GuiPreferences(NDialog):
current = self.dialogLine.text()
values = processDialogSymbols(f"{current} {symbol}")
self.dialogLine.setText(" ".join(values))
return
@pyqtSlot(bool)
def _toggleAutoReplaceMain(self, state: bool) -> None:
@@ -949,7 +936,6 @@ class GuiPreferences(NDialog):
self.doReplaceDash.setEnabled(state)
self.doReplaceDots.setEnabled(state)
self.fmtPadThin.setEnabled(state)
return
@pyqtSlot()
def _changeSingleQuoteOpen(self) -> None:
@@ -957,7 +943,6 @@ class GuiPreferences(NDialog):
quote, status = GuiQuoteSelect.getQuote(self, current=self.fmtSQuoteOpen.text())
if status:
self.fmtSQuoteOpen.setText(quote)
return
@pyqtSlot()
def _changeSingleQuoteClose(self) -> None:
@@ -965,7 +950,6 @@ class GuiPreferences(NDialog):
quote, status = GuiQuoteSelect.getQuote(self, current=self.fmtSQuoteClose.text())
if status:
self.fmtSQuoteClose.setText(quote)
return
@pyqtSlot()
def _changeDoubleQuoteOpen(self) -> None:
@@ -973,7 +957,6 @@ class GuiPreferences(NDialog):
quote, status = GuiQuoteSelect.getQuote(self, current=self.fmtDQuoteOpen.text())
if status:
self.fmtDQuoteOpen.setText(quote)
return
@pyqtSlot()
def _changeDoubleQuoteClose(self) -> None:
@@ -981,7 +964,6 @@ class GuiPreferences(NDialog):
quote, status = GuiQuoteSelect.getQuote(self, current=self.fmtDQuoteClose.text())
if status:
self.fmtDQuoteClose.setText(quote)
return
##
# Internal Functions
@@ -990,7 +972,6 @@ class GuiPreferences(NDialog):
def _saveWindowSize(self) -> None:
"""Save the dialog window size."""
CONFIG.setPreferencesWinSize(self.width(), self.height())
return
def _doSave(self) -> None:
"""Save the values set in the form."""
@@ -1134,5 +1115,3 @@ class GuiPreferences(NDialog):
self.newPreferencesReady.emit(needsRestart, refreshTree, updateTheme, updateSyntax)
self.close()
return
+2 -33
View File
@@ -21,7 +21,7 @@ General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
""" # noqa
from __future__ import annotations
import csv
@@ -55,6 +55,7 @@ logger = logging.getLogger(__name__)
class GuiProjectSettings(NDialog):
"""GUI: Project Settings DIalog."""
PAGE_SETTINGS = 0
PAGE_STATUS = 1
@@ -137,11 +138,8 @@ class GuiProjectSettings(NDialog):
logger.debug("Ready: GuiProjectSettings")
return
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiProjectSettings")
return
##
# Events
@@ -152,7 +150,6 @@ class GuiProjectSettings(NDialog):
self._saveSettings()
event.accept()
self.softDelete()
return
##
# Private Slots
@@ -169,7 +166,6 @@ class GuiProjectSettings(NDialog):
self.mainStack.setCurrentWidget(self.importPage)
elif pageId == self.PAGE_REPLACE:
self.mainStack.setCurrentWidget(self.replacePage)
return
@pyqtSlot()
def _doSave(self) -> None:
@@ -203,8 +199,6 @@ class GuiProjectSettings(NDialog):
QApplication.processEvents()
self.close()
return
##
# Internal Functions
##
@@ -223,8 +217,6 @@ class GuiProjectSettings(NDialog):
options.setValue("GuiProjectSettings", "importColW", importColW)
options.setValue("GuiProjectSettings", "replaceColW", replaceColW)
return
class _SettingsPage(NScrollableForm):
@@ -295,8 +287,6 @@ class _SettingsPage(NScrollableForm):
self.finalise()
return
class _StatusPage(NFixedPage):
@@ -478,8 +468,6 @@ class _StatusPage(NFixedPage):
self.setCentralLayout(self.outerBox)
self._setButtonIcons()
return
@property
def changed(self) -> bool:
"""The user changed these settings."""
@@ -518,7 +506,6 @@ class _StatusPage(NFixedPage):
entry.name = name
item.setText(self.C_LABEL, name)
self._changed = True
return
@pyqtSlot(int)
def _onThemeSelect(self, index: int) -> None:
@@ -526,7 +513,6 @@ class _StatusPage(NFixedPage):
self._theme = str(self.iconColor.currentData())
self._setButtonIcons()
self._updateIcon()
return
@pyqtSlot()
def _onColorSelect(self) -> None:
@@ -536,7 +522,6 @@ class _StatusPage(NFixedPage):
self._theme = CUSTOM_COL
self._setButtonIcons()
self._updateIcon()
return
@pyqtSlot()
def _onItemCreate(self) -> None:
@@ -547,7 +532,6 @@ class _StatusPage(NFixedPage):
theme = str(self.iconColor.currentData())
self._addItem(None, StatusEntry(self.tr("New Item"), color, theme, shape, icon, 0))
self._changed = True
return
@pyqtSlot()
def _onItemDelete(self) -> None:
@@ -560,7 +544,6 @@ class _StatusPage(NFixedPage):
else:
self.listBox.takeTopLevelItem(iRow)
self._changed = True
return
@pyqtSlot()
def _onSelectionChanged(self) -> None:
@@ -593,7 +576,6 @@ class _StatusPage(NFixedPage):
self.iconColor.setEnabled(False)
self.colorButton.setEnabled(False)
self.shapeButton.setEnabled(False)
return
@pyqtSlot()
def _importLabels(self) -> None:
@@ -630,7 +612,6 @@ class _StatusPage(NFixedPage):
writer.writerow([entry.shape.name, entry.color.name(), entry.name])
except Exception as exc:
SHARED.error("Could not write file.", exc=exc)
return
##
# Internal Functions
@@ -641,7 +622,6 @@ class _StatusPage(NFixedPage):
self._shape = shape
self._setButtonIcons()
self._updateIcon()
return
def _updateIcon(self) -> None:
"""Apply changes made to a status icon."""
@@ -654,7 +634,6 @@ class _StatusPage(NFixedPage):
entry.icon = icon
item.setIcon(self.C_LABEL, icon)
self._changed = True
return
def _addItem(self, key: str | None, entry: StatusEntry) -> None:
"""Add a status item to the list."""
@@ -665,7 +644,6 @@ class _StatusPage(NFixedPage):
item.setData(self.C_DATA, self.D_KEY, key)
item.setData(self.C_DATA, self.D_ENTRY, entry)
self.listBox.addTopLevelItem(item)
return
def _moveItem(self, step: int) -> None:
"""Move and item up or down step."""
@@ -678,7 +656,6 @@ class _StatusPage(NFixedPage):
self.listBox.clearSelection()
cItem.setSelected(True)
self._changed = True
return
def _getSelectedItem(self) -> QTreeWidgetItem | None:
"""Get the currently selected item."""
@@ -701,7 +678,6 @@ class _StatusPage(NFixedPage):
self.iconColor.setCurrentData(self._theme, CUSTOM_COL)
self.colorButton.setIcon(icon)
self.shapeButton.setIcon(self._icons[self._shape])
return
def _pickColor(self) -> QColor:
"""Get the correct colour value based on selections."""
@@ -789,8 +765,6 @@ class _ReplacePage(NFixedPage):
self.setCentralLayout(self.outerBox)
return
@property
def changed(self) -> bool:
"""The user changed these settings."""
@@ -823,7 +797,6 @@ class _ReplacePage(NFixedPage):
if (item := self._getSelectedItem()) and (key := self._stripKey(text)):
item.setText(self.C_KEY, f"<{key}>")
self._changed = True
return
@pyqtSlot(str)
def _onValueEdit(self, text: str) -> None:
@@ -831,7 +804,6 @@ class _ReplacePage(NFixedPage):
if item := self._getSelectedItem():
item.setText(self.C_REPL, text)
self._changed = True
return
@pyqtSlot()
def _onSelectionChanged(self) -> None:
@@ -850,14 +822,12 @@ class _ReplacePage(NFixedPage):
self.editValue.setText("")
self.editKey.setEnabled(False)
self.editValue.setEnabled(False)
return
@pyqtSlot()
def _onEntryCreated(self) -> None:
"""Add a new list entry."""
key = f"<keyword{self.listBox.topLevelItemCount() + 1:d}>"
self.listBox.addTopLevelItem(QTreeWidgetItem([key, ""]))
return
@pyqtSlot()
def _onEntryDeleted(self) -> None:
@@ -865,7 +835,6 @@ class _ReplacePage(NFixedPage):
if item := self._getSelectedItem():
self.listBox.takeTopLevelItem(self.listBox.indexOfTopLevelItem(item))
self._changed = True
return
##
# Internal Functions
+2 -5
View File
@@ -20,7 +20,7 @@ General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
""" # noqa
from __future__ import annotations
import logging
@@ -43,6 +43,7 @@ logger = logging.getLogger(__name__)
class GuiQuoteSelect(NDialog):
"""GUI: Quote Selector Dialog."""
_selected = ""
@@ -108,11 +109,8 @@ class GuiQuoteSelect(NDialog):
logger.debug("Ready: GuiQuoteSelect")
return
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiQuoteSelect")
return
@property
def selectedQuote(self) -> str:
@@ -140,4 +138,3 @@ class GuiQuoteSelect(NDialog):
quote = items[0].data(self.D_KEY)
self.previewLabel.setText(quote)
self._selected = quote
return
+2 -12
View File
@@ -20,7 +20,7 @@ General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
""" # noqa
from __future__ import annotations
import logging
@@ -48,6 +48,7 @@ logger = logging.getLogger(__name__)
class GuiWordList(NDialog):
"""GUI: User Dictionary Edit Tool."""
newWordListReady = pyqtSignal()
@@ -128,11 +129,8 @@ class GuiWordList(NDialog):
logger.debug("Ready: GuiWordList")
return
def __del__(self) -> None: # pragma: no cover
logger.debug("Delete: GuiWordList")
return
##
# Events
@@ -143,7 +141,6 @@ class GuiWordList(NDialog):
self._saveGuiSettings()
event.accept()
self.softDelete()
return
##
# Private Slots
@@ -159,14 +156,12 @@ class GuiWordList(NDialog):
if items := self.listBox.findItems(word, Qt.MatchFlag.MatchExactly):
self.listBox.setCurrentItem(items[0])
self.listBox.scrollToItem(items[0], QAbstractItemView.ScrollHint.PositionAtCenter)
return
@pyqtSlot()
def _doDelete(self) -> None:
"""Delete the selected items."""
for item in self.listBox.selectedItems():
self.listBox.takeItem(self.listBox.row(item))
return
@pyqtSlot()
def _doSave(self) -> None:
@@ -178,7 +173,6 @@ class GuiWordList(NDialog):
self.newWordListReady.emit()
QApplication.processEvents()
self.close()
return
@pyqtSlot()
def _importWords(self) -> None:
@@ -213,7 +207,6 @@ class GuiWordList(NDialog):
fo.write("\n".join(self._listWords()))
except Exception as exc:
SHARED.error("Could not write file.", exc=exc)
return
##
# Internal Functions
@@ -226,7 +219,6 @@ class GuiWordList(NDialog):
self.listBox.clear()
for word in userDict:
self.listBox.addItem(word)
return
def _saveGuiSettings(self) -> None:
"""Save GUI settings."""
@@ -234,14 +226,12 @@ class GuiWordList(NDialog):
pOptions = SHARED.project.options
pOptions.setValue("GuiWordList", "winWidth", self.width())
pOptions.setValue("GuiWordList", "winHeight", self.height())
return
def _addWord(self, word: str) -> None:
"""Add a single word to the list."""
if word and not self.listBox.findItems(word, Qt.MatchFlag.MatchExactly):
self.listBox.addItem(word)
self._changed = True
return
def _listWords(self) -> list[str]:
"""List all words in the list box."""