Use Ruff for linting and fix a ton of issues

This commit is contained in:
Veronica Berglyd Olsen
2025-04-03 01:15:52 +02:00
parent d2796d27c3
commit 53a2d0e691
43 changed files with 257 additions and 235 deletions
+14 -14
View File
@@ -333,7 +333,7 @@ class GuiManuscript(NToolDialog):
def _deleteSelectedBuild(self) -> None:
"""Delete the currently selected build settings entry."""
if build := self._getSelectedBuild():
if SHARED.question(self.tr("Delete build '{0}'?".format(build.name))):
if SHARED.question(self.tr("Delete build '{0}'?").format(build.name)):
if dialog := self._findSettingsDialog(build.buildID):
dialog.close()
self._builds.removeBuild(build.buildID)
@@ -977,23 +977,23 @@ class _StatsWidget(QWidget):
def updateStats(self, data: dict[str, int]) -> None:
"""Update the stats values from a Tokenizer stats dict."""
# Minimal
self.minWordCount.setText("{0:n}".format(data.get(nwStats.WORDS, 0)))
self.minCharCount.setText("{0:n}".format(data.get(nwStats.CHARS, 0)))
self.minWordCount.setText(f"{data.get(nwStats.WORDS, 0):n}")
self.minCharCount.setText(f"{data.get(nwStats.CHARS, 0):n}")
# Maximal
self.maxTotalWords.setText("{0:n}".format(data.get(nwStats.WORDS, 0)))
self.maxHeadWords.setText("{0:n}".format(data.get(nwStats.WORDS_TITLE, 0)))
self.maxTextWords.setText("{0:n}".format(data.get(nwStats.WORDS_TEXT, 0)))
self.maxTitleCount.setText("{0:n}".format(data.get(nwStats.TITLES, 0)))
self.maxParCount.setText("{0:n}".format(data.get(nwStats.PARAGRAPHS, 0)))
self.maxTotalWords.setText(f"{data.get(nwStats.WORDS, 0):n}")
self.maxHeadWords.setText(f"{data.get(nwStats.WORDS_TITLE, 0):n}")
self.maxTextWords.setText(f"{data.get(nwStats.WORDS_TEXT, 0):n}")
self.maxTitleCount.setText(f"{data.get(nwStats.TITLES, 0):n}")
self.maxParCount.setText(f"{data.get(nwStats.PARAGRAPHS, 0):n}")
self.maxTotalChars.setText("{0:n}".format(data.get(nwStats.CHARS, 0)))
self.maxHeaderChars.setText("{0:n}".format(data.get(nwStats.CHARS_TITLE, 0)))
self.maxTextChars.setText("{0:n}".format(data.get(nwStats.CHARS_TEXT, 0)))
self.maxTotalChars.setText(f"{data.get(nwStats.CHARS, 0):n}")
self.maxHeaderChars.setText(f"{data.get(nwStats.CHARS_TITLE, 0):n}")
self.maxTextChars.setText(f"{data.get(nwStats.CHARS_TEXT, 0):n}")
self.maxTotalWordChars.setText("{0:n}".format(data.get(nwStats.WCHARS_ALL, 0)))
self.maxHeadWordChars.setText("{0:n}".format(data.get(nwStats.WCHARS_TITLE, 0)))
self.maxTextWordChars.setText("{0:n}".format(data.get(nwStats.WCHARS_TEXT, 0)))
self.maxTotalWordChars.setText(f"{data.get(nwStats.WCHARS_ALL, 0):n}")
self.maxHeadWordChars.setText(f"{data.get(nwStats.WCHARS_TITLE, 0):n}")
self.maxTextWordChars.setText(f"{data.get(nwStats.WCHARS_TEXT, 0):n}")
return
+4 -4
View File
@@ -228,8 +228,8 @@ class GuiBuildSettings(NToolDialog):
"""
if self._build.changed:
response = SHARED.question(self.tr(
"Do you want to save your changes to '{0}'?".format(self._build.name)
))
"Do you want to save your changes to '{0}'?"
).format(self._build.name))
if response:
self._emitBuildData()
self._build.resetChangedState()
@@ -1168,11 +1168,11 @@ class _FormattingTab(NScrollableForm):
for key, name in nwLabels.PAPER_NAME.items():
self.pageSize.addItem(trConst(name), key)
self.pageWidth = NDoubleSpinBox(self, max=500.0)
self.pageWidth = NDoubleSpinBox(self, maxVal=500.0)
self.pageWidth.setFixedWidth(dbW)
self.pageWidth.valueChanged.connect(self._pageSizeValueChanged)
self.pageHeight = NDoubleSpinBox(self, max=500.0)
self.pageHeight = NDoubleSpinBox(self, maxVal=500.0)
self.pageHeight.setFixedWidth(dbW)
self.pageHeight.valueChanged.connect(self._pageSizeValueChanged)
+2 -2
View File
@@ -447,7 +447,7 @@ class GuiWritingStats(NToolDialog):
rType = record.get("type")
if rType == "initial":
self.wordOffset = checkInt(record.get("offset"), 0)
logger.debug("Initial word count when log was started is %d" % self.wordOffset)
logger.debug("Initial word count when log was started is %d", self.wordOffset)
elif rType == "record":
try:
dStart = datetime.fromisoformat(str(record.get("start")))
@@ -570,7 +570,7 @@ class GuiWritingStats(NToolDialog):
idleEntry = formatTime(sIdle)
else:
sRatio = sIdle/sDiff if sDiff > 0.0 else 0.0
idleEntry = "%d %%" % round(100.0 * sRatio)
idleEntry = f"{round(100.0 * sRatio)} %"
newItem = QTreeWidgetItem()
newItem.setText(self.C_TIME, sStart)