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