Dropped the progress bar for rebuild index, and used statusbar instead
This commit is contained in:
@@ -73,6 +73,8 @@ class NWDoc():
|
|||||||
"""Open a document from handle, capturing potential file system
|
"""Open a document from handle, capturing potential file system
|
||||||
errors and parse meta data.
|
errors and parse meta data.
|
||||||
"""
|
"""
|
||||||
|
# Always clear first, since the object will often be reused.
|
||||||
|
self.clearDocument()
|
||||||
|
|
||||||
self.docHandle = tHandle
|
self.docHandle = tHandle
|
||||||
if not isOrphan:
|
if not isOrphan:
|
||||||
|
|||||||
@@ -940,7 +940,6 @@ class NWProject():
|
|||||||
oName = ""
|
oName = ""
|
||||||
if aDoc.openDocument(oHandle, showStatus=False, isOrphan=True):
|
if aDoc.openDocument(oHandle, showStatus=False, isOrphan=True):
|
||||||
oName, oPath = aDoc.getMeta()
|
oName, oPath = aDoc.getMeta()
|
||||||
aDoc.clearDocument()
|
|
||||||
|
|
||||||
if oName == "":
|
if oName == "":
|
||||||
nOrph += 1
|
nOrph += 1
|
||||||
|
|||||||
@@ -216,18 +216,23 @@ class GuiDocEditor(QTextEdit):
|
|||||||
# font changed, otherwise we just clear the editor entirely,
|
# font changed, otherwise we just clear the editor entirely,
|
||||||
# which makes it read only.
|
# which makes it read only.
|
||||||
if self.theHandle is not None:
|
if self.theHandle is not None:
|
||||||
# We must save the current handle as clearEditor() sets it
|
self.reloadText()
|
||||||
# to None
|
|
||||||
tHandle = self.theHandle
|
|
||||||
self.clearEditor()
|
|
||||||
self.loadText(tHandle)
|
|
||||||
self.updateDocMargins()
|
|
||||||
else:
|
else:
|
||||||
self.clearEditor()
|
self.clearEditor()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def loadText(self, tHandle, tLine=None):
|
def reloadText(self):
|
||||||
|
"""Reloads the document currently being edited.
|
||||||
|
"""
|
||||||
|
if self.theHandle is not None:
|
||||||
|
tHandle = self.theHandle
|
||||||
|
self.clearEditor()
|
||||||
|
self.loadText(tHandle, showStatus=False)
|
||||||
|
self.updateDocMargins()
|
||||||
|
return
|
||||||
|
|
||||||
|
def loadText(self, tHandle, tLine=None, showStatus=True):
|
||||||
"""Load text from a document into the editor. If we have an io
|
"""Load text from a document into the editor. If we have an io
|
||||||
error, we must handle this and clear the editor so that we don't
|
error, we must handle this and clear the editor so that we don't
|
||||||
risk overwriting the file if it exists. This can for instance
|
risk overwriting the file if it exists. This can for instance
|
||||||
@@ -237,7 +242,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
the file.
|
the file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
theDoc = self.nwDocument.openDocument(tHandle)
|
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
|
||||||
self.clearEditor()
|
self.clearEditor()
|
||||||
|
|||||||
+22
-3
@@ -32,7 +32,7 @@ from time import time
|
|||||||
|
|
||||||
from PyQt5.QtCore import Qt, QTimer
|
from PyQt5.QtCore import Qt, QTimer
|
||||||
from PyQt5.QtGui import QColor, QPixmap, QFont
|
from PyQt5.QtGui import QColor, QPixmap, QFont
|
||||||
from PyQt5.QtWidgets import QStatusBar, QLabel
|
from PyQt5.QtWidgets import qApp, QStatusBar, QLabel
|
||||||
|
|
||||||
from nw.core import NWSpellCheck
|
from nw.core import NWSpellCheck
|
||||||
|
|
||||||
@@ -114,23 +114,32 @@ class GuiMainStatus(QStatusBar):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def clearStatus(self):
|
def clearStatus(self):
|
||||||
|
"""Reset all widgets on the status bar to default values.
|
||||||
|
"""
|
||||||
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.setProjectStatus(None)
|
self.setProjectStatus(None)
|
||||||
self.setDocumentStatus(None)
|
self.setDocumentStatus(None)
|
||||||
self._updateTime()
|
self._updateTime()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def setRefTime(self, theTime):
|
def setRefTime(self, theTime):
|
||||||
|
"""Set the reference time for the status bar clock.
|
||||||
|
"""
|
||||||
self.refTime = theTime
|
self.refTime = theTime
|
||||||
return
|
return
|
||||||
|
|
||||||
def setStatus(self, theMessage, timeOut=10.0):
|
def setStatus(self, theMessage, timeOut=10.0):
|
||||||
|
"""Set the status bar message to display for 'timeOut' seconds.
|
||||||
|
"""
|
||||||
self.showMessage(theMessage, int(timeOut*1000))
|
self.showMessage(theMessage, int(timeOut*1000))
|
||||||
|
qApp.processEvents()
|
||||||
return
|
return
|
||||||
|
|
||||||
def setLanguage(self, theLanguage):
|
def setLanguage(self, theLanguage):
|
||||||
|
"""Set the language code for the spell checker.
|
||||||
|
"""
|
||||||
if theLanguage is None:
|
if theLanguage is None:
|
||||||
self.langBox.setText("None")
|
self.langBox.setText("None")
|
||||||
else:
|
else:
|
||||||
@@ -138,6 +147,8 @@ class GuiMainStatus(QStatusBar):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def setProjectStatus(self, isChanged):
|
def setProjectStatus(self, isChanged):
|
||||||
|
"""Set the project status colour icon.
|
||||||
|
"""
|
||||||
if isChanged is None:
|
if isChanged is None:
|
||||||
self.projChanged.setPixmap(self.iconGrey)
|
self.projChanged.setPixmap(self.iconGrey)
|
||||||
elif isChanged == True:
|
elif isChanged == True:
|
||||||
@@ -149,6 +160,8 @@ class GuiMainStatus(QStatusBar):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def setDocumentStatus(self, isChanged):
|
def setDocumentStatus(self, isChanged):
|
||||||
|
"""Set the document status colour icon.
|
||||||
|
"""
|
||||||
if isChanged is None:
|
if isChanged is None:
|
||||||
self.docChanged.setPixmap(self.iconGrey)
|
self.docChanged.setPixmap(self.iconGrey)
|
||||||
elif isChanged == True:
|
elif isChanged == True:
|
||||||
@@ -160,10 +173,14 @@ class GuiMainStatus(QStatusBar):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def setStats(self, pWC, sWC):
|
def setStats(self, pWC, sWC):
|
||||||
|
"""Set the current project statistics.
|
||||||
|
"""
|
||||||
self.boxStats.setText("<b>Project:</b> {:d} : {:d}".format(pWC,sWC))
|
self.boxStats.setText("<b>Project:</b> {:d} : {:d}".format(pWC,sWC))
|
||||||
return
|
return
|
||||||
|
|
||||||
def setCounts(self, cC, wC, pC):
|
def setCounts(self, cC, wC, pC):
|
||||||
|
"""Set the current document statistics.
|
||||||
|
"""
|
||||||
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
|
||||||
|
|
||||||
@@ -172,6 +189,8 @@ class GuiMainStatus(QStatusBar):
|
|||||||
##
|
##
|
||||||
|
|
||||||
def _updateTime(self):
|
def _updateTime(self):
|
||||||
|
"""Update the session clock.
|
||||||
|
"""
|
||||||
if self.refTime is None:
|
if self.refTime is None:
|
||||||
theTime = "00:00:00"
|
theTime = "00:00:00"
|
||||||
else:
|
else:
|
||||||
|
|||||||
+21
-27
@@ -26,17 +26,17 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
|
||||||
import nw
|
import nw
|
||||||
|
|
||||||
from os import path
|
from os import path
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from time import time
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt, QTimer
|
from PyQt5.QtCore import Qt, QTimer
|
||||||
from PyQt5.QtGui import QIcon, QPixmap, QColor, QKeySequence
|
from PyQt5.QtGui import QIcon, QPixmap, QColor, QKeySequence, QCursor
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
qApp, QMainWindow, QVBoxLayout, QFrame, QSplitter, QFileDialog, QShortcut,
|
qApp, QMainWindow, QVBoxLayout, QFrame, QSplitter, QFileDialog, QShortcut,
|
||||||
QMessageBox, QProgressDialog, QDialog, QTabWidget
|
QMessageBox, QDialog, QTabWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from nw.gui import (
|
from nw.gui import (
|
||||||
@@ -635,6 +635,8 @@ class GuiMain(QMainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def rebuildTree(self):
|
def rebuildTree(self):
|
||||||
|
"""Rebuild the project tree.
|
||||||
|
"""
|
||||||
self._makeStatusIcons()
|
self._makeStatusIcons()
|
||||||
self._makeImportIcons()
|
self._makeImportIcons()
|
||||||
self.treeView.clearTree()
|
self.treeView.clearTree()
|
||||||
@@ -642,37 +644,25 @@ class GuiMain(QMainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def rebuildIndex(self):
|
def rebuildIndex(self):
|
||||||
|
"""Rebuild the entire index.
|
||||||
|
"""
|
||||||
|
|
||||||
if not self.hasProject:
|
if not self.hasProject:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
logger.debug("Rebuilding indices ...")
|
logger.debug("Rebuilding index ...")
|
||||||
|
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
|
||||||
|
tStart = time()
|
||||||
|
|
||||||
self.treeView.saveTreeOrder()
|
self.treeView.saveTreeOrder()
|
||||||
self.theIndex.clearIndex()
|
self.theIndex.clearIndex()
|
||||||
nItems = len(self.theProject.projTree)
|
nItems = len(self.theProject.projTree)
|
||||||
|
|
||||||
dlgProg = QProgressDialog("Scanning files ...", "Cancel", 0, nItems, self)
|
theDoc = NWDoc(self.theProject, self)
|
||||||
dlgProg.setWindowModality(Qt.WindowModal)
|
for nDone, tItem in enumerate(self.theProject.projTree):
|
||||||
dlgProg.setMinimumDuration(0)
|
|
||||||
dlgProg.setFixedWidth(480)
|
|
||||||
dlgProg.setLabelText("Starting file scan ...")
|
|
||||||
dlgProg.setValue(0)
|
|
||||||
dlgProg.show()
|
|
||||||
time.sleep(0.5)
|
|
||||||
|
|
||||||
nDone = 0
|
|
||||||
for tItem in self.theProject.projTree:
|
|
||||||
|
|
||||||
dlgProg.setValue(nDone)
|
|
||||||
|
|
||||||
if tItem is not None and tItem.itemType == nwItemType.FILE:
|
if tItem is not None and tItem.itemType == nwItemType.FILE:
|
||||||
|
|
||||||
dlgProg.setLabelText("Scanning: %s" % tItem.itemName)
|
|
||||||
logger.verbose("Scanning: %s" % tItem.itemName)
|
logger.verbose("Scanning: %s" % tItem.itemName)
|
||||||
|
theText = theDoc.openDocument(tItem.itemHandle, showStatus=False)
|
||||||
theDoc = NWDoc(self.theProject, self)
|
|
||||||
theText = theDoc.openDocument(tItem.itemHandle, False)
|
|
||||||
|
|
||||||
# Build tag index
|
# Build tag index
|
||||||
self.theIndex.scanText(tItem.itemHandle, theText)
|
self.theIndex.scanText(tItem.itemHandle, theText)
|
||||||
@@ -685,11 +675,15 @@ class GuiMain(QMainWindow):
|
|||||||
self.treeView.propagateCount(tItem.itemHandle, wC)
|
self.treeView.propagateCount(tItem.itemHandle, wC)
|
||||||
self.treeView.projectWordCount()
|
self.treeView.projectWordCount()
|
||||||
|
|
||||||
nDone += 1
|
self.statusBar.setStatus("Building index: %.2f%%" % (100.0*(nDone + 1)/nItems))
|
||||||
if dlgProg.wasCanceled():
|
|
||||||
break
|
|
||||||
|
|
||||||
dlgProg.setValue(nItems)
|
self.docEditor.reloadText()
|
||||||
|
qApp.restoreOverrideCursor()
|
||||||
|
tEnd = time()
|
||||||
|
|
||||||
|
self.makeAlert(
|
||||||
|
"Project index rebuilt in %.3f seconds." % (tEnd - tStart), nwAlert.INFO
|
||||||
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user