Fix linting errors in the main code

This commit is contained in:
Veronica Berglyd Olsen
2025-04-07 17:18:43 +02:00
parent dab48d43a5
commit 8ed3bd889d
66 changed files with 434 additions and 344 deletions
+10 -10
View File
@@ -97,10 +97,10 @@ class GuiDocEditor(QPlainTextEdit):
"""Gui Widget: Main Document Editor"""
__slots__ = (
"_nwDocument", "_nwItem", "_docChanged", "_docHandle", "_vpMargin",
"_lastEdit", "_lastActive", "_lastFind", "_doReplace", "_autoReplace",
"_completer", "_qDocument", "_keyContext", "_followTag1", "_followTag2",
"_timerDoc", "_wCounterDoc", "_timerSel", "_wCounterSel",
"_autoReplace", "_completer", "_doReplace", "_docChanged", "_docHandle", "_followTag1",
"_followTag2", "_keyContext", "_lastActive", "_lastEdit", "_lastFind", "_nwDocument",
"_nwItem", "_qDocument", "_timerDoc", "_timerSel", "_vpMargin", "_wCounterDoc",
"_wCounterSel",
)
MOVE_KEYS = (
@@ -760,7 +760,7 @@ class GuiDocEditor(QPlainTextEdit):
elif action == nwDocAction.REPL_SNG:
self._replaceQuotes("'", CONFIG.fmtSQuoteOpen, CONFIG.fmtSQuoteClose)
elif action == nwDocAction.REPL_DBL:
self._replaceQuotes("\"", CONFIG.fmtDQuoteOpen, CONFIG.fmtDQuoteClose)
self._replaceQuotes('"', CONFIG.fmtDQuoteOpen, CONFIG.fmtDQuoteClose)
elif action == nwDocAction.RM_BREAKS:
self._removeInParLineBreaks()
elif action == nwDocAction.ALIGN_L:
@@ -2003,7 +2003,7 @@ class GuiDocEditor(QPlainTextEdit):
sPos = cPos - i - 1
cOne = str(self._qDocument.characterAt(sPos))
cTwo = str(self._qDocument.characterAt(sPos - 1))
if not (cOne.isalnum() or cOne in apos and cTwo.isalnum()):
if not (cOne.isalnum() or (cOne in apos and cTwo.isalnum())):
sPos += 1
break
@@ -2013,7 +2013,7 @@ class GuiDocEditor(QPlainTextEdit):
ePos = cPos + i
cOne = str(self._qDocument.characterAt(ePos))
cTwo = str(self._qDocument.characterAt(ePos + 1))
if not (cOne.isalnum() or cOne in apos and cTwo.isalnum()):
if not (cOne.isalnum() or (cOne in apos and cTwo.isalnum())):
break
if ePos - sPos <= 0:
@@ -2193,9 +2193,9 @@ class BackgroundWordCounterSignals(QObject):
class TextAutoReplace:
__slots__ = (
"_quoteSO", "_quoteSC", "_quoteDO", "_quoteDC",
"_replaceSQuote", "_replaceDQuote", "_replaceDash", "_replaceDots",
"_padChar", "_padBefore", "_padAfter", "_doPadBefore", "_doPadAfter",
"_doPadAfter", "_doPadBefore", "_padAfter", "_padBefore", "_padChar",
"_quoteDC", "_quoteDO", "_quoteSC", "_quoteSO", "_replaceDQuote",
"_replaceDash", "_replaceDots", "_replaceSQuote",
)
def __init__(self) -> None:
+3 -3
View File
@@ -58,8 +58,8 @@ BLOCK_TITLE = 4
class GuiDocHighlighter(QSyntaxHighlighter):
__slots__ = (
"_tHandle", "_isNovel", "_isInactive", "_spellCheck", "_spellErr",
"_hStyles", "_minRules", "_txtRules", "_cmnRules", "_dialogParser",
"_cmnRules", "_dialogParser", "_hStyles", "_isInactive", "_isNovel",
"_minRules", "_spellCheck", "_spellErr", "_tHandle", "_txtRules",
)
def __init__(self, document: QTextDocument) -> None:
@@ -466,7 +466,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
class TextBlockData(QTextBlockUserData):
__slots__ = ("_text", "_offset", "_metaData", "_spellErrors")
__slots__ = ("_metaData", "_offset", "_spellErrors", "_text")
def __init__(self) -> None:
super().__init__()
+4 -1
View File
@@ -26,6 +26,7 @@ from __future__ import annotations
import logging
from enum import Enum
from typing import TYPE_CHECKING
from PyQt6.QtCore import QModelIndex, Qt, pyqtSignal, pyqtSlot
from PyQt6.QtWidgets import (
@@ -36,12 +37,14 @@ from PyQt6.QtWidgets import (
from novelwriter import SHARED
from novelwriter.common import checkInt, qtAddAction
from novelwriter.constants import nwLabels, nwLists, nwStyles, trConst
from novelwriter.core.indexdata import IndexHeading, IndexNode
from novelwriter.enum import nwChange, nwDocMode, nwItemClass
from novelwriter.extensions.modified import NIconToolButton
from novelwriter.gui.theme import STYLES_FLAT_TABS, STYLES_MIN_TOOLBUTTON
from novelwriter.types import QtDecoration, QtHeaderFixed, QtHeaderToContents, QtUserRole
if TYPE_CHECKING:
from novelwriter.core.indexdata import IndexHeading, IndexNode
logger = logging.getLogger(__name__)
+4 -1
View File
@@ -25,8 +25,8 @@ from __future__ import annotations
import logging
from collections.abc import Iterable
from time import time
from typing import TYPE_CHECKING
from PyQt6.QtCore import QObject, pyqtSlot
from PyQt6.QtGui import QTextBlock, QTextCursor, QTextDocument
@@ -35,6 +35,9 @@ from PyQt6.QtWidgets import QApplication, QPlainTextDocumentLayout
from novelwriter import SHARED
from novelwriter.gui.dochighlight import GuiDocHighlighter, TextBlockData
if TYPE_CHECKING:
from collections.abc import Iterable
logger = logging.getLogger(__name__)
+1 -1
View File
@@ -228,7 +228,7 @@ class GuiItemDetails(QWidget):
return
self._handle = tHandle
iPx = int(round(0.9*SHARED.theme.baseIconHeight))
iPx = round(0.9*SHARED.theme.baseIconHeight)
# Label
# =====
+3 -3
View File
@@ -41,7 +41,7 @@ from novelwriter.constants import (
from novelwriter.enum import nwDocAction, nwDocInsert, nwFocus, nwView
from novelwriter.extensions.eventfilters import StatusTipFilter
if TYPE_CHECKING: # pragma: no cover
if TYPE_CHECKING:
from novelwriter.guimain import GuiMain
logger = logging.getLogger(__name__)
@@ -471,7 +471,7 @@ class GuiMainMenu(QMenuBar):
# Insert > Double Prime
self.aInsDPrime = qtAddAction(self.mInsPunct, self.tr("Double Prime"))
self.aInsDPrime.setShortcut("Ctrl+K, Ctrl+\"")
self.aInsDPrime.setShortcut('Ctrl+K, Ctrl+"')
self.aInsDPrime.triggered.connect(
lambda: self.requestDocInsertText.emit(nwUnicode.U_DPRIME)
)
@@ -680,7 +680,7 @@ class GuiMainMenu(QMenuBar):
# Format > Double Quotes
self.aFmtDQuote = qtAddAction(self.fmtMenu, self.tr("Wrap Double Quotes"))
self.aFmtDQuote.setShortcut("Ctrl+\"")
self.aFmtDQuote.setShortcut('Ctrl+"')
self.aFmtDQuote.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.D_QUOTE)
)
+6 -5
View File
@@ -32,6 +32,7 @@ import logging
from enum import Enum
from time import time
from typing import Final
from PyQt6.QtCore import QT_TRANSLATE_NOOP, Qt, pyqtSignal, pyqtSlot
from PyQt6.QtGui import QAction, QIcon
@@ -319,7 +320,7 @@ class GuiOutlineToolBar(QToolBar):
class GuiOutlineTree(QTreeWidget):
DEF_WIDTH = {
DEF_WIDTH: Final[dict[nwOutline, int]] = {
nwOutline.TITLE: 200,
nwOutline.LEVEL: 40,
nwOutline.LABEL: 150,
@@ -342,7 +343,7 @@ class GuiOutlineTree(QTreeWidget):
nwOutline.SYNOP: 200,
}
DEF_HIDDEN = {
DEF_HIDDEN: Final[dict[nwOutline, bool]] = {
nwOutline.TITLE: False,
nwOutline.LEVEL: True,
nwOutline.LABEL: False,
@@ -498,7 +499,7 @@ class GuiOutlineTree(QTreeWidget):
tree.
"""
# If it's the first time, we always build
if self._firstView or self._firstView and overRide:
if self._firstView or (self._firstView and overRide):
self._loadHeaderState()
self._populateTree(rootHandle)
self._firstView = False
@@ -558,7 +559,7 @@ class GuiOutlineTree(QTreeWidget):
logger.info("Writing CSV file: %s", path)
cols = [col for col in self._treeOrder if not self._colHidden[col]]
order = [self._colIdx[col] for col in cols]
with open(path, mode="w", newline="") as csvFile:
with open(path, mode="w", newline="", encoding="utf-8") as csvFile:
writer = csv.writer(csvFile, dialect="excel", quoting=csv.QUOTE_ALL)
writer.writerow([trConst(nwLabels.OUTLINE_COLS[col]) for col in cols])
for i in range(self.topLevelItemCount()):
@@ -795,7 +796,7 @@ class GuiOutlineHeaderMenu(QMenu):
class GuiOutlineDetails(QScrollArea):
LVL_MAP = {
LVL_MAP: Final[dict[str, str]] = {
"H1": QT_TRANSLATE_NOOP("GuiOutlineDetails", "Title"),
"H2": QT_TRANSLATE_NOOP("GuiOutlineDetails", "Chapter"),
"H3": QT_TRANSLATE_NOOP("GuiOutlineDetails", "Scene"),
+2 -2
View File
@@ -1099,7 +1099,7 @@ class _UpdatableMenu(QMenu):
class _TreeContextMenu(QMenu):
__slots__ = ("_tree", "_view", "_node", "_item", "_model", "_handle", "_indices", "_children")
__slots__ = ("_children", "_handle", "_indices", "_item", "_model", "_node", "_tree", "_view")
def __init__(
self, projTree: GuiProjectTree, model: ProjectModel,
@@ -1327,7 +1327,7 @@ class _TreeContextMenu(QMenu):
"""Add move to Trash action."""
if (
self._model.trashSelection(self._indices)
or len(self._indices) == 1 and self._item.isRootType()
or (len(self._indices) == 1 and self._item.isRootType())
):
text = self.tr("Delete Permanently")
else:
+4 -1
View File
@@ -26,6 +26,7 @@ from __future__ import annotations
import logging
from time import time
from typing import TYPE_CHECKING
from PyQt6.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt6.QtGui import QAction, QCursor, QKeyEvent, QPalette
@@ -37,12 +38,14 @@ from PyQt6.QtWidgets import (
from novelwriter import CONFIG, SHARED
from novelwriter.common import checkInt, qtAddAction
from novelwriter.core.coretools import DocSearch
from novelwriter.core.item import NWItem
from novelwriter.types import (
QtAlignMiddle, QtAlignRight, QtHeaderStretch, QtHeaderToContents,
QtHexArgb, QtUserRole
)
if TYPE_CHECKING:
from novelwriter.core.item import NWItem
logger = logging.getLogger(__name__)
+1 -1
View File
@@ -37,7 +37,7 @@ from novelwriter.extensions.eventfilters import StatusTipFilter
from novelwriter.extensions.modified import NIconToolButton
from novelwriter.gui.theme import STYLES_BIG_TOOLBUTTON
if TYPE_CHECKING: # pragma: no cover
if TYPE_CHECKING:
from novelwriter.guimain import GuiMain
logger = logging.getLogger(__name__)
+20 -22
View File
@@ -27,7 +27,7 @@ from __future__ import annotations
import logging
from math import ceil
from pathlib import Path
from typing import TYPE_CHECKING, Final
from PyQt6.QtCore import QSize, Qt
from PyQt6.QtGui import (
@@ -44,6 +44,9 @@ from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
from novelwriter.error import logException
from novelwriter.types import QtBlack, QtHexArgb, QtPaintAntiAlias, QtTransparent
if TYPE_CHECKING:
from pathlib import Path
logger = logging.getLogger(__name__)
STYLES_FLAT_TABS = "flatTabWidget"
@@ -93,18 +96,13 @@ class GuiTheme:
"""
__slots__ = (
# Attributes
"iconCache", "themeMeta", "isDarkTheme", "helpText", "fadedText", "errorText",
"syntaxMeta", "syntaxTheme", "guiFont", "guiFontB", "guiFontBU", "guiFontSmall",
"fontPointSize", "fontPixelSize", "baseIconHeight", "baseButtonHeight", "textNHeight",
"textNWidth", "baseIconSize", "buttonIconSize", "guiFontFixed",
# Functions
"getIcon", "getPixmap", "getItemIcon", "getIconColor", "getToggleIcon", "getDecoration",
"getHeaderDecoration", "getHeaderDecorationNarrow",
# Internal
"_guiPalette", "_themeList", "_syntaxList", "_availThemes", "_availSyntax", "_styleSheets",
"_availSyntax", "_availThemes", "_guiPalette", "_styleSheets", "_syntaxList", "_themeList",
"baseButtonHeight", "baseIconHeight", "baseIconSize", "buttonIconSize", "errorText",
"fadedText", "fontPixelSize", "fontPointSize", "getDecoration", "getHeaderDecoration",
"getHeaderDecorationNarrow", "getIcon", "getIconColor", "getItemIcon", "getPixmap",
"getToggleIcon", "guiFont", "guiFontB", "guiFontBU", "guiFontFixed", "guiFontSmall",
"helpText", "iconCache", "isDarkTheme", "syntaxMeta", "syntaxTheme", "textNHeight",
"textNWidth", "themeMeta",
)
def __init__(self) -> None:
@@ -164,9 +162,9 @@ class GuiTheme:
fHeight = qMetric.height()
fAscent = qMetric.ascent()
self.fontPointSize = self.guiFont.pointSizeF()
self.fontPixelSize = int(round(fHeight))
self.baseIconHeight = int(round(fAscent))
self.baseButtonHeight = int(round(1.35*fAscent))
self.fontPixelSize = round(fHeight)
self.baseIconHeight = round(fAscent)
self.baseButtonHeight = round(1.35*fAscent)
self.textNHeight = qMetric.boundingRect("N").height()
self.textNWidth = qMetric.boundingRect("N").width()
@@ -202,7 +200,7 @@ class GuiTheme:
qMetrics = QFontMetrics(font)
else:
qMetrics = QFontMetrics(self.guiFont)
return int(ceil(qMetrics.boundingRect(text).width()))
return ceil(qMetrics.boundingRect(text).width())
##
# Theme Methods
@@ -567,16 +565,16 @@ class GuiIcons:
"""
__slots__ = (
"mainTheme", "themeMeta", "_svgData", "_svgColors", "_qColors",
"_qIcons", "_headerDec", "_headerDecNarrow", "_availThemes",
"_themeList", "_noIcon",
"_availThemes", "_headerDec", "_headerDecNarrow", "_noIcon",
"_qColors", "_qIcons", "_svgColors", "_svgData", "_themeList",
"mainTheme", "themeMeta",
)
TOGGLE_ICON_KEYS: dict[str, tuple[str, str]] = {
TOGGLE_ICON_KEYS: Final[dict[str, tuple[str, str]]] = {
"bullet": ("bullet-on", "bullet-off"),
"unfold": ("unfold-show", "unfold-hide"),
}
IMAGE_MAP: dict[str, tuple[str, str]] = {
IMAGE_MAP: Final[dict[str, tuple[str, str]]] = {
"welcome": ("welcome-light.jpg", "welcome-dark.jpg"),
"nw-text": ("novelwriter-text-light.svg", "novelwriter-text-dark.svg"),
}