From 6c6d1ac325426e3a47f00b7d38e5397fb26ec83c Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Sun, 26 May 2019 17:02:32 +0200 Subject: [PATCH] Added a session timer to the status bar. --- nw/gui/statusbar.py | 41 ++++++++++++++++++++++++++++++++++++++++- nw/gui/winmain.py | 4 +++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/nw/gui/statusbar.py b/nw/gui/statusbar.py index d9feb745..4cc437cc 100644 --- a/nw/gui/statusbar.py +++ b/nw/gui/statusbar.py @@ -13,6 +13,8 @@ import logging import nw +from time import time +from PyQt5.QtCore import Qt, QTimer from PyQt5.QtGui import QIcon, QColor, QPixmap from PyQt5.QtWidgets import QStatusBar, QLabel, QFrame @@ -26,6 +28,7 @@ class GuiMainStatus(QStatusBar): logger.debug("Initialising GuiMainStatus ...") self.mainConf = nw.CONFIG + self.refTime = None self.iconGrey = QPixmap(16,16) self.iconGrey.fill(QColor(120,120,120)) @@ -34,10 +37,14 @@ class GuiMainStatus(QStatusBar): self.iconGreen = QPixmap(16,16) self.iconGreen.fill(QColor( 40,120, 0)) - self.boxStats = QLabel() self.boxStats.setToolTip("Project Word Count | Session Word Count") + self.boxTime = QLabel("") + self.boxTime.setToolTip("Session Time") + self.boxTime.setAlignment(Qt.AlignRight) + self.boxTime.setMinimumWidth(80) + self.boxCounts = QLabel() self.boxCounts.setToolTip("Document Character | Word | Paragraph Count") @@ -60,11 +67,17 @@ class GuiMainStatus(QStatusBar): self.addPermanentWidget(QLabel(" ")) self.addPermanentWidget(self.projChanged) self.addPermanentWidget(self.boxStats) + self.addPermanentWidget(self.boxTime) if self.mainConf.debugGUI: self.addPermanentWidget(self.boxDocHandle) self.setSizeGripEnabled(True) + self.sessionTimer = QTimer() + self.sessionTimer.setInterval(1000) + self.sessionTimer.timeout.connect(self._updateTime) + self.sessionTimer.start() + logger.debug("GuiMainStatus initialisation complete") self.clearStatus() @@ -72,13 +85,19 @@ class GuiMainStatus(QStatusBar): return def clearStatus(self): + self.setRefTime(None) self.setStats(0,0) self.setCounts(0,0,0) self.setDocHandleCount(None) self.setProjectStatus(None) self.setDocumentStatus(None) + self._updateTime() return True + def setRefTime(self, theTime): + self.refTime = theTime + return + def setStatus(self, theMessage, timeOut=10.0): self.showMessage(theMessage, int(timeOut*1000)) return @@ -120,4 +139,24 @@ class GuiMainStatus(QStatusBar): self.boxDocHandle.setText("%13s" % theHandle) return + ## + # Internal Functions + ## + + def _updateTime(self): + sTime = time() + if self.refTime is None: + theTime = "00:00:00" + else: + # This is much faster than using datetime format + tS = int(time() - self.refTime) + tM = int(tS/60) + tH = int(tM/60) + tM = tM - tH*60 + tS = tS - tM*60 - tH*3600 + theTime = "%02d:%02d:%02d" % (tH,tM,tS) + self.boxTime.setText(theTime) + print((time()-sTime)*1e6) + return + # END Class GuiMainStatus diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py index 36a9e0f1..46948ae1 100644 --- a/nw/gui/winmain.py +++ b/nw/gui/winmain.py @@ -180,6 +180,7 @@ class GuiMain(QMainWindow): self.rebuildTree() self.saveProject() self.hasProject = True + self.statusBar.setRefTime(self.theProject.projOpened) return True @@ -209,7 +210,7 @@ class GuiMain(QMainWindow): self.theProject.closeProject() self.clearGUI() self.hasProject = False - + return saveOK def openProject(self, projFile=None): @@ -234,6 +235,7 @@ class GuiMain(QMainWindow): self.rebuildTree() self.docEditor.setPwl(path.join(self.theProject.projMeta, nwFiles.PROJ_DICT)) self.docEditor.setSpellCheck(self.theProject.spellCheck) + self.statusBar.setRefTime(self.theProject.projOpened) self.mainMenu.updateMenu() # Restore previously open documents, if any