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:
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.")
-1
View File
@@ -26,7 +26,6 @@
"""
import logging
import nw
from datetime import datetime
+1 -2
View File
@@ -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:
-3
View File
@@ -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
+14 -15
View File
@@ -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
##
+14 -15
View File
@@ -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")
+1 -1
View File
@@ -197,7 +197,7 @@ class NWSpellEnchantDummy:
"""
def __init__(self):
return
def check(self, theWord):
return True
-1
View File
@@ -26,7 +26,6 @@
"""
import logging
import nw
from lxml import etree
-7
View File
@@ -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 = []
-1
View File
@@ -28,7 +28,6 @@
"""
import logging
import nw
logger = logging.getLogger(__name__)
-1
View File
@@ -27,7 +27,6 @@
import logging
import json
import nw
from os import path
from lxml import etree
-1
View File
@@ -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("<b>Build Time:</b> Unknown", self)
self.theTitle.setIndent(0)
-7
View File
@@ -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)
-2
View File
@@ -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
)
-1
View File
@@ -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
+1 -2
View File
@@ -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
-1
View File
@@ -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)
-1
View File
@@ -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] = (
+1 -3
View File
@@ -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)
-1
View File
@@ -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__)
+5 -1
View File
@@ -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
+2 -3
View File
@@ -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):