From 00f0a6887c1d43328c1b2206f3e546cb7dcffb38 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Wed, 12 Aug 2020 21:41:37 +0200 Subject: [PATCH] Fixed flake8 W and F errors --- nw/__init__.py | 4 ++-- nw/common.py | 1 - nw/config.py | 3 +-- nw/core/index.py | 3 --- nw/core/item.py | 29 ++++++++++++++--------------- nw/core/project.py | 29 ++++++++++++++--------------- nw/core/spellcheck.py | 2 +- nw/core/status.py | 1 - nw/core/tohtml.py | 7 ------- nw/core/tools.py | 1 - nw/core/tree.py | 1 - nw/gui/build.py | 1 - nw/gui/doceditor.py | 7 ------- nw/gui/docviewer.py | 2 -- nw/gui/outline.py | 1 - nw/gui/outlinedetails.py | 3 +-- nw/gui/preferences.py | 1 - nw/gui/projsettings.py | 1 - nw/gui/projtree.py | 4 +--- nw/gui/statusbar.py | 1 - nw/gui/theme.py | 6 +++++- nw/guimain.py | 5 ++--- 22 files changed, 41 insertions(+), 72 deletions(-) diff --git a/nw/__init__.py b/nw/__init__.py index 33d36450..603ded31 100644 --- a/nw/__init__.py +++ b/nw/__init__.py @@ -239,12 +239,12 @@ def main(sysArgs=None): ) try: - import PyQt5.QtSvg + import PyQt5.QtSvg # noqa: F401 except ImportError: errorData.append("Python module 'PyQt5.QtSvg' is missing.") try: - import lxml + import lxml # noqa: F401 except ImportError: errorData.append("Python module 'lxml' is missing.") diff --git a/nw/common.py b/nw/common.py index 2f5fca4e..71aa4873 100644 --- a/nw/common.py +++ b/nw/common.py @@ -26,7 +26,6 @@ """ import logging -import nw from datetime import datetime diff --git a/nw/config.py b/nw/config.py index 96c5a71b..3c3915b7 100644 --- a/nw/config.py +++ b/nw/config.py @@ -29,7 +29,6 @@ import logging import configparser import json import sys -import nw from os import path, mkdir, unlink, rename from time import time @@ -902,7 +901,7 @@ class Config: """Cheks if we have the optional packages used by some features. """ try: - import enchant + import enchant # noqa: F401 self.hasEnchant = True logger.debug("Checking package 'pyenchant': Ok") except Exception: diff --git a/nw/core/index.py b/nw/core/index.py index b793ecc2..c542a459 100644 --- a/nw/core/index.py +++ b/nw/core/index.py @@ -27,7 +27,6 @@ import logging import json -import nw from os import path from time import time @@ -603,8 +602,6 @@ class NWIndex(): by tHandle. """ theRefs = {} - - tItem = self.theProject.projTree[tHandle] if tHandle is None: return theRefs diff --git a/nw/core/item.py b/nw/core/item.py index 09f3571b..6e8048f1 100644 --- a/nw/core/item.py +++ b/nw/core/item.py @@ -26,7 +26,6 @@ """ import logging -import nw from lxml import etree @@ -73,19 +72,19 @@ class NWItem(): "order" : str(self.itemOrder), "parent" : str(self.parHandle), }) - xSub = self._subPack(xPack, "name", text=str(self.itemName)) - xSub = self._subPack(xPack, "type", text=str(self.itemType.name)) - xSub = self._subPack(xPack, "class", text=str(self.itemClass.name)) - xSub = self._subPack(xPack, "status", text=str(self.itemStatus)) + self._subPack(xPack, "name", text=str(self.itemName)) + self._subPack(xPack, "type", text=str(self.itemType.name)) + self._subPack(xPack, "class", text=str(self.itemClass.name)) + self._subPack(xPack, "status", text=str(self.itemStatus)) if self.itemType == nwItemType.FILE: - xSub = self._subPack(xPack, "exported", text=str(self.isExported)) - xSub = self._subPack(xPack, "layout", text=str(self.itemLayout.name)) - xSub = self._subPack(xPack, "charCount", text=str(self.charCount), none=False) - xSub = self._subPack(xPack, "wordCount", text=str(self.wordCount), none=False) - xSub = self._subPack(xPack, "paraCount", text=str(self.paraCount), none=False) - xSub = self._subPack(xPack, "cursorPos", text=str(self.cursorPos), none=False) + self._subPack(xPack, "exported", text=str(self.isExported)) + self._subPack(xPack, "layout", text=str(self.itemLayout.name)) + self._subPack(xPack, "charCount", text=str(self.charCount), none=False) + self._subPack(xPack, "wordCount", text=str(self.wordCount), none=False) + self._subPack(xPack, "paraCount", text=str(self.paraCount), none=False) + self._subPack(xPack, "cursorPos", text=str(self.cursorPos), none=False) else: - xSub = self._subPack(xPack, "expanded", text=str(self.isExpanded)) + self._subPack(xPack, "expanded", text=str(self.isExpanded)) return def unpackXML(self, xItem): @@ -135,7 +134,7 @@ class NWItem(): xSub = etree.SubElement(xParent, name, attrib=attrib) if text is not None: xSub.text = text - return xSub + return ## # Set Item Values @@ -235,7 +234,7 @@ class NWItem(): if isinstance(expState, str): self.isExpanded = (expState == str(True)) else: - self.isExpanded = (expState == True) # noqa + self.isExpanded = (expState == True) # noqa: E712 return def setExported(self, expState): @@ -244,7 +243,7 @@ class NWItem(): if isinstance(expState, str): self.isExported = (expState == str(True)) else: - self.isExported = (expState == True) # noqa + self.isExported = (expState == True) # noqa: E712 return ## diff --git a/nw/core/project.py b/nw/core/project.py index 70ccc853..1844c9cb 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -26,7 +26,6 @@ """ import logging -import json import nw from os import path, mkdir, listdir, unlink, rename, rmdir @@ -265,27 +264,28 @@ class NWProject(): if popMinimal: # Creating a minimal project with a few root folders and a # single chapter folder with a single file. - nHandle = self.newRoot("Novel", nwItemClass.NOVEL) - xHandle = self.newRoot("Plot", nwItemClass.PLOT) - xHandle = self.newRoot("Characters", nwItemClass.CHARACTER) - xHandle = self.newRoot("World", nwItemClass.WORLD) - tHandle = self.newFile("Title Page", nwItemClass.NOVEL, nHandle) - dHandle = self.newFolder("New Chapter", nwItemClass.NOVEL, nHandle) - cHandle = self.newFile("New Chapter", nwItemClass.NOVEL, dHandle) - sHandle = self.newFile("New Scene", nwItemClass.NOVEL, dHandle) + xHandle = {} + xHandle[1] = self.newRoot("Novel", nwItemClass.NOVEL) + xHandle[2] = self.newRoot("Plot", nwItemClass.PLOT) + xHandle[3] = self.newRoot("Characters", nwItemClass.CHARACTER) + xHandle[4] = self.newRoot("World", nwItemClass.WORLD) + xHandle[5] = self.newFile("Title Page", nwItemClass.NOVEL, xHandle[1]) + xHandle[6] = self.newFolder("New Chapter", nwItemClass.NOVEL, xHandle[1]) + xHandle[7] = self.newFile("New Chapter", nwItemClass.NOVEL, xHandle[6]) + xHandle[8] = self.newFile("New Scene", nwItemClass.NOVEL, xHandle[6]) - self.projTree.setFileItemLayout(tHandle, nwItemLayout.TITLE) - self.projTree.setFileItemLayout(cHandle, nwItemLayout.CHAPTER) + self.projTree.setFileItemLayout(xHandle[5], nwItemLayout.TITLE) + self.projTree.setFileItemLayout(xHandle[7], nwItemLayout.CHAPTER) - aDoc.openDocument(tHandle, showStatus=False) + aDoc.openDocument(xHandle[5], showStatus=False) aDoc.saveDocument(titlePage) aDoc.clearDocument() - aDoc.openDocument(cHandle, showStatus=False) + aDoc.openDocument(xHandle[7], showStatus=False) aDoc.saveDocument("## New Chapter\n\n") aDoc.clearDocument() - aDoc.openDocument(sHandle, showStatus=False) + aDoc.openDocument(xHandle[8], showStatus=False) aDoc.saveDocument("### New Scene\n\n") aDoc.clearDocument() @@ -838,7 +838,6 @@ class NWProject(): project path, or if the folder doesn't exist, look for the zip file in the assets folder. """ - projName = projData.get("projName", "Sample Project") projPath = projData.get("projPath", None) if projPath is None: logger.error("No project path set for the example project") diff --git a/nw/core/spellcheck.py b/nw/core/spellcheck.py index 296b1605..e904eae5 100644 --- a/nw/core/spellcheck.py +++ b/nw/core/spellcheck.py @@ -197,7 +197,7 @@ class NWSpellEnchantDummy: """ def __init__(self): return - + def check(self, theWord): return True diff --git a/nw/core/status.py b/nw/core/status.py index 6b67ac67..eac1a52a 100644 --- a/nw/core/status.py +++ b/nw/core/status.py @@ -26,7 +26,6 @@ """ import logging -import nw from lxml import etree diff --git a/nw/core/tohtml.py b/nw/core/tohtml.py index 95d3089f..74c5a676 100644 --- a/nw/core/tohtml.py +++ b/nw/core/tohtml.py @@ -27,7 +27,6 @@ import logging import re -import nw from nw.core.tokenizer import Tokenizer from nw.constants import nwUnicode, nwLabels, nwKeyWords @@ -153,12 +152,6 @@ class ToHtml(Tokenizer): h3 = "h3" h4 = "h4" - alignHead = self.A_LEFT - if self.doJustify: - alignPar = self.A_JUSTIFY - else: - alignPar = self.A_LEFT - self.theResult = "" thisPar = [] diff --git a/nw/core/tools.py b/nw/core/tools.py index 80c1c867..ff1976e9 100644 --- a/nw/core/tools.py +++ b/nw/core/tools.py @@ -28,7 +28,6 @@ """ import logging -import nw logger = logging.getLogger(__name__) diff --git a/nw/core/tree.py b/nw/core/tree.py index cde46b4e..a9e77326 100644 --- a/nw/core/tree.py +++ b/nw/core/tree.py @@ -27,7 +27,6 @@ import logging import json -import nw from os import path from lxml import etree diff --git a/nw/gui/build.py b/nw/gui/build.py index ce14db2c..336eb684 100644 --- a/nw/gui/build.py +++ b/nw/gui/build.py @@ -964,7 +964,6 @@ class GuiBuildNovelDocView(QTextBrowser): lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) fPx = int(1.1*self.theTheme.fontPixelSize) - mPx = self.mainConf.pxInt(4) self.theTitle = QLabel("Build Time: Unknown", self) self.theTitle.setIndent(0) diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 76fdc392..5eeef904 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -1372,7 +1372,6 @@ class GuiDocEditSearch(QFrame): self.doMatchCap = self.mainConf.searchMatchCap mPx = self.mainConf.pxInt(6) - fPx = int(0.9*self.theTheme.fontPixelSize) tPx = int(0.8*self.theTheme.fontPixelSize) boxFont = self.theTheme.guiFont boxFont.setPointSizeF(0.9*self.theTheme.fontPointSize) @@ -1892,7 +1891,6 @@ class GuiDocEditFooter(QWidget): self.sPx = int(round(0.9*self.theTheme.baseIconSize)) fPx = int(0.9*self.theTheme.fontPixelSize) bSp = self.mainConf.pxInt(4) - hSp = self.mainConf.pxInt(8) lblFont = self.font() lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) @@ -1902,11 +1900,6 @@ class GuiDocEditFooter(QWidget): self.setAutoFillBackground(True) self.setPalette(self.thePalette) - buttonStyle = ( - "QToolButton {{border: none; background: transparent;}} " - "QToolButton:hover {{border: none; background: rgba({0},{1},{2},0.2);}}" - ).format(*self.theTheme.colText) - # Status self.statusIcon = QLabel("") self.statusIcon.setContentsMargins(0, 0, 0, 0) diff --git a/nw/gui/docviewer.py b/nw/gui/docviewer.py index 50c86b72..13707ae9 100644 --- a/nw/gui/docviewer.py +++ b/nw/gui/docviewer.py @@ -366,7 +366,6 @@ class GuiDocViewer(QTextBrowser): "}}\n" ).format( textSize = self.mainConf.textSize, - preSize = self.mainConf.textSize*0.9, tColR = self.theTheme.colText[0], tColG = self.theTheme.colText[1], tColB = self.theTheme.colText[2], @@ -701,7 +700,6 @@ class GuiDocViewDetails(QScrollArea): self.refList.setScaledContents(True) self.refList.linkActivated.connect(self._linkClicked) - hCol = self.palette().highlight().color() self.linkStyle = "style='color: rgb({0},{1},{2})'".format( *self.theTheme.colLink ) diff --git a/nw/gui/outline.py b/nw/gui/outline.py index 1bc245b7..039e2f3f 100644 --- a/nw/gui/outline.py +++ b/nw/gui/outline.py @@ -374,7 +374,6 @@ class GuiOutline(QTreeWidget): continue tLevel = self.theIndex.novelIndex[tHandle][sTitle]["level"] - tTime = self.theIndex.novelIndex[tHandle][sTitle]["updated"] tItem = self._createTreeItem(tHandle, sTitle, tLevel) self.treeMap[titleKey] = tItem diff --git a/nw/gui/outlinedetails.py b/nw/gui/outlinedetails.py index 89aa7a3e..9e53653f 100644 --- a/nw/gui/outlinedetails.py +++ b/nw/gui/outlinedetails.py @@ -30,8 +30,7 @@ import nw from PyQt5.QtCore import Qt from PyQt5.QtWidgets import ( - QScrollArea, QWidget, QGridLayout, QHBoxLayout, QGroupBox, QLabel, - QSizePolicy + QScrollArea, QWidget, QGridLayout, QHBoxLayout, QGroupBox, QLabel ) from nw.constants import nwLabels, nwKeyWords diff --git a/nw/gui/preferences.py b/nw/gui/preferences.py index 3cdb515e..e7052671 100644 --- a/nw/gui/preferences.py +++ b/nw/gui/preferences.py @@ -720,7 +720,6 @@ class GuiConfigEditEditingTab(QWidget): def _disableComboItem(self, theList, theValue): """Disable a list item in the combo box. """ - theIdx = theList.findData(theValue) theModel = theList.model() anItem = theModel.item(1) anItem.setFlags(anItem.flags() ^ Qt.ItemIsEnabled) diff --git a/nw/gui/projsettings.py b/nw/gui/projsettings.py index 1eabac39..44f39d5b 100644 --- a/nw/gui/projsettings.py +++ b/nw/gui/projsettings.py @@ -422,7 +422,6 @@ class GuiProjectEditStatus(QWidget): """ logger.verbose("Save item button clicked") selItem = self._getSelectedItem() - iRow = self.listBox.row(selItem) if selItem is not None: selIdx = selItem.data(Qt.UserRole) self.colData[selIdx] = ( diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index 77fd881a..a4a9b8f7 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -475,7 +475,6 @@ class GuiProjectTree(QTreeWidget): tName = nwItem.itemName tClass = nwItem.itemClass tHandle = nwItem.itemHandle - pHandle = nwItem.parHandle expIcon = QIcon() @@ -670,7 +669,6 @@ class GuiProjectTree(QTreeWidget): isNote = snItem.itemLayout == nwItemLayout.NOTE onFile = dnItem.itemType == nwItemType.FILE isRoot = snItem.itemType == nwItemType.ROOT - onRoot = dnItem.itemType == nwItemType.ROOT isOnTop = self.dropIndicatorPosition() == QAbstractItemView.OnItem if (isSame or isNone or isNote) and not (onFile and isOnTop) and not isRoot: logger.debug("Drag'n'drop of item %s accepted" % sHandle) @@ -758,7 +756,7 @@ class GuiProjectTree(QTreeWidget): byIndex = self.theMap[pHandle].indexOfChild(self.theMap[nHandle]) except Exception: logger.error("Failed to get index of item with handle %s" % nHandle) - if byIndex >= 0: + if byIndex >= 0: self.theMap[pHandle].insertChild(byIndex+1, newItem) else: self.theMap[pHandle].addChild(newItem) diff --git a/nw/gui/statusbar.py b/nw/gui/statusbar.py index 907937d4..ab5fe23a 100644 --- a/nw/gui/statusbar.py +++ b/nw/gui/statusbar.py @@ -35,7 +35,6 @@ from PyQt5.QtGui import QColor, QPainter from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton from nw.core import NWSpellCheck -from nw.common import formatInt logger = logging.getLogger(__name__) diff --git a/nw/gui/theme.py b/nw/gui/theme.py index 74642bef..3ec6d717 100644 --- a/nw/gui/theme.py +++ b/nw/gui/theme.py @@ -33,7 +33,7 @@ import nw from os import path, listdir from math import ceil -from PyQt5.QtCore import Qt, QSize +from PyQt5.QtCore import Qt from PyQt5.QtSvg import QSvgWidget from PyQt5.QtWidgets import QStyle, qApp from PyQt5.QtGui import ( @@ -260,6 +260,7 @@ class GuiTheme: cssData = inFile.read() except Exception as e: logger.error("Could not load theme css file") + logger.error(str(e)) return False # Config File @@ -269,6 +270,7 @@ class GuiTheme: confParser.read_file(inFile) except Exception as e: logger.error("Could not load theme settings from: %s" % self.confFile) + logger.error(str(e)) return False ## Main @@ -324,6 +326,7 @@ class GuiTheme: confParser.read_file(inFile) except Exception as e: logger.error("Could not load syntax colours from: %s" % self.syntaxFile) + logger.error(str(e)) return False ## Main @@ -615,6 +618,7 @@ class GuiIcons: confParser.read_file(inFile) except Exception as e: logger.error("Could not load icon theme settings from: %s" % self.confFile) + logger.error(str(e)) return False ## Main diff --git a/nw/guimain.py b/nw/guimain.py index 33f42d8f..9267a49d 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -269,7 +269,7 @@ class GuiMain(QMainWindow): """ if self.hasProject: msgBox = QMessageBox() - msgRes = msgBox.warning( + msgBox.warning( self, "New Project", "Please close the current project before making a new one." ) @@ -288,7 +288,7 @@ class GuiMain(QMainWindow): if path.isfile(path.join(projPath, self.theProject.projFile)) and not forceNew: msgBox = QMessageBox() - msgRes = msgBox.critical( + msgBox.critical( self, "New Project", "A project already exists in that location. Please choose another folder." ) @@ -713,7 +713,6 @@ class GuiMain(QMainWindow): self.treeView.saveTreeOrder() self.theIndex.clearIndex() - nItems = len(self.theProject.projTree) theDoc = NWDoc(self.theProject, self) for nDone, tItem in enumerate(self.theProject.projTree):