Building a simple index now works
This commit is contained in:
+2
-2
@@ -88,7 +88,7 @@ class GuiMainStatus(QStatusBar):
|
|||||||
self.setRefTime(None)
|
self.setRefTime(None)
|
||||||
self.setStats(0,0)
|
self.setStats(0,0)
|
||||||
self.setCounts(0,0,0)
|
self.setCounts(0,0,0)
|
||||||
self.setDocHandleCount(None)
|
self.setDocHandle(None)
|
||||||
self.setProjectStatus(None)
|
self.setProjectStatus(None)
|
||||||
self.setDocumentStatus(None)
|
self.setDocumentStatus(None)
|
||||||
self._updateTime()
|
self._updateTime()
|
||||||
@@ -132,7 +132,7 @@ class GuiMainStatus(QStatusBar):
|
|||||||
self.boxCounts.setText("<b>Document:</b> {:d} : {:d} : {:d}".format(cC,wC,pC))
|
self.boxCounts.setText("<b>Document:</b> {:d} : {:d} : {:d}".format(cC,wC,pC))
|
||||||
return
|
return
|
||||||
|
|
||||||
def setDocHandleCount(self, theHandle):
|
def setDocHandle(self, theHandle):
|
||||||
if theHandle is None:
|
if theHandle is None:
|
||||||
self.boxDocHandle.setText("0000000000000")
|
self.boxDocHandle.setText("0000000000000")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -283,6 +283,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.docEditor.changeWidth()
|
self.docEditor.changeWidth()
|
||||||
self.docEditor.setFocus()
|
self.docEditor.setFocus()
|
||||||
self.theProject.setLastEdited(tHandle)
|
self.theProject.setLastEdited(tHandle)
|
||||||
|
self.theProject.theIndex.scanFile(tHandle)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def saveDocument(self):
|
def saveDocument(self):
|
||||||
|
|||||||
@@ -13,8 +13,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import nw
|
import nw
|
||||||
|
|
||||||
from time import time
|
|
||||||
|
|
||||||
from PyQt5.QtCore import QThread
|
from PyQt5.QtCore import QThread
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|||||||
@@ -41,11 +41,10 @@ class NWDoc():
|
|||||||
self.docHandle = None
|
self.docHandle = None
|
||||||
return
|
return
|
||||||
|
|
||||||
def openDocument(self, tHandle):
|
def openDocument(self, tHandle, showStatus=True):
|
||||||
|
|
||||||
self.docHandle = tHandle
|
self.docHandle = tHandle
|
||||||
self.theItem = self.theProject.getItem(tHandle)
|
self.theItem = self.theProject.getItem(tHandle)
|
||||||
self.theParent.statusBar.setDocHandleCount(tHandle)
|
|
||||||
|
|
||||||
docDir, docFile = self._assemblePath(self.FILE_MN)
|
docDir, docFile = self._assemblePath(self.FILE_MN)
|
||||||
logger.debug("Opening document %s" % path.join(docDir,docFile))
|
logger.debug("Opening document %s" % path.join(docDir,docFile))
|
||||||
@@ -63,7 +62,9 @@ class NWDoc():
|
|||||||
logger.debug("The requested document does not exist.")
|
logger.debug("The requested document does not exist.")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
self.theParent.statusBar.setStatus("Opened Document: %s" % self.theItem.itemName)
|
if showStatus:
|
||||||
|
self.theParent.statusBar.setStatus("Opened Document: %s" % self.theItem.itemName)
|
||||||
|
self.theParent.statusBar.setDocHandle(tHandle)
|
||||||
|
|
||||||
return theDoc
|
return theDoc
|
||||||
|
|
||||||
|
|||||||
+74
-3
@@ -13,16 +13,87 @@
|
|||||||
import logging
|
import logging
|
||||||
import nw
|
import nw
|
||||||
|
|
||||||
|
from nw.project.document import NWDoc
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class NWIndex():
|
class NWIndex():
|
||||||
|
|
||||||
def __init__(self, theParent):
|
VALID_KEYS = ["todo","tag","pov","char","plot","time","location"]
|
||||||
|
|
||||||
|
def __init__(self, theProject, theParent):
|
||||||
|
|
||||||
# Internal
|
# Internal
|
||||||
self.theParent = theParent
|
self.theProject = theProject
|
||||||
self.mainConf = self.theParent.mainConf
|
self.theParent = theParent
|
||||||
|
self.mainConf = self.theParent.mainConf
|
||||||
|
|
||||||
|
# Indices
|
||||||
|
self.itemIndex = {}
|
||||||
|
self.keyIndex = {}
|
||||||
|
for aKey in self.VALID_KEYS:
|
||||||
|
self.keyIndex[aKey] = []
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def scanFile(self, tHandle):
|
||||||
|
|
||||||
|
theDocument = NWDoc(self.theProject, self.theParent)
|
||||||
|
theText = theDocument.openDocument(tHandle, False)
|
||||||
|
|
||||||
|
self.itemIndex[tHandle] = {}
|
||||||
|
for aKey in self.VALID_KEYS:
|
||||||
|
self.itemIndex[tHandle][aKey] = []
|
||||||
|
|
||||||
|
nLine = 0
|
||||||
|
for aLine in theText.splitlines():
|
||||||
|
aLine = aLine.strip()
|
||||||
|
nLine += 1
|
||||||
|
nChar = len(aLine)
|
||||||
|
if nChar > 0 and aLine[0] == "@":
|
||||||
|
self.indexThis(tHandle, aLine, nLine)
|
||||||
|
|
||||||
|
for aKey in self.VALID_KEYS:
|
||||||
|
if len(self.itemIndex[tHandle][aKey]) > 0:
|
||||||
|
if tHandle not in self.keyIndex[aKey]:
|
||||||
|
self.keyIndex[aKey].append(tHandle)
|
||||||
|
else:
|
||||||
|
if tHandle in self.keyIndex[aKey]:
|
||||||
|
self.keyIndex[aKey].remove(tHandle)
|
||||||
|
|
||||||
|
print(self.itemIndex)
|
||||||
|
print(self.keyIndex)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def indexThis(self, tHandle, aLine, nLine):
|
||||||
|
|
||||||
|
nChar = len(aLine)
|
||||||
|
nPos = aLine.find(":")
|
||||||
|
if nPos < 2 or nChar < nPos+2:
|
||||||
|
return False
|
||||||
|
|
||||||
|
aKey = aLine[1:nPos].strip().lower()
|
||||||
|
tVal = aLine[nPos+1:].strip()
|
||||||
|
if aKey not in self.VALID_KEYS:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if aKey == "todo":
|
||||||
|
self.itemIndex[tHandle]["todo"].append((nLine, tVal))
|
||||||
|
elif aKey == "tag":
|
||||||
|
if tVal.find(",") >- 0:
|
||||||
|
return False
|
||||||
|
self.itemIndex[tHandle]["tag"].append((nLine, tVal))
|
||||||
|
else:
|
||||||
|
kVal = tVal.split(",")
|
||||||
|
cVal = []
|
||||||
|
for aVal in kVal:
|
||||||
|
cVal.append(aVal.strip().lower())
|
||||||
|
if len(cVal) > 0:
|
||||||
|
self.itemIndex[tHandle][aKey].append((nLine, cVal))
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
# END Class NWIndex
|
# END Class NWIndex
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ from time import time
|
|||||||
|
|
||||||
from nw.project.item import NWItem
|
from nw.project.item import NWItem
|
||||||
from nw.project.status import NWStatus
|
from nw.project.status import NWStatus
|
||||||
|
from nw.project.index import NWIndex
|
||||||
from nw.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert
|
from nw.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert
|
||||||
from nw.common import checkString, checkBool, checkInt
|
from nw.common import checkString, checkBool, checkInt
|
||||||
from nw.constants import nwFiles
|
from nw.constants import nwFiles
|
||||||
@@ -64,6 +65,9 @@ class NWProject():
|
|||||||
self.lastWCount = 0
|
self.lastWCount = 0
|
||||||
self.currWCount = 0
|
self.currWCount = 0
|
||||||
|
|
||||||
|
# Index
|
||||||
|
self.theIndex = None
|
||||||
|
|
||||||
# Set Defaults
|
# Set Defaults
|
||||||
self.clearProject()
|
self.clearProject()
|
||||||
|
|
||||||
@@ -165,6 +169,7 @@ class NWProject():
|
|||||||
self.lastViewed = None
|
self.lastViewed = None
|
||||||
self.lastWCount = 0
|
self.lastWCount = 0
|
||||||
self.currWCount = 0
|
self.currWCount = 0
|
||||||
|
self.theIndex = NWIndex(self, self.theParent)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user