Added a session timer to the status bar.
This commit is contained in:
+40
-1
@@ -13,6 +13,8 @@
|
|||||||
import logging
|
import logging
|
||||||
import nw
|
import nw
|
||||||
|
|
||||||
|
from time import time
|
||||||
|
from PyQt5.QtCore import Qt, QTimer
|
||||||
from PyQt5.QtGui import QIcon, QColor, QPixmap
|
from PyQt5.QtGui import QIcon, QColor, QPixmap
|
||||||
from PyQt5.QtWidgets import QStatusBar, QLabel, QFrame
|
from PyQt5.QtWidgets import QStatusBar, QLabel, QFrame
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ class GuiMainStatus(QStatusBar):
|
|||||||
logger.debug("Initialising GuiMainStatus ...")
|
logger.debug("Initialising GuiMainStatus ...")
|
||||||
|
|
||||||
self.mainConf = nw.CONFIG
|
self.mainConf = nw.CONFIG
|
||||||
|
self.refTime = None
|
||||||
|
|
||||||
self.iconGrey = QPixmap(16,16)
|
self.iconGrey = QPixmap(16,16)
|
||||||
self.iconGrey.fill(QColor(120,120,120))
|
self.iconGrey.fill(QColor(120,120,120))
|
||||||
@@ -34,10 +37,14 @@ class GuiMainStatus(QStatusBar):
|
|||||||
self.iconGreen = QPixmap(16,16)
|
self.iconGreen = QPixmap(16,16)
|
||||||
self.iconGreen.fill(QColor( 40,120, 0))
|
self.iconGreen.fill(QColor( 40,120, 0))
|
||||||
|
|
||||||
|
|
||||||
self.boxStats = QLabel()
|
self.boxStats = QLabel()
|
||||||
self.boxStats.setToolTip("Project Word Count | Session Word Count")
|
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 = QLabel()
|
||||||
self.boxCounts.setToolTip("Document Character | Word | Paragraph Count")
|
self.boxCounts.setToolTip("Document Character | Word | Paragraph Count")
|
||||||
|
|
||||||
@@ -60,11 +67,17 @@ class GuiMainStatus(QStatusBar):
|
|||||||
self.addPermanentWidget(QLabel(" "))
|
self.addPermanentWidget(QLabel(" "))
|
||||||
self.addPermanentWidget(self.projChanged)
|
self.addPermanentWidget(self.projChanged)
|
||||||
self.addPermanentWidget(self.boxStats)
|
self.addPermanentWidget(self.boxStats)
|
||||||
|
self.addPermanentWidget(self.boxTime)
|
||||||
if self.mainConf.debugGUI:
|
if self.mainConf.debugGUI:
|
||||||
self.addPermanentWidget(self.boxDocHandle)
|
self.addPermanentWidget(self.boxDocHandle)
|
||||||
|
|
||||||
self.setSizeGripEnabled(True)
|
self.setSizeGripEnabled(True)
|
||||||
|
|
||||||
|
self.sessionTimer = QTimer()
|
||||||
|
self.sessionTimer.setInterval(1000)
|
||||||
|
self.sessionTimer.timeout.connect(self._updateTime)
|
||||||
|
self.sessionTimer.start()
|
||||||
|
|
||||||
logger.debug("GuiMainStatus initialisation complete")
|
logger.debug("GuiMainStatus initialisation complete")
|
||||||
|
|
||||||
self.clearStatus()
|
self.clearStatus()
|
||||||
@@ -72,13 +85,19 @@ class GuiMainStatus(QStatusBar):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def clearStatus(self):
|
def clearStatus(self):
|
||||||
|
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.setDocHandleCount(None)
|
||||||
self.setProjectStatus(None)
|
self.setProjectStatus(None)
|
||||||
self.setDocumentStatus(None)
|
self.setDocumentStatus(None)
|
||||||
|
self._updateTime()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def setRefTime(self, theTime):
|
||||||
|
self.refTime = theTime
|
||||||
|
return
|
||||||
|
|
||||||
def setStatus(self, theMessage, timeOut=10.0):
|
def setStatus(self, theMessage, timeOut=10.0):
|
||||||
self.showMessage(theMessage, int(timeOut*1000))
|
self.showMessage(theMessage, int(timeOut*1000))
|
||||||
return
|
return
|
||||||
@@ -120,4 +139,24 @@ class GuiMainStatus(QStatusBar):
|
|||||||
self.boxDocHandle.setText("%13s" % theHandle)
|
self.boxDocHandle.setText("%13s" % theHandle)
|
||||||
return
|
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
|
# END Class GuiMainStatus
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.rebuildTree()
|
self.rebuildTree()
|
||||||
self.saveProject()
|
self.saveProject()
|
||||||
self.hasProject = True
|
self.hasProject = True
|
||||||
|
self.statusBar.setRefTime(self.theProject.projOpened)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -234,6 +235,7 @@ class GuiMain(QMainWindow):
|
|||||||
self.rebuildTree()
|
self.rebuildTree()
|
||||||
self.docEditor.setPwl(path.join(self.theProject.projMeta, nwFiles.PROJ_DICT))
|
self.docEditor.setPwl(path.join(self.theProject.projMeta, nwFiles.PROJ_DICT))
|
||||||
self.docEditor.setSpellCheck(self.theProject.spellCheck)
|
self.docEditor.setSpellCheck(self.theProject.spellCheck)
|
||||||
|
self.statusBar.setRefTime(self.theProject.projOpened)
|
||||||
self.mainMenu.updateMenu()
|
self.mainMenu.updateMenu()
|
||||||
|
|
||||||
# Restore previously open documents, if any
|
# Restore previously open documents, if any
|
||||||
|
|||||||
Reference in New Issue
Block a user