Make sure all code lines are within a 100 characters

This commit is contained in:
Veronica K. B. Olsen
2019-11-03 15:36:34 +01:00
parent f6bc1f32e5
commit 33e3b67ba5
17 changed files with 263 additions and 115 deletions
+102 -34
View File
@@ -200,65 +200,133 @@ class Config:
logger.debug("Loading config file") logger.debug("Loading config file")
cnfParse = configparser.ConfigParser() cnfParse = configparser.ConfigParser()
try: try:
cnfParse.read_file(open(path.join(self.confPath,self.confFile),mode="r",encoding="utf8")) cnfParse.read_file(
open(path.join(self.confPath,self.confFile),mode="r",encoding="utf8")
)
except Exception as e: except Exception as e:
logger.error("Could not load config file") logger.error("Could not load config file")
return False return False
## Main ## Main
cnfSec = "Main" cnfSec = "Main"
self.guiTheme = self._parseLine(cnfParse, cnfSec, "theme", self.CNF_STR, self.guiTheme) self.guiTheme = self._parseLine(
self.guiSyntax = self._parseLine(cnfParse, cnfSec, "syntax", self.CNF_STR, self.guiSyntax) cnfParse, cnfSec, "theme", self.CNF_STR, self.guiTheme
)
self.guiSyntax = self._parseLine(
cnfParse, cnfSec, "syntax", self.CNF_STR, self.guiSyntax
)
## Sizes ## Sizes
cnfSec = "Sizes" cnfSec = "Sizes"
self.winGeometry = self._parseLine(cnfParse, cnfSec, "geometry", self.CNF_LIST, self.winGeometry) self.winGeometry = self._parseLine(
self.treeColWidth = self._parseLine(cnfParse, cnfSec, "treecols", self.CNF_LIST, self.treeColWidth) cnfParse, cnfSec, "geometry", self.CNF_LIST, self.winGeometry
self.mainPanePos = self._parseLine(cnfParse, cnfSec, "mainpane", self.CNF_LIST, self.mainPanePos) )
self.docPanePos = self._parseLine(cnfParse, cnfSec, "docpane", self.CNF_LIST, self.docPanePos) self.treeColWidth = self._parseLine(
cnfParse, cnfSec, "treecols", self.CNF_LIST, self.treeColWidth
)
self.mainPanePos = self._parseLine(
cnfParse, cnfSec, "mainpane", self.CNF_LIST, self.mainPanePos
)
self.docPanePos = self._parseLine(
cnfParse, cnfSec, "docpane", self.CNF_LIST, self.docPanePos
)
## Project ## Project
cnfSec = "Project" cnfSec = "Project"
self.autoSaveProj = self._parseLine(cnfParse, cnfSec, "autosaveproject", self.CNF_INT, self.autoSaveProj) self.autoSaveProj = self._parseLine(
self.autoSaveDoc = self._parseLine(cnfParse, cnfSec, "autosavedoc", self.CNF_INT, self.autoSaveDoc) cnfParse, cnfSec, "autosaveproject", self.CNF_INT, self.autoSaveProj
)
self.autoSaveDoc = self._parseLine(
cnfParse, cnfSec, "autosavedoc", self.CNF_INT, self.autoSaveDoc
)
## Editor ## Editor
cnfSec = "Editor" cnfSec = "Editor"
self.textFont = self._parseLine(cnfParse, cnfSec, "textfont", self.CNF_STR, self.textFont) self.textFont = self._parseLine(
self.textSize = self._parseLine(cnfParse, cnfSec, "textsize", self.CNF_INT, self.textSize) cnfParse, cnfSec, "textfont", self.CNF_STR, self.textFont
self.textFixedW = self._parseLine(cnfParse, cnfSec, "fixedwidth", self.CNF_BOOL, self.textFixedW) )
self.textWidth = self._parseLine(cnfParse, cnfSec, "width", self.CNF_INT, self.textWidth) self.textSize = self._parseLine(
self.textMargin = self._parseLine(cnfParse, cnfSec, "margin", self.CNF_INT, self.textMargin) cnfParse, cnfSec, "textsize", self.CNF_INT, self.textSize
self.tabWidth = self._parseLine(cnfParse, cnfSec, "tabwidth", self.CNF_INT, self.tabWidth) )
self.doJustify = self._parseLine(cnfParse, cnfSec, "justify", self.CNF_BOOL, self.doJustify) self.textFixedW = self._parseLine(
self.autoSelect = self._parseLine(cnfParse, cnfSec, "autoselect", self.CNF_BOOL, self.autoSelect) cnfParse, cnfSec, "fixedwidth", self.CNF_BOOL, self.textFixedW
self.doReplace = self._parseLine(cnfParse, cnfSec, "autoreplace", self.CNF_BOOL, self.doReplace) )
self.doReplaceSQuote = self._parseLine(cnfParse, cnfSec, "repsquotes", self.CNF_BOOL, self.doReplaceSQuote) self.textWidth = self._parseLine(
self.doReplaceDQuote = self._parseLine(cnfParse, cnfSec, "repdquotes", self.CNF_BOOL, self.doReplaceDQuote) cnfParse, cnfSec, "width", self.CNF_INT, self.textWidth
self.doReplaceDash = self._parseLine(cnfParse, cnfSec, "repdash", self.CNF_BOOL, self.doReplaceDash) )
self.doReplaceDots = self._parseLine(cnfParse, cnfSec, "repdots", self.CNF_BOOL, self.doReplaceDots) self.textMargin = self._parseLine(
self.fmtSingleQuotes = self._parseLine(cnfParse, cnfSec, "fmtsinglequote", self.CNF_LIST, self.fmtSingleQuotes) cnfParse, cnfSec, "margin", self.CNF_INT, self.textMargin
self.fmtDoubleQuotes = self._parseLine(cnfParse, cnfSec, "fmtdoublequote", self.CNF_LIST, self.fmtDoubleQuotes) )
self.spellLanguage = self._parseLine(cnfParse, cnfSec, "spellcheck", self.CNF_STR, self.spellLanguage) self.tabWidth = self._parseLine(
self.showTabsNSpaces = self._parseLine(cnfParse, cnfSec, "showtabsnspaces", self.CNF_BOOL, self.showTabsNSpaces) cnfParse, cnfSec, "tabwidth", self.CNF_INT, self.tabWidth
self.showLineEndings = self._parseLine(cnfParse, cnfSec, "showlineendings", self.CNF_BOOL, self.showLineEndings) )
self.doJustify = self._parseLine(
cnfParse, cnfSec, "justify", self.CNF_BOOL, self.doJustify
)
self.autoSelect = self._parseLine(
cnfParse, cnfSec, "autoselect", self.CNF_BOOL, self.autoSelect
)
self.doReplace = self._parseLine(
cnfParse, cnfSec, "autoreplace", self.CNF_BOOL, self.doReplace
)
self.doReplaceSQuote = self._parseLine(
cnfParse, cnfSec, "repsquotes", self.CNF_BOOL, self.doReplaceSQuote
)
self.doReplaceDQuote = self._parseLine(
cnfParse, cnfSec, "repdquotes", self.CNF_BOOL, self.doReplaceDQuote
)
self.doReplaceDash = self._parseLine(
cnfParse, cnfSec, "repdash", self.CNF_BOOL, self.doReplaceDash
)
self.doReplaceDots = self._parseLine(
cnfParse, cnfSec, "repdots", self.CNF_BOOL, self.doReplaceDots
)
self.fmtSingleQuotes = self._parseLine(
cnfParse, cnfSec, "fmtsinglequote", self.CNF_LIST, self.fmtSingleQuotes
)
self.fmtDoubleQuotes = self._parseLine(
cnfParse, cnfSec, "fmtdoublequote", self.CNF_LIST, self.fmtDoubleQuotes
)
self.spellLanguage = self._parseLine(
cnfParse, cnfSec, "spellcheck", self.CNF_STR, self.spellLanguage
)
self.showTabsNSpaces = self._parseLine(
cnfParse, cnfSec, "showtabsnspaces", self.CNF_BOOL, self.showTabsNSpaces
)
self.showLineEndings = self._parseLine(
cnfParse, cnfSec, "showlineendings", self.CNF_BOOL, self.showLineEndings
)
## Backup ## Backup
cnfSec = "Backup" cnfSec = "Backup"
self.backupPath = self._parseLine(cnfParse, cnfSec, "backuppath", self.CNF_STR, self.backupPath) self.backupPath = self._parseLine(
self.backupOnClose = self._parseLine(cnfParse, cnfSec, "backuponclose", self.CNF_BOOL, self.backupOnClose) cnfParse, cnfSec, "backuppath", self.CNF_STR, self.backupPath
self.askBeforeBackup = self._parseLine(cnfParse, cnfSec, "askbeforebackup", self.CNF_BOOL, self.askBeforeBackup) )
self.backupOnClose = self._parseLine(
cnfParse, cnfSec, "backuponclose", self.CNF_BOOL, self.backupOnClose
)
self.askBeforeBackup = self._parseLine(
cnfParse, cnfSec, "askbeforebackup", self.CNF_BOOL, self.askBeforeBackup
)
## State ## State
cnfSec = "State" cnfSec = "State"
self.showRefPanel = self._parseLine(cnfParse, cnfSec, "showrefpanel", self.CNF_BOOL, self.showRefPanel) self.showRefPanel = self._parseLine(
self.viewComments = self._parseLine(cnfParse, cnfSec, "viewcomments", self.CNF_BOOL, self.viewComments) cnfParse, cnfSec, "showrefpanel", self.CNF_BOOL, self.showRefPanel
)
self.viewComments = self._parseLine(
cnfParse, cnfSec, "viewcomments", self.CNF_BOOL, self.viewComments
)
## Path ## Path
cnfSec = "Path" cnfSec = "Path"
self.lastPath = self._parseLine(cnfParse, cnfSec, "lastpath", self.CNF_STR, self.lastPath) self.lastPath = self._parseLine(
cnfParse, cnfSec, "lastpath", self.CNF_STR, self.lastPath
)
for i in range(10): for i in range(10):
self.recentList[i] = self._parseLine(cnfParse, cnfSec, "recent%d" % i,self.CNF_STR, self.recentList[i]) self.recentList[i] = self._parseLine(
cnfParse, cnfSec, "recent%d" % i,self.CNF_STR, self.recentList[i]
)
# Check Certain Values for None # Check Certain Values for None
self.spellLanguage = self._checkNone(self.spellLanguage) self.spellLanguage = self._checkNone(self.spellLanguage)
+3 -1
View File
@@ -71,7 +71,9 @@ class ToMarkdown(Tokenizer):
# The text can now be word wrapped, if we have requested this and it's needed. # The text can now be word wrapped, if we have requested this and it's needed.
if self.wordWrap > 0 and tLen > self.wordWrap: if self.wordWrap > 0 and tLen > self.wordWrap:
if tType == self.T_COMMENT: if tType == self.T_COMMENT:
tText = textwrap.fill(tText.strip(),initial_indent=" ",subsequent_indent=" ") tText = textwrap.fill(
tText.strip(),initial_indent=" ",subsequent_indent=" "
)
else: else:
tText = tWrap.fill(tText) tText = tWrap.fill(tText)
+2 -1
View File
@@ -203,7 +203,8 @@ class Tokenizer():
xLen = rxMatch.capturedLength(n) xLen = rxMatch.capturedLength(n)
fmtPos.append([xPos,xLen,theKeys[n]]) fmtPos.append([xPos,xLen,theKeys[n]])
# Save the line as is, but append the array of formatting locations sorted by position # Save the line as is, but append the array of formatting locations
# sorted by position
fmtPos = sorted(fmtPos,key=itemgetter(0)) fmtPos = sorted(fmtPos,key=itemgetter(0))
self.theTokens.append((self.T_TEXT,aLine,fmtPos,self.A_LEFT)) self.theTokens.append((self.T_TEXT,aLine,fmtPos,self.A_LEFT))
+3 -1
View File
@@ -407,7 +407,9 @@ class GuiConfigEditEditor(QWidget):
self.autoReplaceDQ.setCheckState(Qt.Unchecked) self.autoReplaceDQ.setCheckState(Qt.Unchecked)
self.autoReplaceDash = QCheckBox(self) self.autoReplaceDash = QCheckBox(self)
self.autoReplaceDash.setToolTip("Auto-replace double and triple hyphens with short and long dash.") self.autoReplaceDash.setToolTip(
"Auto-replace double and triple hyphens with short and long dash."
)
if self.mainConf.doReplaceDash: if self.mainConf.doReplaceDash:
self.autoReplaceDash.setCheckState(Qt.Checked) self.autoReplaceDash.setCheckState(Qt.Checked)
else: else:
+3 -1
View File
@@ -510,7 +510,9 @@ class GuiExportMain(QWidget):
self.fixedWidth.setMaximum(999) self.fixedWidth.setMaximum(999)
self.fixedWidth.setSingleStep(1) self.fixedWidth.setSingleStep(1)
self.fixedWidth.setValue(self.optState.getSetting("fixWidth")) self.fixedWidth.setValue(self.optState.getSetting("fixWidth"))
self.fixedWidth.setToolTip("Applies to .txt and .md files. A value of '0' disables the feature.") self.fixedWidth.setToolTip(
"Applies to .txt and .md files. A value of '0' disables the feature."
)
self.addSettingsForm.addWidget(QLabel("Fixed width"), 0, 0) self.addSettingsForm.addWidget(QLabel("Fixed width"), 0, 0)
self.addSettingsForm.addWidget(self.fixedWidth, 0, 1) self.addSettingsForm.addWidget(self.fixedWidth, 0, 1)
+8 -6
View File
@@ -13,14 +13,16 @@
import logging import logging
import nw import nw
from os import path from os import path
from PyQt5.QtCore import Qt, QSize from PyQt5.QtCore import Qt, QSize
from PyQt5.QtWidgets import QDialog, QHBoxLayout, QVBoxLayout, QGroupBox, QFormLayout, QLineEdit, QPushButton, QComboBox
from PyQt5.QtSvg import QSvgWidget from PyQt5.QtSvg import QSvgWidget
from PyQt5.QtWidgets import (
QDialog, QHBoxLayout, QVBoxLayout, QGroupBox, QFormLayout, QLineEdit, QPushButton, QComboBox
)
from nw.enum import nwItemLayout, nwItemClass, nwItemType from nw.enum import nwItemLayout, nwItemClass, nwItemType
from nw.constants import nwLabels from nw.constants import nwLabels
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -36,8 +38,8 @@ class GuiItemEditor(QDialog):
self.theParent = theParent self.theParent = theParent
self.theItem = self.theProject.getItem(tHandle) self.theItem = self.theProject.getItem(tHandle)
self.outerBox = QHBoxLayout() self.outerBox = QHBoxLayout()
self.innerBox = QVBoxLayout() self.innerBox = QVBoxLayout()
self.setWindowTitle("Item Settings") self.setWindowTitle("Item Settings")
+3 -1
View File
@@ -221,7 +221,9 @@ class GuiProjectEditStatus(QWidget):
def _selectColour(self): def _selectColour(self):
logger.verbose("Item colour button clicked") logger.verbose("Item colour button clicked")
if self.selColour is not None: if self.selColour is not None:
newCol = QColorDialog.getColor(self.selColour, self, "Select Colour", QColorDialog.DontUseNativeDialog) newCol = QColorDialog.getColor(
self.selColour, self, "Select Colour", QColorDialog.DontUseNativeDialog
)
if newCol: if newCol:
self.selColour = newCol self.selColour = newCol
colPixmap = QPixmap(16,16) colPixmap = QPixmap(16,16)
+6 -2
View File
@@ -70,8 +70,12 @@ class GuiSessionLogView(QDialog):
self.monoFont = QFont("Monospace",10) self.monoFont = QFont("Monospace",10)
sortValid = (Qt.AscendingOrder, Qt.DescendingOrder) sortValid = (Qt.AscendingOrder, Qt.DescendingOrder)
sortCol = self.optState.validIntRange(self.optState.getSetting("sortCol"), 0, 2, 0) sortCol = self.optState.validIntRange(
sortOrder = self.optState.validIntTuple(self.optState.getSetting("sortOrder"), sortValid, Qt.DescendingOrder) self.optState.getSetting("sortCol"), 0, 2, 0
)
sortOrder = self.optState.validIntTuple(
self.optState.getSetting("sortOrder"), sortValid, Qt.DescendingOrder
)
self.listBox.sortByColumn(sortCol, sortOrder) self.listBox.sortByColumn(sortCol, sortOrder)
self.listBox.setSortingEnabled(True) self.listBox.setSortingEnabled(True)
+15 -10
View File
@@ -13,7 +13,8 @@
import logging import logging
import nw import nw
from os import path from os import path
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QColor, QPixmap from PyQt5.QtGui import QIcon, QColor, QPixmap
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
@@ -41,21 +42,25 @@ class GuiTimeLineView(QDialog):
self.optState = TimeLineLastState(self.theProject,nwFiles.TLINE_OPT) self.optState = TimeLineLastState(self.theProject,nwFiles.TLINE_OPT)
self.optState.loadSettings() self.optState.loadSettings()
self.theMatrix = {} self.theMatrix = {}
self.numRows = 0 self.numRows = 0
self.numCols = 0 self.numCols = 0
self.outerBox = QVBoxLayout() self.outerBox = QVBoxLayout()
self.filterBox = QVBoxLayout() self.filterBox = QVBoxLayout()
self.centreBox = QHBoxLayout() self.centreBox = QHBoxLayout()
self.bottomBox = QHBoxLayout() self.bottomBox = QHBoxLayout()
self.setWindowTitle("Timeline View") self.setWindowTitle("Timeline View")
self.setMinimumWidth(700) self.setMinimumWidth(700)
self.setMinimumHeight(400) self.setMinimumHeight(400)
winWidth = self.optState.validIntRange(self.optState.getSetting("winWidth"), 700, 10000, 700) winWidth = self.optState.validIntRange(
winHeight = self.optState.validIntRange(self.optState.getSetting("winHeight"), 400, 10000, 400) self.optState.getSetting("winWidth"), 700, 10000, 700
)
winHeight = self.optState.validIntRange(
self.optState.getSetting("winHeight"), 400, 10000, 400
)
self.resize(winWidth,winHeight) self.resize(winWidth,winHeight)
# TimeLine Table # TimeLine Table
+21 -4
View File
@@ -82,9 +82,24 @@ class GuiDocEditor(QTextEdit):
self.setAcceptRichText(False) self.setAcceptRichText(False)
# Custom Shortcuts # Custom Shortcuts
QShortcut(QKeySequence("Ctrl+."), self, context=Qt.WidgetShortcut, activated=self._openSpellContext) QShortcut(
QShortcut(Qt.Key_Return | Qt.ControlModifier, self, context=Qt.WidgetShortcut, activated=self._followTag) QKeySequence("Ctrl+."),
QShortcut(Qt.Key_Enter | Qt.ControlModifier, self, context=Qt.WidgetShortcut, activated=self._followTag) self,
context = Qt.WidgetShortcut,
activated = self._openSpellContext
)
QShortcut(
Qt.Key_Return | Qt.ControlModifier,
self,
context = Qt.WidgetShortcut,
activated = self._followTag
)
QShortcut(
Qt.Key_Enter | Qt.ControlModifier,
self,
context = Qt.WidgetShortcut,
activated = self._followTag
)
# Set Up Word Count Thread and Timer # Set Up Word Count Thread and Timer
self.wcInterval = self.mainConf.wordCountTimer self.wcInterval = self.mainConf.wordCountTimer
@@ -459,7 +474,9 @@ class GuiDocEditor(QTextEdit):
if len(theSuggest) > 0: if len(theSuggest) > 0:
for aWord in theSuggest: for aWord in theSuggest:
mnuWord = QAction(aWord, mnuSuggest) mnuWord = QAction(aWord, mnuSuggest)
mnuWord.triggered.connect(lambda thePos, aWord=aWord : self._correctWord(theCursor, aWord)) mnuWord.triggered.connect(
lambda thePos, aWord=aWord : self._correctWord(theCursor, aWord)
)
mnuSuggest.addAction(mnuWord) mnuSuggest.addAction(mnuWord)
mnuSuggest.addSeparator() mnuSuggest.addSeparator()
mnuAdd = QAction("Add Word to Dictionary", mnuSuggest) mnuAdd = QAction("Add Word to Dictionary", mnuSuggest)
+9 -5
View File
@@ -18,8 +18,8 @@ from PyQt5.QtGui import QIcon, QFont, QColor
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QAbstractItemView, QApplication from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QAbstractItemView, QApplication
from nw.project.item import NWItem from nw.project.item import NWItem
from nw.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert
from nw.constants import nwLabels from nw.constants import nwLabels
from nw.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -145,11 +145,15 @@ class GuiDocTree(QTreeWidget):
# If we again has no home, give up # If we again has no home, give up
if pHandle is None: if pHandle is None:
self.makeAlert("Did not find anywhere to add the file or folder!", nwAlert.ERROR) self.makeAlert(
"Did not find anywhere to add the file or folder!", nwAlert.ERROR
)
return False return False
if pHandle == self.theProject.trashRoot: if pHandle == self.theProject.trashRoot:
self.makeAlert("Cannot add new files or folders to the trash folder.", nwAlert.ERROR) self.makeAlert(
"Cannot add new files or folders to the trash folder.", nwAlert.ERROR
)
return False return False
# If we're still here, add the file or folder # If we're still here, add the file or folder
@@ -295,10 +299,10 @@ class GuiDocTree(QTreeWidget):
tStatus += "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout] tStatus += "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout]
iStatus = nwItem.itemStatus iStatus = nwItem.itemStatus
if tClass == nwItemClass.NOVEL: if tClass == nwItemClass.NOVEL:
iStatus = self.theProject.statusItems.checkEntry(iStatus) # Make sure it's a valid index iStatus = self.theProject.statusItems.checkEntry(iStatus) # Make sure it's valid
flagIcon = self.theParent.statusIcons[iStatus] flagIcon = self.theParent.statusIcons[iStatus]
else: else:
iStatus = self.theProject.importItems.checkEntry(iStatus) # Make sure it's a valid index iStatus = self.theProject.importItems.checkEntry(iStatus) # Make sure it's valid
flagIcon = self.theParent.importIcons[iStatus] flagIcon = self.theParent.importIcons[iStatus]
trItem.setText(self.C_NAME, tName) trItem.setText(self.C_NAME, tName)
+18 -18
View File
@@ -205,24 +205,24 @@ class GuiDocViewer(QTextBrowser):
).format( ).format(
textSize = self.mainConf.textSize, textSize = self.mainConf.textSize,
preSize = self.mainConf.textSize*0.9, 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],
hColR = self.theTheme.colHead[0], hColR = self.theTheme.colHead[0],
hColG = self.theTheme.colHead[1], hColG = self.theTheme.colHead[1],
hColB = self.theTheme.colHead[2], hColB = self.theTheme.colHead[2],
cColR = self.theTheme.colComm[0], cColR = self.theTheme.colComm[0],
cColG = self.theTheme.colComm[1], cColG = self.theTheme.colComm[1],
cColB = self.theTheme.colComm[2], cColB = self.theTheme.colComm[2],
eColR = self.theTheme.colEmph[0], eColR = self.theTheme.colEmph[0],
eColG = self.theTheme.colEmph[1], eColG = self.theTheme.colEmph[1],
eColB = self.theTheme.colEmph[2], eColB = self.theTheme.colEmph[2],
aColR = self.theTheme.colVal[0], aColR = self.theTheme.colVal[0],
aColG = self.theTheme.colVal[1], aColG = self.theTheme.colVal[1],
aColB = self.theTheme.colVal[2], aColB = self.theTheme.colVal[2],
kColR = self.theTheme.colKey[0], kColR = self.theTheme.colKey[0],
kColG = self.theTheme.colKey[1], kColG = self.theTheme.colKey[1],
kColB = self.theTheme.colKey[2], kColB = self.theTheme.colKey[2],
) )
self.qDocument.setDefaultStyleSheet(styleSheet) self.qDocument.setDefaultStyleSheet(styleSheet)
+1 -1
View File
@@ -17,7 +17,7 @@ from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, QApplication from PyQt5.QtWidgets import QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, QApplication
from nw.enum import nwDocAction from nw.enum import nwDocAction
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
+3 -1
View File
@@ -353,7 +353,9 @@ class GuiMainMenu(QMenuBar):
# Document > Show File Details # Document > Show File Details
menuItem = QAction("Show File Details", self) menuItem = QAction("Show File Details", self)
menuItem.setStatusTip("Shows a message box with the document location in the project folder") menuItem.setStatusTip(
"Shows a message box with the document location in the project folder"
)
menuItem.triggered.connect(self._showDocumentLocation) menuItem.triggered.connect(self._showDocumentLocation)
self.docuMenu.addAction(menuItem) self.docuMenu.addAction(menuItem)
+40 -16
View File
@@ -63,10 +63,18 @@ class GuiMain(QMainWindow):
self.theIndex = NWIndex(self.theProject, self) self.theIndex = NWIndex(self.theProject, self)
self.hasProject = False self.hasProject = False
logger.info("OS: %s" % (self.mainConf.osType)) logger.info("OS: %s" % (
logger.info("Qt5 Version: %s (%d)" % (self.mainConf.verQtString, self.mainConf.verQtValue)) self.mainConf.osType)
logger.info("PyQt5 Version: %s (%d)" % (self.mainConf.verPyQtString, self.mainConf.verPyQtValue)) )
logger.info("Python Version: %s (0x%x)" % (self.mainConf.verPyString, self.mainConf.verPyHexVal)) logger.info("Qt5 Version: %s (%d)" % (
self.mainConf.verQtString, self.mainConf.verQtValue)
)
logger.info("PyQt5 Version: %s (%d)" % (
self.mainConf.verPyQtString, self.mainConf.verPyQtValue)
)
logger.info("Python Version: %s (0x%x)" % (
self.mainConf.verPyString, self.mainConf.verPyHexVal)
)
self.resize(*self.mainConf.winGeometry) self.resize(*self.mainConf.winGeometry)
self._setWindowTitle() self._setWindowTitle()
@@ -157,8 +165,17 @@ class GuiMain(QMainWindow):
self.asDocTimer.timeout.connect(self._autoSaveDocument) self.asDocTimer.timeout.connect(self._autoSaveDocument)
# Keyboard Shortcuts # Keyboard Shortcuts
QShortcut(Qt.Key_Return, self.treeView, context=Qt.WidgetShortcut, activated=self._treeKeyPressReturn) QShortcut(
QShortcut(Qt.Key_Escape, self, activated=self._keyPressEscape) Qt.Key_Return,
self.treeView,
context = Qt.WidgetShortcut,
activated = self._treeKeyPressReturn
)
QShortcut(
Qt.Key_Escape,
self,
activated = self._keyPressEscape
)
# Forward Functions # Forward Functions
self.setStatus = self.statusBar.setStatus self.setStatus = self.statusBar.setStatus
@@ -271,8 +288,8 @@ class GuiMain(QMainWindow):
return saveOK return saveOK
def openProject(self, projFile=None): def openProject(self, projFile=None):
"""Open a project. """Open a project. The parameter projFile is passed from the open recent projects menu, so
projFile is passed from the open recent projects menu, so can be set. If not, we pop the dialog. can be set. If not, we pop the dialog.
""" """
if projFile is None: if projFile is None:
projFile = self.openProjectDialog() projFile = self.openProjectDialog()
@@ -415,20 +432,26 @@ class GuiMain(QMainWindow):
with open(loadFile,mode="rt",encoding="utf8") as inFile: with open(loadFile,mode="rt",encoding="utf8") as inFile:
theText = inFile.read() theText = inFile.read()
except Exception as e: except Exception as e:
self.makeAlert(["Could not read file. The file cannot be a binary file.",str(e)], nwAlert.ERROR) self.makeAlert(
["Could not read file. The file cannot be a binary file.",str(e)],
nwAlert.ERROR
)
return False return False
if self.docEditor.theHandle is None: if self.docEditor.theHandle is None:
self.makeAlert(["Please open a document to import the text file into."], nwAlert.ERROR) self.makeAlert(
["Please open a document to import the text file into."],
nwAlert.ERROR
)
return False return False
if not self.docEditor.isEmpty(): if not self.docEditor.isEmpty():
if self.mainConf.showGUI: if self.mainConf.showGUI:
msgBox = QMessageBox() msgBox = QMessageBox()
msgRes = msgBox.question( msgRes = msgBox.question(self, "Import Document",(
self, "Import Document", "Importing the file will overwrite the current content of the document. "
"Importing the file will overwrite the current content of the document. Do you want to proceed?" "Do you want to proceed?"
) ))
if msgRes != QMessageBox.Yes: if msgRes != QMessageBox.Yes:
return False return False
else: else:
@@ -733,7 +756,8 @@ class GuiMain(QMainWindow):
## ##
def resizeEvent(self, theEvent): def resizeEvent(self, theEvent):
"""Extend QMainWindow.resizeEvent to signal dependent GUI elements that its pane may have changed size. """Extend QMainWindow.resizeEvent to signal dependent GUI elements that its pane may have
changed size.
""" """
QMainWindow.resizeEvent(self,theEvent) QMainWindow.resizeEvent(self,theEvent)
self.docEditor.changeWidth() self.docEditor.changeWidth()
@@ -779,7 +803,7 @@ class GuiMain(QMainWindow):
return return
def _keyPressEscape(self): def _keyPressEscape(self):
"""When the escape key is pressed somewhere in the main window, do the following, in order """When the escape key is pressed somewhere in the main window, do the following, in order.
""" """
if self.searchBar.isVisible(): if self.searchBar.isVisible():
self.searchBar.setVisible(False) self.searchBar.setVisible(False)
+10 -3
View File
@@ -32,11 +32,15 @@ class NWBackup():
def zipIt(self): def zipIt(self):
if self.mainConf.backupPath is None: if self.mainConf.backupPath is None:
self.theParent.makeAlert("Cannot backup project because no backup path is set.",nwAlert.WARN) self.theParent.makeAlert(
"Cannot backup project because no backup path is set.",nwAlert.WARN
)
return False return False
if self.theProject.projName is None: if self.theProject.projName is None:
self.theParent.makeAlert("Cannot backup project because no project name is set.",nwAlert.WARN) self.theParent.makeAlert(
"Cannot backup project because no project name is set.",nwAlert.WARN
)
return False return False
logger.info("Backing up project") logger.info("Backing up project")
@@ -55,7 +59,10 @@ class NWBackup():
try: try:
make_archive(baseName, "zip", self.theProject.projPath, ".") make_archive(baseName, "zip", self.theProject.projPath, ".")
except Exception as e: except Exception as e:
self.theParent.makeAlert(["Could not write backup archive.",str(e)],nwAlert.ERROR) self.theParent.makeAlert(
["Could not write backup archive.",str(e)],
nwAlert.ERROR
)
return False return False
self.theParent.statusBar.setStatus("Project backup complete") self.theParent.statusBar.setStatus("Project backup complete")
+16 -10
View File
@@ -214,7 +214,10 @@ class NWProject():
logger.verbose("File version is %s" % fileVersion) logger.verbose("File version is %s" % fileVersion)
if not nwxRoot == "novelWriterXML" or not fileVersion == "1.0": if not nwxRoot == "novelWriterXML" or not fileVersion == "1.0":
self.makeAlert("Project file does not appear to be a novelWriterXML file version 1.0", nwAlert.ERROR) self.makeAlert(
"Project file does not appear to be a novelWriterXML file version 1.0",
nwAlert.ERROR
)
return False return False
for xChild in xRoot: for xChild in xRoot:
@@ -399,16 +402,16 @@ class NWProject():
self.doBackup = False self.doBackup = False
if doBackup: if doBackup:
if not path.isdir(self.mainConf.backupPath): if not path.isdir(self.mainConf.backupPath):
self.theParent.makeAlert( self.theParent.makeAlert((
"You must set a valid backup path in preferences<br>to use the automatic project backup feature.", "You must set a valid backup path in preferences to use "
nwAlert.ERROR "the automatic project backup feature."
) ), nwAlert.ERROR)
return False return False
if self.projName == "": if self.projName == "":
self.theParent.makeAlert( self.theParent.makeAlert((
"You must set a valid project name in project settings<br>to use the automatic project backup feature.", "You must set a valid project name in project settings to use "
nwAlert.ERROR "the automatic project backup feature."
) ), nwAlert.ERROR)
return False return False
self.doBackup = True self.doBackup = True
return True return True
@@ -634,7 +637,10 @@ class NWProject():
# Report status # Report status
if len(orphanFiles) > 0: if len(orphanFiles) > 0:
self.makeAlert("Found %d orphaned file(s) in project folder!" % len(orphanFiles), nwAlert.WARN) self.makeAlert(
"Found %d orphaned file(s) in project folder!" % len(orphanFiles),
nwAlert.WARN
)
else: else:
logger.debug("File check OK") logger.debug("File check OK")
return return