Fixed flake8 W and F errors

This commit is contained in:
Veronica K. B. Olsen
2020-08-12 21:41:37 +02:00
parent 72cb1ed60f
commit 00f0a6887c
22 changed files with 41 additions and 72 deletions
+2 -2
View File
@@ -239,12 +239,12 @@ def main(sysArgs=None):
) )
try: try:
import PyQt5.QtSvg import PyQt5.QtSvg # noqa: F401
except ImportError: except ImportError:
errorData.append("Python module 'PyQt5.QtSvg' is missing.") errorData.append("Python module 'PyQt5.QtSvg' is missing.")
try: try:
import lxml import lxml # noqa: F401
except ImportError: except ImportError:
errorData.append("Python module 'lxml' is missing.") errorData.append("Python module 'lxml' is missing.")
-1
View File
@@ -26,7 +26,6 @@
""" """
import logging import logging
import nw
from datetime import datetime from datetime import datetime
+1 -2
View File
@@ -29,7 +29,6 @@ import logging
import configparser import configparser
import json import json
import sys import sys
import nw
from os import path, mkdir, unlink, rename from os import path, mkdir, unlink, rename
from time import time from time import time
@@ -902,7 +901,7 @@ class Config:
"""Cheks if we have the optional packages used by some features. """Cheks if we have the optional packages used by some features.
""" """
try: try:
import enchant import enchant # noqa: F401
self.hasEnchant = True self.hasEnchant = True
logger.debug("Checking package 'pyenchant': Ok") logger.debug("Checking package 'pyenchant': Ok")
except Exception: except Exception:
-3
View File
@@ -27,7 +27,6 @@
import logging import logging
import json import json
import nw
from os import path from os import path
from time import time from time import time
@@ -603,8 +602,6 @@ class NWIndex():
by tHandle. by tHandle.
""" """
theRefs = {} theRefs = {}
tItem = self.theProject.projTree[tHandle]
if tHandle is None: if tHandle is None:
return theRefs return theRefs
+14 -15
View File
@@ -26,7 +26,6 @@
""" """
import logging import logging
import nw
from lxml import etree from lxml import etree
@@ -73,19 +72,19 @@ class NWItem():
"order" : str(self.itemOrder), "order" : str(self.itemOrder),
"parent" : str(self.parHandle), "parent" : str(self.parHandle),
}) })
xSub = self._subPack(xPack, "name", text=str(self.itemName)) self._subPack(xPack, "name", text=str(self.itemName))
xSub = self._subPack(xPack, "type", text=str(self.itemType.name)) self._subPack(xPack, "type", text=str(self.itemType.name))
xSub = self._subPack(xPack, "class", text=str(self.itemClass.name)) self._subPack(xPack, "class", text=str(self.itemClass.name))
xSub = self._subPack(xPack, "status", text=str(self.itemStatus)) self._subPack(xPack, "status", text=str(self.itemStatus))
if self.itemType == nwItemType.FILE: if self.itemType == nwItemType.FILE:
xSub = self._subPack(xPack, "exported", text=str(self.isExported)) self._subPack(xPack, "exported", text=str(self.isExported))
xSub = self._subPack(xPack, "layout", text=str(self.itemLayout.name)) self._subPack(xPack, "layout", text=str(self.itemLayout.name))
xSub = self._subPack(xPack, "charCount", text=str(self.charCount), none=False) self._subPack(xPack, "charCount", text=str(self.charCount), none=False)
xSub = self._subPack(xPack, "wordCount", text=str(self.wordCount), none=False) self._subPack(xPack, "wordCount", text=str(self.wordCount), none=False)
xSub = self._subPack(xPack, "paraCount", text=str(self.paraCount), none=False) self._subPack(xPack, "paraCount", text=str(self.paraCount), none=False)
xSub = self._subPack(xPack, "cursorPos", text=str(self.cursorPos), none=False) self._subPack(xPack, "cursorPos", text=str(self.cursorPos), none=False)
else: else:
xSub = self._subPack(xPack, "expanded", text=str(self.isExpanded)) self._subPack(xPack, "expanded", text=str(self.isExpanded))
return return
def unpackXML(self, xItem): def unpackXML(self, xItem):
@@ -135,7 +134,7 @@ class NWItem():
xSub = etree.SubElement(xParent, name, attrib=attrib) xSub = etree.SubElement(xParent, name, attrib=attrib)
if text is not None: if text is not None:
xSub.text = text xSub.text = text
return xSub return
## ##
# Set Item Values # Set Item Values
@@ -235,7 +234,7 @@ class NWItem():
if isinstance(expState, str): if isinstance(expState, str):
self.isExpanded = (expState == str(True)) self.isExpanded = (expState == str(True))
else: else:
self.isExpanded = (expState == True) # noqa self.isExpanded = (expState == True) # noqa: E712
return return
def setExported(self, expState): def setExported(self, expState):
@@ -244,7 +243,7 @@ class NWItem():
if isinstance(expState, str): if isinstance(expState, str):
self.isExported = (expState == str(True)) self.isExported = (expState == str(True))
else: else:
self.isExported = (expState == True) # noqa self.isExported = (expState == True) # noqa: E712
return return
## ##
+14 -15
View File
@@ -26,7 +26,6 @@
""" """
import logging import logging
import json
import nw import nw
from os import path, mkdir, listdir, unlink, rename, rmdir from os import path, mkdir, listdir, unlink, rename, rmdir
@@ -265,27 +264,28 @@ class NWProject():
if popMinimal: if popMinimal:
# Creating a minimal project with a few root folders and a # Creating a minimal project with a few root folders and a
# single chapter folder with a single file. # single chapter folder with a single file.
nHandle = self.newRoot("Novel", nwItemClass.NOVEL) xHandle = {}
xHandle = self.newRoot("Plot", nwItemClass.PLOT) xHandle[1] = self.newRoot("Novel", nwItemClass.NOVEL)
xHandle = self.newRoot("Characters", nwItemClass.CHARACTER) xHandle[2] = self.newRoot("Plot", nwItemClass.PLOT)
xHandle = self.newRoot("World", nwItemClass.WORLD) xHandle[3] = self.newRoot("Characters", nwItemClass.CHARACTER)
tHandle = self.newFile("Title Page", nwItemClass.NOVEL, nHandle) xHandle[4] = self.newRoot("World", nwItemClass.WORLD)
dHandle = self.newFolder("New Chapter", nwItemClass.NOVEL, nHandle) xHandle[5] = self.newFile("Title Page", nwItemClass.NOVEL, xHandle[1])
cHandle = self.newFile("New Chapter", nwItemClass.NOVEL, dHandle) xHandle[6] = self.newFolder("New Chapter", nwItemClass.NOVEL, xHandle[1])
sHandle = self.newFile("New Scene", nwItemClass.NOVEL, dHandle) 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(xHandle[5], nwItemLayout.TITLE)
self.projTree.setFileItemLayout(cHandle, nwItemLayout.CHAPTER) self.projTree.setFileItemLayout(xHandle[7], nwItemLayout.CHAPTER)
aDoc.openDocument(tHandle, showStatus=False) aDoc.openDocument(xHandle[5], showStatus=False)
aDoc.saveDocument(titlePage) aDoc.saveDocument(titlePage)
aDoc.clearDocument() aDoc.clearDocument()
aDoc.openDocument(cHandle, showStatus=False) aDoc.openDocument(xHandle[7], showStatus=False)
aDoc.saveDocument("## New Chapter\n\n") aDoc.saveDocument("## New Chapter\n\n")
aDoc.clearDocument() aDoc.clearDocument()
aDoc.openDocument(sHandle, showStatus=False) aDoc.openDocument(xHandle[8], showStatus=False)
aDoc.saveDocument("### New Scene\n\n") aDoc.saveDocument("### New Scene\n\n")
aDoc.clearDocument() aDoc.clearDocument()
@@ -838,7 +838,6 @@ class NWProject():
project path, or if the folder doesn't exist, look for the zip project path, or if the folder doesn't exist, look for the zip
file in the assets folder. file in the assets folder.
""" """
projName = projData.get("projName", "Sample Project")
projPath = projData.get("projPath", None) projPath = projData.get("projPath", None)
if projPath is None: if projPath is None:
logger.error("No project path set for the example project") logger.error("No project path set for the example project")
+1 -1
View File
@@ -197,7 +197,7 @@ class NWSpellEnchantDummy:
""" """
def __init__(self): def __init__(self):
return return
def check(self, theWord): def check(self, theWord):
return True return True
-1
View File
@@ -26,7 +26,6 @@
""" """
import logging import logging
import nw
from lxml import etree from lxml import etree
-7
View File
@@ -27,7 +27,6 @@
import logging import logging
import re import re
import nw
from nw.core.tokenizer import Tokenizer from nw.core.tokenizer import Tokenizer
from nw.constants import nwUnicode, nwLabels, nwKeyWords from nw.constants import nwUnicode, nwLabels, nwKeyWords
@@ -153,12 +152,6 @@ class ToHtml(Tokenizer):
h3 = "h3" h3 = "h3"
h4 = "h4" h4 = "h4"
alignHead = self.A_LEFT
if self.doJustify:
alignPar = self.A_JUSTIFY
else:
alignPar = self.A_LEFT
self.theResult = "" self.theResult = ""
thisPar = [] thisPar = []
-1
View File
@@ -28,7 +28,6 @@
""" """
import logging import logging
import nw
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
-1
View File
@@ -27,7 +27,6 @@
import logging import logging
import json import json
import nw
from os import path from os import path
from lxml import etree from lxml import etree
-1
View File
@@ -964,7 +964,6 @@ class GuiBuildNovelDocView(QTextBrowser):
lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize)
fPx = int(1.1*self.theTheme.fontPixelSize) fPx = int(1.1*self.theTheme.fontPixelSize)
mPx = self.mainConf.pxInt(4)
self.theTitle = QLabel("<b>Build Time:</b> Unknown", self) self.theTitle = QLabel("<b>Build Time:</b> Unknown", self)
self.theTitle.setIndent(0) self.theTitle.setIndent(0)
-7
View File
@@ -1372,7 +1372,6 @@ class GuiDocEditSearch(QFrame):
self.doMatchCap = self.mainConf.searchMatchCap self.doMatchCap = self.mainConf.searchMatchCap
mPx = self.mainConf.pxInt(6) mPx = self.mainConf.pxInt(6)
fPx = int(0.9*self.theTheme.fontPixelSize)
tPx = int(0.8*self.theTheme.fontPixelSize) tPx = int(0.8*self.theTheme.fontPixelSize)
boxFont = self.theTheme.guiFont boxFont = self.theTheme.guiFont
boxFont.setPointSizeF(0.9*self.theTheme.fontPointSize) boxFont.setPointSizeF(0.9*self.theTheme.fontPointSize)
@@ -1892,7 +1891,6 @@ class GuiDocEditFooter(QWidget):
self.sPx = int(round(0.9*self.theTheme.baseIconSize)) self.sPx = int(round(0.9*self.theTheme.baseIconSize))
fPx = int(0.9*self.theTheme.fontPixelSize) fPx = int(0.9*self.theTheme.fontPixelSize)
bSp = self.mainConf.pxInt(4) bSp = self.mainConf.pxInt(4)
hSp = self.mainConf.pxInt(8)
lblFont = self.font() lblFont = self.font()
lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize)
@@ -1902,11 +1900,6 @@ class GuiDocEditFooter(QWidget):
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
self.setPalette(self.thePalette) 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 # Status
self.statusIcon = QLabel("") self.statusIcon = QLabel("")
self.statusIcon.setContentsMargins(0, 0, 0, 0) self.statusIcon.setContentsMargins(0, 0, 0, 0)
-2
View File
@@ -366,7 +366,6 @@ class GuiDocViewer(QTextBrowser):
"}}\n" "}}\n"
).format( ).format(
textSize = self.mainConf.textSize, textSize = self.mainConf.textSize,
preSize = self.mainConf.textSize*0.9,
tColR = self.theTheme.colText[0], tColR = self.theTheme.colText[0],
tColG = self.theTheme.colText[1], tColG = self.theTheme.colText[1],
tColB = self.theTheme.colText[2], tColB = self.theTheme.colText[2],
@@ -701,7 +700,6 @@ class GuiDocViewDetails(QScrollArea):
self.refList.setScaledContents(True) self.refList.setScaledContents(True)
self.refList.linkActivated.connect(self._linkClicked) self.refList.linkActivated.connect(self._linkClicked)
hCol = self.palette().highlight().color()
self.linkStyle = "style='color: rgb({0},{1},{2})'".format( self.linkStyle = "style='color: rgb({0},{1},{2})'".format(
*self.theTheme.colLink *self.theTheme.colLink
) )
-1
View File
@@ -374,7 +374,6 @@ class GuiOutline(QTreeWidget):
continue continue
tLevel = self.theIndex.novelIndex[tHandle][sTitle]["level"] tLevel = self.theIndex.novelIndex[tHandle][sTitle]["level"]
tTime = self.theIndex.novelIndex[tHandle][sTitle]["updated"]
tItem = self._createTreeItem(tHandle, sTitle, tLevel) tItem = self._createTreeItem(tHandle, sTitle, tLevel)
self.treeMap[titleKey] = tItem self.treeMap[titleKey] = tItem
+1 -2
View File
@@ -30,8 +30,7 @@ import nw
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QScrollArea, QWidget, QGridLayout, QHBoxLayout, QGroupBox, QLabel, QScrollArea, QWidget, QGridLayout, QHBoxLayout, QGroupBox, QLabel
QSizePolicy
) )
from nw.constants import nwLabels, nwKeyWords from nw.constants import nwLabels, nwKeyWords
-1
View File
@@ -720,7 +720,6 @@ class GuiConfigEditEditingTab(QWidget):
def _disableComboItem(self, theList, theValue): def _disableComboItem(self, theList, theValue):
"""Disable a list item in the combo box. """Disable a list item in the combo box.
""" """
theIdx = theList.findData(theValue)
theModel = theList.model() theModel = theList.model()
anItem = theModel.item(1) anItem = theModel.item(1)
anItem.setFlags(anItem.flags() ^ Qt.ItemIsEnabled) anItem.setFlags(anItem.flags() ^ Qt.ItemIsEnabled)
-1
View File
@@ -422,7 +422,6 @@ class GuiProjectEditStatus(QWidget):
""" """
logger.verbose("Save item button clicked") logger.verbose("Save item button clicked")
selItem = self._getSelectedItem() selItem = self._getSelectedItem()
iRow = self.listBox.row(selItem)
if selItem is not None: if selItem is not None:
selIdx = selItem.data(Qt.UserRole) selIdx = selItem.data(Qt.UserRole)
self.colData[selIdx] = ( self.colData[selIdx] = (
+1 -3
View File
@@ -475,7 +475,6 @@ class GuiProjectTree(QTreeWidget):
tName = nwItem.itemName tName = nwItem.itemName
tClass = nwItem.itemClass tClass = nwItem.itemClass
tHandle = nwItem.itemHandle tHandle = nwItem.itemHandle
pHandle = nwItem.parHandle
expIcon = QIcon() expIcon = QIcon()
@@ -670,7 +669,6 @@ class GuiProjectTree(QTreeWidget):
isNote = snItem.itemLayout == nwItemLayout.NOTE isNote = snItem.itemLayout == nwItemLayout.NOTE
onFile = dnItem.itemType == nwItemType.FILE onFile = dnItem.itemType == nwItemType.FILE
isRoot = snItem.itemType == nwItemType.ROOT isRoot = snItem.itemType == nwItemType.ROOT
onRoot = dnItem.itemType == nwItemType.ROOT
isOnTop = self.dropIndicatorPosition() == QAbstractItemView.OnItem isOnTop = self.dropIndicatorPosition() == QAbstractItemView.OnItem
if (isSame or isNone or isNote) and not (onFile and isOnTop) and not isRoot: if (isSame or isNone or isNote) and not (onFile and isOnTop) and not isRoot:
logger.debug("Drag'n'drop of item %s accepted" % sHandle) 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]) byIndex = self.theMap[pHandle].indexOfChild(self.theMap[nHandle])
except Exception: except Exception:
logger.error("Failed to get index of item with handle %s" % nHandle) 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) self.theMap[pHandle].insertChild(byIndex+1, newItem)
else: else:
self.theMap[pHandle].addChild(newItem) self.theMap[pHandle].addChild(newItem)
-1
View File
@@ -35,7 +35,6 @@ from PyQt5.QtGui import QColor, QPainter
from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton
from nw.core import NWSpellCheck from nw.core import NWSpellCheck
from nw.common import formatInt
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
+5 -1
View File
@@ -33,7 +33,7 @@ import nw
from os import path, listdir from os import path, listdir
from math import ceil from math import ceil
from PyQt5.QtCore import Qt, QSize from PyQt5.QtCore import Qt
from PyQt5.QtSvg import QSvgWidget from PyQt5.QtSvg import QSvgWidget
from PyQt5.QtWidgets import QStyle, qApp from PyQt5.QtWidgets import QStyle, qApp
from PyQt5.QtGui import ( from PyQt5.QtGui import (
@@ -260,6 +260,7 @@ class GuiTheme:
cssData = inFile.read() cssData = inFile.read()
except Exception as e: except Exception as e:
logger.error("Could not load theme css file") logger.error("Could not load theme css file")
logger.error(str(e))
return False return False
# Config File # Config File
@@ -269,6 +270,7 @@ class GuiTheme:
confParser.read_file(inFile) confParser.read_file(inFile)
except Exception as e: except Exception as e:
logger.error("Could not load theme settings from: %s" % self.confFile) logger.error("Could not load theme settings from: %s" % self.confFile)
logger.error(str(e))
return False return False
## Main ## Main
@@ -324,6 +326,7 @@ class GuiTheme:
confParser.read_file(inFile) confParser.read_file(inFile)
except Exception as e: except Exception as e:
logger.error("Could not load syntax colours from: %s" % self.syntaxFile) logger.error("Could not load syntax colours from: %s" % self.syntaxFile)
logger.error(str(e))
return False return False
## Main ## Main
@@ -615,6 +618,7 @@ class GuiIcons:
confParser.read_file(inFile) confParser.read_file(inFile)
except Exception as e: except Exception as e:
logger.error("Could not load icon theme settings from: %s" % self.confFile) logger.error("Could not load icon theme settings from: %s" % self.confFile)
logger.error(str(e))
return False return False
## Main ## Main
+2 -3
View File
@@ -269,7 +269,7 @@ class GuiMain(QMainWindow):
""" """
if self.hasProject: if self.hasProject:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.warning( msgBox.warning(
self, "New Project", self, "New Project",
"Please close the current project before making a new one." "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: if path.isfile(path.join(projPath, self.theProject.projFile)) and not forceNew:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.critical( msgBox.critical(
self, "New Project", self, "New Project",
"A project already exists in that location. Please choose another folder." "A project already exists in that location. Please choose another folder."
) )
@@ -713,7 +713,6 @@ class GuiMain(QMainWindow):
self.treeView.saveTreeOrder() self.treeView.saveTreeOrder()
self.theIndex.clearIndex() self.theIndex.clearIndex()
nItems = len(self.theProject.projTree)
theDoc = NWDoc(self.theProject, self) theDoc = NWDoc(self.theProject, self)
for nDone, tItem in enumerate(self.theProject.projTree): for nDone, tItem in enumerate(self.theProject.projTree):