Added a lot of comments to functions in the source code

This commit is contained in:
Veronica K. B. Olsen
2020-05-24 16:42:28 +02:00
parent e1ce93416c
commit c865dbd59b
21 changed files with 273 additions and 82 deletions
+2 -2
View File
@@ -136,7 +136,6 @@ class NWDoc():
"""Save the document via temp file in case of save failure, and """Save the document via temp file in case of save failure, and
in any case keep a backup of the file. in any case keep a backup of the file.
""" """
if self.docHandle is None or not self.docEditable: if self.docHandle is None or not self.docEditable:
return False return False
@@ -202,7 +201,6 @@ class NWDoc():
"""Parses the document meta tag and returns the path and name as """Parses the document meta tag and returns the path and name as
a list and a string. a list and a string.
""" """
if len(self.docMeta) < 14: if len(self.docMeta) < 14:
# Not enough information # Not enough information
return "", [] return "", []
@@ -232,6 +230,8 @@ class NWDoc():
@staticmethod @staticmethod
def _assemblePath(tHandle, docExt): def _assemblePath(tHandle, docExt):
"""Assemble the file path for a given handle.
"""
if tHandle is None: if tHandle is None:
return None, None return None, None
docDir = "data_"+tHandle[0] docDir = "data_"+tHandle[0]
-1
View File
@@ -244,7 +244,6 @@ class NWIndex():
and text as separate inputs as we want to primarily scan the and text as separate inputs as we want to primarily scan the
files before we save them, unless we're rebuilding the index. files before we save them, unless we're rebuilding the index.
""" """
theItem = self.theProject.projTree[tHandle] theItem = self.theProject.projTree[tHandle]
if theItem is None: if theItem is None:
return False return False
+70 -17
View File
@@ -181,7 +181,6 @@ class NWProject():
"""Clear the data for the current project, and set them to """Clear the data for the current project, and set them to
default values. default values.
""" """
# Project Status # Project Status
self.projOpened = 0 self.projOpened = 0
self.projChanged = False self.projChanged = False
@@ -236,7 +235,6 @@ class NWProject():
parse the XML of the file and populate the project variables and parse the XML of the file and populate the project variables and
build the tree of project items. build the tree of project items.
""" """
if not path.isfile(fileName): if not path.isfile(fileName):
fileName = path.join(fileName, nwFiles.PROJ_FILE) fileName = path.join(fileName, nwFiles.PROJ_FILE)
if not path.isfile(fileName): if not path.isfile(fileName):
@@ -404,7 +402,6 @@ class NWProject():
make sure if the save fails, we're not left with a truncated make sure if the save fails, we're not left with a truncated
file. file.
""" """
if self.projPath is None: if self.projPath is None:
self.makeAlert("Project path not set, cannot save.", nwAlert.ERROR) self.makeAlert("Project path not set, cannot save.", nwAlert.ERROR)
return False return False
@@ -522,7 +519,6 @@ class NWProject():
def zipIt(self, doNotify): def zipIt(self, doNotify):
"""Create a zip file of the entire project. """Create a zip file of the entire project.
""" """
logger.info("Backing up project") logger.info("Backing up project")
self.theParent.statusBar.setStatus("Backing up project ...") self.theParent.statusBar.setStatus("Backing up project ...")
@@ -836,7 +832,6 @@ class NWProject():
def _readLockFile(self): def _readLockFile(self):
"""Reads the lock file in the project folder. """Reads the lock file in the project folder.
""" """
if self.projPath is None: if self.projPath is None:
return ["ERROR"] return ["ERROR"]
@@ -863,7 +858,6 @@ class NWProject():
def _writeLockFile(self): def _writeLockFile(self):
"""Writes a lock file to the project folder. """Writes a lock file to the project folder.
""" """
if self.projPath is None: if self.projPath is None:
return False return False
@@ -901,6 +895,8 @@ class NWProject():
return None return None
def _checkFolder(self, thePath): def _checkFolder(self, thePath):
"""Check if a folder exists, and if it doesn't, create it.
"""
if not path.isdir(thePath): if not path.isdir(thePath):
try: try:
mkdir(thePath) mkdir(thePath)
@@ -911,6 +907,8 @@ class NWProject():
return True return True
def _packProjectValue(self, xParent, theName, theValue, allowNone=True): def _packProjectValue(self, xParent, theName, theValue, allowNone=True):
"""Pack a list of values into an xml element.
"""
if not isinstance(theValue, list): if not isinstance(theValue, list):
theValue = [theValue] theValue = [theValue]
for aValue in theValue: for aValue in theValue:
@@ -927,7 +925,6 @@ class NWProject():
orphaned files so the user can either delete them, or put them orphaned files so the user can either delete them, or put them
back into the project tree. back into the project tree.
""" """
if self.projPath is None: if self.projPath is None:
return return
@@ -992,7 +989,6 @@ class NWProject():
def _appendSessionStats(self): def _appendSessionStats(self):
"""Append session statistics to the sessions log file. """Append session statistics to the sessions log file.
""" """
if self.projMeta is None: if self.projMeta is None:
return False return False
@@ -1234,9 +1230,13 @@ class NWTree():
## ##
def __len__(self): def __len__(self):
"""Return the length counter. Does not check that it is correct!
"""
return self._theLength return self._theLength
def __bool__(self): def __bool__(self):
"""Returns True if the tree has any entries.
"""
return self._theLength > 0 return self._theLength > 0
## ##
@@ -1382,7 +1382,6 @@ class NWItem():
def unpackXML(self, xItem): def unpackXML(self, xItem):
"""Sets the values from an XML entry of type 'item'. """Sets the values from an XML entry of type 'item'.
""" """
if xItem.tag != "item": if xItem.tag != "item":
logger.error("XML entry is not an NWItem") logger.error("XML entry is not an NWItem")
return False return False
@@ -1420,9 +1419,11 @@ class NWItem():
@staticmethod @staticmethod
def _subPack(xParent, name, attrib=None, text=None, none=True): def _subPack(xParent, name, attrib=None, text=None, none=True):
"""Packs the values into an xml element.
"""
if not none and (text == None or text == "None"): if not none and (text == None or text == "None"):
return None return None
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 xSub
@@ -1432,10 +1433,14 @@ class NWItem():
## ##
def setName(self, theName): def setName(self, theName):
"""Set the item name.
"""
self.itemName = theName.strip() self.itemName = theName.strip()
return return
def setHandle(self, theHandle): def setHandle(self, theHandle):
"""Set the item handle, and ensure it is valid.
"""
if isinstance(theHandle, str): if isinstance(theHandle, str):
if len(theHandle) == 13: if len(theHandle) == 13:
self.itemHandle = theHandle self.itemHandle = theHandle
@@ -1446,6 +1451,8 @@ class NWItem():
return return
def setParent(self, theParent): def setParent(self, theParent):
"""Set the parent handle, and ensure that it is valid.
"""
if theParent is None: if theParent is None:
self.parHandle = None self.parHandle = None
elif isinstance(theParent, str): elif isinstance(theParent, str):
@@ -1458,10 +1465,16 @@ class NWItem():
return return
def setOrder(self, theOrder): def setOrder(self, theOrder):
"""Set the item order, and ensure that it is valid. This value
is purely a meta value, not actually used by novelWriter.
"""
self.itemOrder = checkInt(theOrder, 0) self.itemOrder = checkInt(theOrder, 0)
return return
def setType(self, theType): def setType(self, theType):
"""Set the item type from either a proper nwItemType, or set it
from a string representing a nwItemType.
"""
if isinstance(theType, nwItemType): if isinstance(theType, nwItemType):
self.itemType = theType self.itemType = theType
elif theType in nwItemType.__members__: elif theType in nwItemType.__members__:
@@ -1472,6 +1485,9 @@ class NWItem():
return return
def setClass(self, theClass): def setClass(self, theClass):
"""Set the item class from either a proper nwItemClass, or set
it from a string representing a nwItemClass.
"""
if isinstance(theClass, nwItemClass): if isinstance(theClass, nwItemClass):
self.itemClass = theClass self.itemClass = theClass
elif theClass in nwItemClass.__members__: elif theClass in nwItemClass.__members__:
@@ -1482,6 +1498,9 @@ class NWItem():
return return
def setLayout(self, theLayout): def setLayout(self, theLayout):
"""Set the item layout from either a proper nwItemLayout, or set
it from a string representing a nwItemLayout.
"""
if isinstance(theLayout, nwItemLayout): if isinstance(theLayout, nwItemLayout):
self.itemLayout = theLayout self.itemLayout = theLayout
elif theLayout in nwItemLayout.__members__: elif theLayout in nwItemLayout.__members__:
@@ -1492,6 +1511,9 @@ class NWItem():
return return
def setStatus(self, theStatus): def setStatus(self, theStatus):
"""Set the item status by looking it up in the valid status
items of the current project.
"""
if self.itemClass == nwItemClass.NOVEL: if self.itemClass == nwItemClass.NOVEL:
self.itemStatus = self.theProject.statusItems.checkEntry(theStatus) self.itemStatus = self.theProject.statusItems.checkEntry(theStatus)
else: else:
@@ -1499,6 +1521,8 @@ class NWItem():
return return
def setExpanded(self, expState): def setExpanded(self, expState):
"""Save the expanded status of an item in the project tree.
"""
if isinstance(expState, str): if isinstance(expState, str):
self.isExpanded = expState == str(True) self.isExpanded = expState == str(True)
else: else:
@@ -1506,6 +1530,8 @@ class NWItem():
return return
def setExported(self, expState): def setExported(self, expState):
"""Save the export flag.
"""
if isinstance(expState, str): if isinstance(expState, str):
self.isExported = expState == str(True) self.isExported = expState == str(True)
else: else:
@@ -1517,19 +1543,27 @@ class NWItem():
## ##
def setCharCount(self, theCount): def setCharCount(self, theCount):
self.charCount = checkInt(theCount,0) """Set the character count, and ensure that it is an integer.
"""
self.charCount = checkInt(theCount, 0)
return return
def setWordCount(self, theCount): def setWordCount(self, theCount):
self.wordCount = checkInt(theCount,0) """Set the word count, and ensure that it is an integer.
"""
self.wordCount = checkInt(theCount, 0)
return return
def setParaCount(self, theCount): def setParaCount(self, theCount):
self.paraCount = checkInt(theCount,0) """Set the paragraph count, and ensure that it is an integer.
"""
self.paraCount = checkInt(theCount, 0)
return return
def setCursorPos(self, thePosition): def setCursorPos(self, thePosition):
self.cursorPos = checkInt(thePosition,0) """Set the cursor position, and ensure that it is an integer.
"""
self.cursorPos = checkInt(thePosition, 0)
return return
# END Class NWItem # END Class NWItem
@@ -1551,6 +1585,9 @@ class NWStatus():
return return
def addEntry(self, theLabel, theColours): def addEntry(self, theLabel, theColours):
"""Add a status entry to the status object, but ensure it isn't
a duplicate.
"""
theLabel = theLabel.strip() theLabel = theLabel.strip()
if self.lookupEntry(theLabel) is None: if self.lookupEntry(theLabel) is None:
self.theLabels.append(theLabel) self.theLabels.append(theLabel)
@@ -1561,6 +1598,9 @@ class NWStatus():
return True return True
def lookupEntry(self, theLabel): def lookupEntry(self, theLabel):
"""Look up a status entry in the object lists, and return it if
it exists.
"""
if theLabel is None: if theLabel is None:
return None return None
theLabel = theLabel.strip() theLabel = theLabel.strip()
@@ -1569,6 +1609,9 @@ class NWStatus():
return None return None
def checkEntry(self, theStatus): def checkEntry(self, theStatus):
"""Check if a status value is valid, and returns the safe
reference to be used internally.
"""
if isinstance(theStatus, str): if isinstance(theStatus, str):
theStatus = theStatus.strip() theStatus = theStatus.strip()
if self.lookupEntry(theStatus) is not None: if self.lookupEntry(theStatus) is not None:
@@ -1578,11 +1621,12 @@ class NWStatus():
return self.theLabels[theStatus] return self.theLabels[theStatus]
def setNewEntries(self, newList): def setNewEntries(self, newList):
"""Update the list of entries after they have been modified by
the GUI tool.
"""
replaceMap = {} replaceMap = {}
if newList is not None: if newList is not None:
self.theLabels = [] self.theLabels = []
self.theColours = [] self.theColours = []
self.theCounts = [] self.theCounts = []
@@ -1598,10 +1642,14 @@ class NWStatus():
return replaceMap return replaceMap
def resetCounts(self): def resetCounts(self):
"""Clear the counts of references to the status entries.
"""
self.theCounts = [0]*self.theLength self.theCounts = [0]*self.theLength
return return
def countEntry(self, theLabel): def countEntry(self, theLabel):
"""Lookup the usage count of a given entry.
"""
theIndex = self.lookupEntry(theLabel) theIndex = self.lookupEntry(theLabel)
if theIndex is not None: if theIndex is not None:
self.theCounts[theIndex] += 1 self.theCounts[theIndex] += 1
@@ -1623,7 +1671,6 @@ class NWStatus():
def unpackEntries(self, xParent): def unpackEntries(self, xParent):
"""Unpack an XML tree and set the class values. """Unpack an XML tree and set the class values.
""" """
theLabels = [] theLabels = []
theColours = [] theColours = []
@@ -1661,15 +1708,21 @@ class NWStatus():
## ##
def __getitem__(self, n): def __getitem__(self, n):
"""Return an entry by its index.
"""
if n >= 0 and n < self.theLength: if n >= 0 and n < self.theLength:
return self.theLabels[n], self.theColours[n], self.theCounts[n] return self.theLabels[n], self.theColours[n], self.theCounts[n]
return None, None, None return None, None, None
def __iter__(self): def __iter__(self):
"""Initialise the iterator.
"""
self.theIndex = 0 self.theIndex = 0
return self return self
def __next__(self): def __next__(self):
"""Return the next entry for the iterator.
"""
if self.theIndex < self.theLength: if self.theIndex < self.theLength:
theLabel, theColour, theCount = self.__getitem__(self.theIndex) theLabel, theColour, theCount = self.__getitem__(self.theIndex)
self.theIndex += 1 self.theIndex += 1
+36 -2
View File
@@ -55,15 +55,23 @@ class NWSpellCheck():
return return
def setLanguage(self, theLang, projectDict=None): def setLanguage(self, theLang, projectDict=None):
"""Dummy function.
"""
return return
def checkWord(self, theWord): def checkWord(self, theWord):
"""Dummy function.
"""
return True return True
def suggestWords(self, theWord): def suggestWords(self, theWord):
"""Dummy function.
"""
return [] return []
def addWord(self, newWord): def addWord(self, newWord):
"""Add a word to the project dictionary.
"""
if self.projectDict is not None and newWord not in self.PROJW: if self.projectDict is not None and newWord not in self.PROJW:
newWord = newWord.strip() newWord = newWord.strip()
self.PROJW.append(newWord) self.PROJW.append(newWord)
@@ -76,10 +84,14 @@ class NWSpellCheck():
return return
def listDictionaries(self): def listDictionaries(self):
"""Dummy function.
"""
return [] return []
@staticmethod @staticmethod
def expandLanguage(spTag): def expandLanguage(spTag):
"""Translate a language tag to something more suer friendly.
"""
spBits = spTag.split("_") spBits = spTag.split("_")
if spBits[0] in isoLanguage.ISO_639_1: if spBits[0] in isoLanguage.ISO_639_1:
spLang = isoLanguage.ISO_639_1[spBits[0]] spLang = isoLanguage.ISO_639_1[spBits[0]]
@@ -94,6 +106,9 @@ class NWSpellCheck():
## ##
def _readProjectDictionary(self, projectDict): def _readProjectDictionary(self, projectDict):
"""Read the content of the project dictionary, and add it to the
lookup lists.
"""
self.PROJW = [] self.PROJW = []
if projectDict is not None: if projectDict is not None:
self.projectDict = projectDict self.projectDict = projectDict
@@ -147,17 +162,25 @@ class NWSpellEnchant(NWSpellCheck):
return return
def checkWord(self, theWord): def checkWord(self, theWord):
"""Wrapper function for pyenchant.
"""
return self.theDict.check(theWord) return self.theDict.check(theWord)
def suggestWords(self, theWord): def suggestWords(self, theWord):
"""Wrapper function for pyenchant.
"""
return self.theDict.suggest(theWord) return self.theDict.suggest(theWord)
def addWord(self, newWord): def addWord(self, newWord):
"""Wrapper function for pyenchant.
"""
self.theDict.add_to_session(newWord) self.theDict.add_to_session(newWord)
NWSpellCheck.addWord(self, newWord) NWSpellCheck.addWord(self, newWord)
return return
def listDictionaries(self): def listDictionaries(self):
"""Wrapper function for pyenchant.
"""
retList = [] retList = []
try: try:
import enchant import enchant
@@ -171,6 +194,8 @@ class NWSpellEnchant(NWSpellCheck):
# END Class NWSpellEnchant # END Class NWSpellEnchant
class NWSpellEnchantDummy: class NWSpellEnchantDummy:
"""Fallback for when Enchant is selected, but not installed.
"""
def __init__(self): def __init__(self):
return return
@@ -191,6 +216,11 @@ class NWSpellEnchantDummy:
# ================================================================================================ # # ================================================================================================ #
class NWSpellSimple(NWSpellCheck): class NWSpellSimple(NWSpellCheck):
"""Internal spell check tool that uses standard Python packages with
no other external dependencies. This is the fallback spell checker
when no other is available. This method is fairly slow compared to
other implementations.
"""
WORDS = [] WORDS = []
@@ -200,7 +230,8 @@ class NWSpellSimple(NWSpellCheck):
return return
def setLanguage(self, theLang, projectDict=None): def setLanguage(self, theLang, projectDict=None):
"""Load a dictionary as a list from the app assets folder.
"""
self.WORDS = [] self.WORDS = []
dictFile = path.join(self.mainConf.dictPath,theLang+".dict") dictFile = path.join(self.mainConf.dictPath,theLang+".dict")
try: try:
@@ -259,6 +290,8 @@ class NWSpellSimple(NWSpellCheck):
return theOptions return theOptions
def addWord(self, newWord): def addWord(self, newWord):
"""Wrapper for the internal project dictionary feature.
"""
newWord = newWord.strip().lower() newWord = newWord.strip().lower()
if newWord not in self.WORDS: if newWord not in self.WORDS:
self.WORDS.append(newWord) self.WORDS.append(newWord)
@@ -266,7 +299,8 @@ class NWSpellSimple(NWSpellCheck):
return return
def listDictionaries(self): def listDictionaries(self):
"""Lists the dictionary files in the app assets folder.
"""
retList = [] retList = []
for dictFile in listdir(self.mainConf.dictPath): for dictFile in listdir(self.mainConf.dictPath):
-3
View File
@@ -39,7 +39,6 @@ def countWords(theText):
"""Count words in a piece of text, skipping special syntax and """Count words in a piece of text, skipping special syntax and
comments. comments.
""" """
charCount = 0 charCount = 0
wordCount = 0 wordCount = 0
paraCount = 0 paraCount = 0
@@ -86,7 +85,6 @@ def projectMaintenance(theProject):
"""Wrapper class for handling various tasks related to managing old """Wrapper class for handling various tasks related to managing old
projects with content from older versions of novelWriter. projects with content from older versions of novelWriter.
""" """
# Remove no longer used project cache folder # Remove no longer used project cache folder
if path.isdir(theProject.projPath): if path.isdir(theProject.projPath):
cacheDir = path.join(theProject.projPath, "cache") cacheDir = path.join(theProject.projPath, "cache")
@@ -141,7 +139,6 @@ def numberToWord(numVal, theLanguage):
def _numberToWordEN(numVal): def _numberToWordEN(numVal):
"""Convert numbers to English words. """Convert numbers to English words.
""" """
numWord = "" numWord = ""
oneWord = "" oneWord = ""
tenWord = "" tenWord = ""
+9 -1
View File
@@ -69,10 +69,14 @@ class PagedDialog(QDialog):
return return
def addTab(self, tabWidget, tabLabel): def addTab(self, tabWidget, tabLabel):
"""Forwards the adding of tabs to the QTabWidget.
"""
self._tabBox.addTab(tabWidget, tabLabel) self._tabBox.addTab(tabWidget, tabLabel)
return return
def addControls(self, buttonBar): def addControls(self, buttonBar):
"""Adds a button bar to the dialog.
"""
self._buttonBox.addWidget(buttonBar) self._buttonBox.addWidget(buttonBar)
return return
@@ -85,12 +89,16 @@ class VerticalTabBar(QTabBar):
return return
def tabSizeHint(self, theIndex): def tabSizeHint(self, theIndex):
"""Returns a transposed size hint for the rotated bar.
"""
tSize = QTabBar.tabSizeHint(self, theIndex) tSize = QTabBar.tabSizeHint(self, theIndex)
tSize.transpose() tSize.transpose()
return tSize return tSize
def paintEvent(self, theEvent): def paintEvent(self, theEvent):
"""Custom implementation of the label painter that rotates the
label 90 degrees.
"""
pObj = QStylePainter(self) pObj = QStylePainter(self)
oObj = QStyleOptionTab() oObj = QStyleOptionTab()
+4 -2
View File
@@ -69,11 +69,15 @@ class QConfigLayout(QGridLayout):
return return
def setHelpText(self, intRow, theText): def setHelpText(self, intRow, theText):
"""Set the text for the help label.
"""
if intRow in self._itemMap: if intRow in self._itemMap:
self._itemMap[intRow]["help"].setText(theText) self._itemMap[intRow]["help"].setText(theText)
return return
def setLabelText(self, intRow, theText): def setLabelText(self, intRow, theText):
"""Set the text for the main label.
"""
if intRow in self._itemMap: if intRow in self._itemMap:
self._itemMap[intRow]["label"].setText(theText) self._itemMap[intRow]["label"].setText(theText)
return return
@@ -85,7 +89,6 @@ class QConfigLayout(QGridLayout):
def addGroupLabel(self, theLabel): def addGroupLabel(self, theLabel):
"""Adds a text label to separate groups of settings. """Adds a text label to separate groups of settings.
""" """
if isinstance(theLabel, QLabel): if isinstance(theLabel, QLabel):
qLabel = theLabel qLabel = theLabel
elif isinstance(theLabel, str): elif isinstance(theLabel, str):
@@ -107,7 +110,6 @@ class QConfigLayout(QGridLayout):
def addRow(self, theLabel, theWidget, helpText=None, theUnit=None): def addRow(self, theLabel, theWidget, helpText=None, theUnit=None):
"""Add a label and a widget as a new row of the grid. """Add a label and a widget as a new row of the grid.
""" """
thisEntry = { thisEntry = {
"label" : None, "label" : None,
"help" : None, "help" : None,
-1
View File
@@ -97,7 +97,6 @@ class QSwitch(QAbstractButton):
def paintEvent(self, event): def paintEvent(self, event):
"""Drawing the switch itself. """Drawing the switch itself.
""" """
qPaint = QPainter(self) qPaint = QPainter(self)
qPaint.setRenderHint(QPainter.Antialiasing, True) qPaint.setRenderHint(QPainter.Antialiasing, True)
qPaint.setPen(Qt.NoPen) qPaint.setPen(Qt.NoPen)
+20 -19
View File
@@ -143,31 +143,33 @@ class GuiDocDetails(QFrame):
self.pCountData.setAlignment(Qt.AlignRight) self.pCountData.setAlignment(Qt.AlignRight)
# Assemble # Assemble
self.mainBox.addWidget(self.labelName, 0, 0, 1, 1) self.mainBox.addWidget(self.labelName, 0, 0, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.labelFlag, 0, 1, 1, 1) self.mainBox.addWidget(self.labelFlag, 0, 1, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.labelData, 0, 2, 1, 3) self.mainBox.addWidget(self.labelData, 0, 2, 1, 3, Qt.AlignTop)
self.mainBox.addWidget(self.statusName, 1, 0, 1, 1) self.mainBox.addWidget(self.statusName, 1, 0, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.statusFlag, 1, 1, 1, 1) self.mainBox.addWidget(self.statusFlag, 1, 1, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.statusData, 1, 2, 1, 1) self.mainBox.addWidget(self.statusData, 1, 2, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.cCountName, 1, 3, 1, 1) self.mainBox.addWidget(self.cCountName, 1, 3, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.cCountData, 1, 4, 1, 1) self.mainBox.addWidget(self.cCountData, 1, 4, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.className, 2, 0, 1, 1) self.mainBox.addWidget(self.className, 2, 0, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.classFlag, 2, 1, 1, 1) self.mainBox.addWidget(self.classFlag, 2, 1, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.classData, 2, 2, 1, 1) self.mainBox.addWidget(self.classData, 2, 2, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.wCountName, 2, 3, 1, 1) self.mainBox.addWidget(self.wCountName, 2, 3, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.wCountData, 2, 4, 1, 1) self.mainBox.addWidget(self.wCountData, 2, 4, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.layoutName, 3, 0, 1, 1) self.mainBox.addWidget(self.layoutName, 3, 0, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.layoutFlag, 3, 1, 1, 1) self.mainBox.addWidget(self.layoutFlag, 3, 1, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.layoutData, 3, 2, 1, 1) self.mainBox.addWidget(self.layoutData, 3, 2, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.pCountName, 3, 3, 1, 1) self.mainBox.addWidget(self.pCountName, 3, 3, 1, 1, Qt.AlignTop)
self.mainBox.addWidget(self.pCountData, 3, 4, 1, 1) self.mainBox.addWidget(self.pCountData, 3, 4, 1, 1, Qt.AlignTop)
self.mainBox.setColumnStretch(0,0) self.mainBox.setColumnStretch(0,0)
self.mainBox.setColumnStretch(1,0) self.mainBox.setColumnStretch(1,0)
self.mainBox.setColumnStretch(2,1) self.mainBox.setColumnStretch(2,1)
self.mainBox.setColumnStretch(3,0)
self.mainBox.setColumnStretch(4,0)
logger.debug("DocDetails initialisation complete") logger.debug("DocDetails initialisation complete")
@@ -180,7 +182,6 @@ class GuiDocDetails(QFrame):
def updateViewBox(self, tHandle): def updateViewBox(self, tHandle):
"""Populate the details box from a given handle. """Populate the details box from a given handle.
""" """
nwItem = self.theProject.projTree[tHandle] nwItem = self.theProject.projTree[tHandle]
if nwItem is None: if nwItem is None:
+28 -12
View File
@@ -141,7 +141,6 @@ class GuiDocEditor(QTextEdit):
"""Clear the current document and reset all document related """Clear the current document and reset all document related
flags and counters. flags and counters.
""" """
self.nwDocument.clearDocument() self.nwDocument.clearDocument()
self.setReadOnly(True) self.setReadOnly(True)
self.clear() self.clear()
@@ -167,7 +166,6 @@ class GuiDocEditor(QTextEdit):
settings. This function is both called when the editor is settings. This function is both called when the editor is
created, and when the user changes the main editor preferences. created, and when the user changes the main editor preferences.
""" """
# Some Constants # Some Constants
self.nonWord = "\"'" self.nonWord = "\"'"
self.nonWord += "".join(self.mainConf.fmtDoubleQuotes) self.nonWord += "".join(self.mainConf.fmtDoubleQuotes)
@@ -241,7 +239,6 @@ class GuiDocEditor(QTextEdit):
document is new (empty string), we set up the editor for editing document is new (empty string), we set up the editor for editing
the file. the file.
""" """
theDoc = self.nwDocument.openDocument(tHandle, showStatus=showStatus) theDoc = self.nwDocument.openDocument(tHandle, showStatus=showStatus)
if theDoc is None: if theDoc is None:
# There was an io error # There was an io error
@@ -319,7 +316,6 @@ class GuiDocEditor(QTextEdit):
Config.textFixedW is enabled or we're in Zen mode. Otherwise, Config.textFixedW is enabled or we're in Zen mode. Otherwise,
just ensure the margins are set correctly. just ensure the margins are set correctly.
""" """
if self.mainConf.textFixedW or self.theParent.isZenMode: if self.mainConf.textFixedW or self.theParent.isZenMode:
vBar = self.verticalScrollBar() vBar = self.verticalScrollBar()
if vBar.isVisible(): if vBar.isVisible():
@@ -376,6 +372,10 @@ class GuiDocEditor(QTextEdit):
## ##
def setDocumentChanged(self, bValue): def setDocumentChanged(self, bValue):
"""Keeps track of the document changed variable, and ensures
that the corresponding icon on the status bar shows the same
status.
"""
self.docChanged = bValue self.docChanged = bValue
self.theParent.statusBar.setDocumentStatus(self.docChanged) self.theParent.statusBar.setDocumentStatus(self.docChanged)
return self.docChanged return self.docChanged
@@ -437,7 +437,6 @@ class GuiDocEditor(QTextEdit):
If the spell check mode (theMode) is not defined (None), then If the spell check mode (theMode) is not defined (None), then
toggle the current status saved in this class. toggle the current status saved in this class.
""" """
if theMode is None: if theMode is None:
theMode = not self.spellCheck theMode = not self.spellCheck
@@ -460,7 +459,6 @@ class GuiDocEditor(QTextEdit):
currently loaded text. The fastest way to do this, at least as currently loaded text. The fastest way to do this, at least as
of Qt 5.13, is to clear the text and put it back. of Qt 5.13, is to clear the text and put it back.
""" """
logger.verbose("Running spell checker") logger.verbose("Running spell checker")
if self.spellCheck: if self.spellCheck:
bfTime = time() bfTime = time()
@@ -481,6 +479,12 @@ class GuiDocEditor(QTextEdit):
## ##
def docAction(self, theAction): def docAction(self, theAction):
"""Perform an action on the current document based on an action
flag. This is just a single entry point wrapper function to
ensure all the feature functions get the correct information
passed to it without having to consider the internal logic of
this class when calling these actions from other classes.
"""
logger.verbose("Requesting action: %s" % theAction.name) logger.verbose("Requesting action: %s" % theAction.name)
if not self.theParent.hasProject: if not self.theParent.hasProject:
logger.error("No project open") logger.error("No project open")
@@ -537,9 +541,14 @@ class GuiDocEditor(QTextEdit):
return True return True
def isEmpty(self): def isEmpty(self):
"""Wrapper function to check if the current document is empty.
"""
return self.qDocument.isEmpty() return self.qDocument.isEmpty()
def revealLocation(self): def revealLocation(self):
"""Tell the user where on the file system the file in the editor
is saved.
"""
if self.theHandle is not None: if self.theHandle is not None:
msgBox = QMessageBox() msgBox = QMessageBox()
msgBox.information(self, "File Location", ( msgBox.information(self, "File Location", (
@@ -568,7 +577,6 @@ class GuiDocEditor(QTextEdit):
However, we don't want to spend a lot of time in this function However, we don't want to spend a lot of time in this function
as it is triggered on every keypress when typing. as it is triggered on every keypress when typing.
""" """
self.hasSelection = self.textCursor().hasSelection() self.hasSelection = self.textCursor().hasSelection()
if keyEvent.modifiers() == Qt.ShiftModifier: if keyEvent.modifiers() == Qt.ShiftModifier:
@@ -628,7 +636,6 @@ class GuiDocEditor(QTextEdit):
"""Triggered by right click to open the context menu. Also """Triggered by right click to open the context menu. Also
triggered by the Ctrl+. shortcut. triggered by the Ctrl+. shortcut.
""" """
if not self.spellCheck: if not self.spellCheck:
return return
@@ -667,7 +674,11 @@ class GuiDocEditor(QTextEdit):
return return
@pyqtSlot("QTextCursor", str)
def _correctWord(self, theCursor, theWord): def _correctWord(self, theCursor, theWord):
"""Slot for the spell check context menu triggering the
replacement of a word with the word from the dictionary.
"""
xPos = theCursor.selectionStart() xPos = theCursor.selectionStart()
theCursor.beginEditBlock() theCursor.beginEditBlock()
theCursor.removeSelectedText() theCursor.removeSelectedText()
@@ -677,7 +688,11 @@ class GuiDocEditor(QTextEdit):
self.setTextCursor(theCursor) self.setTextCursor(theCursor)
return return
@pyqtSlot("QTextCursor")
def _addWord(self, theCursor): def _addWord(self, theCursor):
"""Slot for the spell check context menu triggered when the user
wants to add a word to the project dictionary.
"""
theWord = theCursor.selectedText().strip().strip(self.nonWord) theWord = theCursor.selectedText().strip().strip(self.nonWord)
logger.debug("Added '%s' to project dictionary" % theWord) logger.debug("Added '%s' to project dictionary" % theWord)
self.theDict.addWord(theWord) self.theDict.addWord(theWord)
@@ -729,7 +744,6 @@ class GuiDocEditor(QTextEdit):
tag and can tell the document viewer to try and find and load tag and can tell the document viewer to try and find and load
the file where the tag is defined. the file where the tag is defined.
""" """
if theCursor is None: if theCursor is None:
theCursor = self.textCursor() theCursor = self.textCursor()
@@ -772,13 +786,15 @@ class GuiDocEditor(QTextEdit):
return return
def _openSpellContext(self): def _openSpellContext(self):
"""Opens the spell check context menu at the current point of
the cursor.
"""
self._openContextMenu(self.cursorRect().center()) self._openContextMenu(self.cursorRect().center())
return return
def _docAutoReplace(self, theBlock): def _docAutoReplace(self, theBlock):
"""Autoreplace text elements based on main configuration. """Autoreplace text elements based on main configuration.
""" """
if not theBlock.isValid(): if not theBlock.isValid():
return return
@@ -870,7 +886,6 @@ class GuiDocEditor(QTextEdit):
def _formatBlock(self, docAction): def _formatBlock(self, docAction):
"""Changes the block format of the block under the cursor. """Changes the block format of the block under the cursor.
""" """
theCursor = self.textCursor() theCursor = self.textCursor()
theBlock = theCursor.block() theBlock = theCursor.block()
if not theBlock.isValid(): if not theBlock.isValid():
@@ -949,6 +964,8 @@ class GuiDocEditor(QTextEdit):
return return
def _makeSelection(self, selMode): def _makeSelection(self, selMode):
"""Wrapper function to select a word based on a selection mode.
"""
theCursor = self.textCursor() theCursor = self.textCursor()
theCursor.clearSelection() theCursor.clearSelection()
theCursor.select(selMode) theCursor.select(selMode)
@@ -1025,7 +1042,6 @@ class GuiDocEditor(QTextEdit):
"""Create the spell checking object based on the spellTool """Create the spell checking object based on the spellTool
setting in config. setting in config.
""" """
if self.mainConf.spellTool == "enchant": if self.mainConf.spellTool == "enchant":
from nw.core.spellcheck import NWSpellEnchant from nw.core.spellcheck import NWSpellEnchant
self.theDict = NWSpellEnchant() self.theDict = NWSpellEnchant()
-1
View File
@@ -79,7 +79,6 @@ class GuiDocTitleBar(QLabel):
"""Sets the document title from the handle, or alternatively, """Sets the document title from the handle, or alternatively,
set the whole document path. set the whole document path.
""" """
self.setText("") self.setText("")
self.theHandle = tHandle self.theHandle = tHandle
if tHandle is None: if tHandle is None:
+42 -5
View File
@@ -105,13 +105,19 @@ class GuiDocTree(QTreeWidget):
## ##
def clearTree(self): def clearTree(self):
"""Clear the GUI content and the related maps.
"""
self.clear() self.clear()
self.theMap = {} self.theMap = {}
self.orphRoot = None self.orphRoot = None
return return
def newTreeItem(self, itemType, itemClass): def newTreeItem(self, itemType, itemClass):
"""Add new item to the tree, with a given itemType and
itemClass, and attach it to the selected handle. Also make sure
the item is added in a place it can be added, and that other
meta data is set correctly to ensure a valid project tree.
"""
pHandle = self.getSelectedHandle() pHandle = self.getSelectedHandle()
if not self.theParent.hasProject: if not self.theParent.hasProject:
@@ -274,7 +280,6 @@ class GuiDocTree(QTreeWidget):
function only asks for confirmation once, and calls the regular function only asks for confirmation once, and calls the regular
deleteItem function for each document in the Trash folder. deleteItem function for each document in the Trash folder.
""" """
trashHandle = self.theProject.projTree.trashRoot() trashHandle = self.theProject.projTree.trashRoot()
logger.debug("Emptying Trash folder") logger.debug("Emptying Trash folder")
@@ -315,7 +320,6 @@ class GuiDocTree(QTreeWidget):
that to save memory. Items not in the tree are not saved to the that to save memory. Items not in the tree are not saved to the
project file, so a loaded project will be clean anyway. project file, so a loaded project will be clean anyway.
""" """
if tHandle is None: if tHandle is None:
tHandle = self.getSelectedHandle() tHandle = self.getSelectedHandle()
@@ -446,6 +450,13 @@ class GuiDocTree(QTreeWidget):
return return
def propagateCount(self, tHandle, theCount, nDepth=0): def propagateCount(self, tHandle, theCount, nDepth=0):
"""Recursive function setting the word count for a given item,
and propagating that count upwards in the tree until reaching a
root item. This function is more efficient than recalculating
everything each time the word count is updated, but is also
prone to diverging from the true values if the counts are not
properly reported to the function.
"""
tItem = self._getTreeItem(tHandle) tItem = self._getTreeItem(tHandle)
if tItem is not None: if tItem is not None:
tItem.setText(self.C_COUNT,str(theCount)) tItem.setText(self.C_COUNT,str(theCount))
@@ -460,6 +471,12 @@ class GuiDocTree(QTreeWidget):
return return
def projectWordCount(self): def projectWordCount(self):
"""Sum up the word counts for all root items and set the
relevant values in the project and on the status bar. This call
is a fast way of getting this number, and depends on the
propagateCount function being called when it should to maintain
the correct count.
"""
nWords = 0 nWords = 0
for n in range(self.topLevelItemCount()): for n in range(self.topLevelItemCount()):
tItem = self.topLevelItem(n) tItem = self.topLevelItem(n)
@@ -472,6 +489,11 @@ class GuiDocTree(QTreeWidget):
return return
def buildTree(self): def buildTree(self):
"""Build the entire project tree from scratch. This depends on
the save project item iterator in the project class which will
always make sure items with a parent have had their parent item
sent first.
"""
self.clear() self.clear()
for nwItem in self.theProject.getProjectItems(): for nwItem in self.theProject.getProjectItems():
self._addTreeItem(nwItem) self._addTreeItem(nwItem)
@@ -517,11 +539,16 @@ class GuiDocTree(QTreeWidget):
## ##
def _getTreeItem(self, tHandle): def _getTreeItem(self, tHandle):
"""Returns the QTreeWidgetItem of a given item handle.
"""
if tHandle in self.theMap.keys(): if tHandle in self.theMap.keys():
return self.theMap[tHandle] return self.theMap[tHandle]
return None return None
def _scanChildren(self, theList, theItem, theIndex): def _scanChildren(self, theList, theItem, theIndex):
"""This is a recursive function returning all items in a tree
starting at a given QTreeWidgetItem.
"""
tHandle = theItem.text(self.C_HANDLE) tHandle = theItem.text(self.C_HANDLE)
nwItem = self.theProject.projTree[tHandle] nwItem = self.theProject.projTree[tHandle]
nwItem.setExpanded(theItem.isExpanded()) nwItem.setExpanded(theItem.isExpanded())
@@ -532,7 +559,9 @@ class GuiDocTree(QTreeWidget):
return theList return theList
def _addTreeItem(self, nwItem): def _addTreeItem(self, nwItem):
"""Create a QTreeWidgetItem from an NWItem and add it to the
project tree.
"""
tHandle = nwItem.itemHandle tHandle = nwItem.itemHandle
pHandle = nwItem.parHandle pHandle = nwItem.parHandle
tClass = nwItem.itemClass tClass = nwItem.itemClass
@@ -591,6 +620,9 @@ class GuiDocTree(QTreeWidget):
return trItem return trItem
def _addOrphanedRoot(self): def _addOrphanedRoot(self):
"""Add the special Orphaned Files root item to hold non-root
items with no parent set.
"""
if self.orphRoot is None: if self.orphRoot is None:
newItem = QTreeWidgetItem([""]*4) newItem = QTreeWidgetItem([""]*4)
newItem.setText(self.C_NAME, "Orphaned Files") newItem.setText(self.C_NAME, "Orphaned Files")
@@ -604,6 +636,8 @@ class GuiDocTree(QTreeWidget):
return return
def _cleanOrphanedRoot(self): def _cleanOrphanedRoot(self):
"""Remove the special Orphaned Files root folder if it is empty.
"""
if self.orphRoot is not None: if self.orphRoot is not None:
if self.orphRoot.childCount() == 0: if self.orphRoot.childCount() == 0:
self.takeTopLevelItem(self.indexOfTopLevelItem(self.orphRoot)) self.takeTopLevelItem(self.indexOfTopLevelItem(self.orphRoot))
@@ -615,7 +649,6 @@ class GuiDocTree(QTreeWidget):
in the project is consistent with the treeView. Also move the in the project is consistent with the treeView. Also move the
word count over to the new parent tree. word count over to the new parent tree.
""" """
trItemS = self._getTreeItem(tHandle) trItemS = self._getTreeItem(tHandle)
nwItemS = self.theProject.projTree[tHandle] nwItemS = self.theProject.projTree[tHandle]
trItemP = trItemS.parent() trItemP = trItemS.parent()
@@ -636,6 +669,10 @@ class GuiDocTree(QTreeWidget):
return True return True
def _moveOrphanedItem(self, tHandle, dHandle): def _moveOrphanedItem(self, tHandle, dHandle):
"""Move an Orphaned Item to a new dHandle parent item. This
function will set all the missing meta data based on the meta
data of the destination item.
"""
trItemS = self._getTreeItem(tHandle) trItemS = self._getTreeItem(tHandle)
nwItemS = self.theProject.projTree[tHandle] nwItemS = self.theProject.projTree[tHandle]
nwItemD = self.theProject.projTree[dHandle] nwItemD = self.theProject.projTree[dHandle]
+17 -5
View File
@@ -88,7 +88,6 @@ class GuiDocViewer(QTextBrowser):
def initViewer(self): def initViewer(self):
"""Set editor settings from main config. """Set editor settings from main config.
""" """
self._makeStyleSheet() self._makeStyleSheet()
# Set Font # Set Font
@@ -122,7 +121,6 @@ class GuiDocViewer(QTextBrowser):
def loadText(self, tHandle): def loadText(self, tHandle):
"""Load text into the viewer from an item handle. """Load text into the viewer from an item handle.
""" """
tItem = self.theProject.projTree[tHandle] tItem = self.theProject.projTree[tHandle]
if tItem is None: if tItem is None:
logger.warning("Item not found") logger.warning("Item not found")
@@ -153,11 +151,16 @@ class GuiDocViewer(QTextBrowser):
return True return True
def reloadText(self): def reloadText(self):
"""Reload the text in the current document.
"""
self.loadText(self.theHandle) self.loadText(self.theHandle)
return return
def loadFromTag(self, theTag): def loadFromTag(self, theTag):
"""Load text in the document from a reference given by a meta
tag rather than a known handle. This function depends on the
index being up to date.
"""
logger.debug("Loading document from tag '%s'" % theTag) logger.debug("Loading document from tag '%s'" % theTag)
if theTag in self.theParent.theIndex.tagIndex.keys(): if theTag in self.theParent.theIndex.tagIndex.keys():
@@ -175,6 +178,9 @@ class GuiDocViewer(QTextBrowser):
return True return True
def docAction(self, theAction): def docAction(self, theAction):
"""Wrapper function for various document actions on the current
document.
"""
logger.verbose("Requesting action: %s" % theAction.name) logger.verbose("Requesting action: %s" % theAction.name)
if self.theHandle is None: if self.theHandle is None:
logger.error("No document open") logger.error("No document open")
@@ -225,6 +231,9 @@ class GuiDocViewer(QTextBrowser):
## ##
def _makeSelection(self, selMode): def _makeSelection(self, selMode):
"""Wrapper function for making a selection based on a specific
selection mode.
"""
theCursor = self.textCursor() theCursor = self.textCursor()
theCursor.clearSelection() theCursor.clearSelection()
theCursor.select(selMode) theCursor.select(selMode)
@@ -232,7 +241,8 @@ class GuiDocViewer(QTextBrowser):
return return
def _linkClicked(self, theURL): def _linkClicked(self, theURL):
"""Slot for a link in the document being clicked.
"""
theLink = theURL.url() theLink = theURL.url()
tHandle = None tHandle = None
onLine = 0 onLine = 0
@@ -256,7 +266,9 @@ class GuiDocViewer(QTextBrowser):
return return
def _makeStyleSheet(self): def _makeStyleSheet(self):
"""Generate an appropriate style sheet for the document viewer,
based on the current syntax highlighter theme,
"""
styleSheet = ( styleSheet = (
"body {{" "body {{"
" color: rgb({tColR},{tColG},{tColB});" " color: rgb({tColR},{tColG},{tColB});"
+4
View File
@@ -67,11 +67,15 @@ class GuiNoticeBar(QFrame):
return return
def showNote(self, theNote): def showNote(self, theNote):
"""Show the note on the noticebar.
"""
self.noteLabel.setText("<b>Note:</b> %s" % theNote) self.noteLabel.setText("<b>Note:</b> %s" % theNote)
self.setVisible(True) self.setVisible(True)
return return
def hideNote(self): def hideNote(self):
"""Clear the noticebar and hide it.
"""
self.noteLabel.setText("") self.noteLabel.setText("")
self.setVisible(False) self.setVisible(False)
return return
-4
View File
@@ -125,7 +125,6 @@ class GuiProjectOutline(QTreeWidget):
"""Clear the tree and header and set the default values for the """Clear the tree and header and set the default values for the
columns arrays. columns arrays.
""" """
self.clear() self.clear()
self.setColumnCount(1) self.setColumnCount(1)
self.setHeaderLabel(nwLabels.OUTLINE_COLS[nwOutline.TITLE]) self.setHeaderLabel(nwLabels.OUTLINE_COLS[nwOutline.TITLE])
@@ -150,7 +149,6 @@ class GuiProjectOutline(QTreeWidget):
what data to load, and if necessary, force a rebuild of the what data to load, and if necessary, force a rebuild of the
tree. tree.
""" """
# If it's the first time, we always build # If it's the first time, we always build
if self.firstView or self.firstView and overRide: if self.firstView or self.firstView and overRide:
self._loadHeaderState() self._loadHeaderState()
@@ -229,7 +227,6 @@ class GuiProjectOutline(QTreeWidget):
"""Load the state of the main tree header, that is, column order """Load the state of the main tree header, that is, column order
and column width. and column width.
""" """
# Load whatever we saved last time, regardless of wether it # Load whatever we saved last time, regardless of wether it
# contains the correct names or number of columns. The names # contains the correct names or number of columns. The names
# must be valid though. # must be valid though.
@@ -280,7 +277,6 @@ class GuiProjectOutline(QTreeWidget):
save the current width of hidden columns though. This preserves save the current width of hidden columns though. This preserves
the last known width in case they're unhidden again. the last known width in case they're unhidden again.
""" """
# If we haven't built the tree, there is nothing to save. # If we haven't built the tree, there is nothing to save.
if self.lastBuild == 0: if self.lastBuild == 0:
return return
+17
View File
@@ -98,6 +98,9 @@ class GuiSearchBar(QFrame):
## ##
def setSearchText(self, theText): def setSearchText(self, theText):
"""Open the search bar and set the search text to the text
provided, if any.
"""
if not self.isVisible(): if not self.isVisible():
self.setVisible(True) self.setVisible(True)
self.searchBox.setText(theText) self.searchBox.setText(theText)
@@ -106,15 +109,21 @@ class GuiSearchBar(QFrame):
return True return True
def setReplaceText(self, theText): def setReplaceText(self, theText):
"""Set the replace text.
"""
self._replaceVisible(True) self._replaceVisible(True)
self.replaceBox.setFocus() self.replaceBox.setFocus()
self.replaceBox.setText(theText) self.replaceBox.setText(theText)
return True return True
def getSearchText(self): def getSearchText(self):
"""Return the current search text.
"""
return self.searchBox.text() return self.searchBox.text()
def getReplaceText(self): def getReplaceText(self):
"""Return the current replace text.
"""
return self.replaceBox.text() return self.replaceBox.text()
## ##
@@ -122,11 +131,15 @@ class GuiSearchBar(QFrame):
## ##
def _doClose(self): def _doClose(self):
"""Hide the search/replace bar.
"""
self._replaceVisible(False) self._replaceVisible(False)
self.setVisible(False) self.setVisible(False)
return return
def _doSearch(self): def _doSearch(self):
"""Call the search action function for the document editor.
"""
modKey = qApp.keyboardModifiers() modKey = qApp.keyboardModifiers()
if modKey == Qt.ShiftModifier: if modKey == Qt.ShiftModifier:
self.theParent.docEditor.docAction(nwDocAction.GO_PREV) self.theParent.docEditor.docAction(nwDocAction.GO_PREV)
@@ -135,10 +148,14 @@ class GuiSearchBar(QFrame):
return return
def _doReplace(self): def _doReplace(self):
"""Call the replace action function for the document editor.
"""
self.theParent.docEditor.docAction(nwDocAction.REPL_NEXT) self.theParent.docEditor.docAction(nwDocAction.REPL_NEXT)
return return
def _replaceVisible(self, isVisible): def _replaceVisible(self, isVisible):
"""Set the visibility of all the replace widgets.
"""
self.replaceLabel.setVisible(isVisible) self.replaceLabel.setVisible(isVisible)
self.replaceBox.setVisible(isVisible) self.replaceBox.setVisible(isVisible)
self.replaceButton.setVisible(isVisible) self.replaceButton.setVisible(isVisible)
+10 -1
View File
@@ -94,7 +94,9 @@ class GuiDocViewDetails(QWidget):
return return
def refreshReferences(self, tHandle): def refreshReferences(self, tHandle):
"""Update the current list of document references from the
project index.
"""
self.currHandle = tHandle self.currHandle = tHandle
if self.isSticky.isChecked(): if self.isSticky.isChecked():
@@ -117,12 +119,17 @@ class GuiDocViewDetails(QWidget):
## ##
def _linkClicked(self, theLink): def _linkClicked(self, theLink):
"""Capture the link-click and forward it to the document viewer
class for handling.
"""
if len(theLink) == 18: if len(theLink) == 18:
tHandle = theLink[-13:] tHandle = theLink[-13:]
self.theParent.viewDocument(tHandle) self.theParent.viewDocument(tHandle)
return return
def _doShowHide(self, chState): def _doShowHide(self, chState):
"""Toggle the expand/collapse of the panel.
"""
self.scrollBox.setVisible(chState) self.scrollBox.setVisible(chState)
self.mainConf.setShowRefPanel(chState) self.mainConf.setShowRefPanel(chState)
if chState: if chState:
@@ -132,6 +139,8 @@ class GuiDocViewDetails(QWidget):
return return
def _doSticky(self, chState): def _doSticky(self, chState):
"""Toggle the sticky feature of the references.
"""
if not chState and self.currHandle is not None: if not chState and self.currHandle is not None:
self.refreshReferences(self.currHandle) self.refreshReferences(self.currHandle)
return return
+10 -2
View File
@@ -75,6 +75,9 @@ class GuiDocHighlighter(QSyntaxHighlighter):
return return
def initHighlighter(self): def initHighlighter(self):
"""Initialise the syntax highlighter, setting all the colour
rules and building the regexes.
"""
logger.debug("Setting up highlighting rules") logger.debug("Setting up highlighting rules")
@@ -205,14 +208,21 @@ class GuiDocHighlighter(QSyntaxHighlighter):
## ##
def setDict(self, theDict): def setDict(self, theDict):
"""Set the dictionary object for spell check underlines lookup.
"""
self.theDict = theDict self.theDict = theDict
return True return True
def setSpellCheck(self, theMode): def setSpellCheck(self, theMode):
"""Enable/disable the real time spell checker.
"""
self.spellCheck = theMode self.spellCheck = theMode
return True return True
def setHandle(self, theHandle): def setHandle(self, theHandle):
"""Set the handle of the currently highlighted document. This is
needed for the index lookup for validating tags and references.
"""
self.theHandle = theHandle self.theHandle = theHandle
return True return True
@@ -226,7 +236,6 @@ class GuiDocHighlighter(QSyntaxHighlighter):
is significantly faster than running the regex checks we use for is significantly faster than running the regex checks we use for
text paragraphs. text paragraphs.
""" """
if self.theHandle is None or not theText: if self.theHandle is None or not theText:
return return
@@ -317,7 +326,6 @@ class GuiDocHighlighter(QSyntaxHighlighter):
"""Generate a valid character format to be applied to the text """Generate a valid character format to be applied to the text
that is to be highlighted. that is to be highlighted.
""" """
theFormat = QTextCharFormat() theFormat = QTextCharFormat()
if fmtCol is not None: if fmtCol is not None:
-2
View File
@@ -51,7 +51,6 @@ class OptionState():
def loadSettings(self): def loadSettings(self):
"""Load the options dictionary from the project settings file. """Load the options dictionary from the project settings file.
""" """
if self.theProject.projMeta is None: if self.theProject.projMeta is None:
return False return False
@@ -76,7 +75,6 @@ class OptionState():
def saveSettings(self): def saveSettings(self):
"""Save the options dictionary to the project settings file. """Save the options dictionary to the project settings file.
""" """
if self.theProject.projMeta is None: if self.theProject.projMeta is None:
return False return False
+3 -1
View File
@@ -45,7 +45,9 @@ class WordCounter(QThread):
return return
def run(self): def run(self):
"""Overloaded run function for the word counter, forwarding the
call to the function that does the actual counting.
"""
theText = self.theParent.getText() theText = self.theParent.getText()
cC, wC, pC = countWords(theText) cC, wC, pC = countWords(theText)
+1 -1
View File
@@ -57,7 +57,7 @@ class GuiMain(QMainWindow):
logger.info("Starting %s" % nw.__package__) logger.info("Starting %s" % nw.__package__)
logger.debug("Initialising GUI ...") logger.debug("Initialising GUI ...")
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
# Some runtime info useful for debugging # Some runtime info useful for debugging
logger.info("OS: %s" % self.mainConf.osType) logger.info("OS: %s" % self.mainConf.osType)