From 407f12760cc116a67ad89a322ca3c836aad2ffc5 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 8 Feb 2021 21:58:38 +0100 Subject: [PATCH] Record idle time --- nw/gui/statusbar.py | 4 ++-- nw/guimain.py | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/nw/gui/statusbar.py b/nw/gui/statusbar.py index 5997561d..ebc0593a 100644 --- a/nw/gui/statusbar.py +++ b/nw/gui/statusbar.py @@ -175,13 +175,13 @@ class GuiMainStatus(QStatusBar): self.statsText.setToolTip("Project word count (session change)") return - def updateTime(self): + def updateTime(self, idleTime=0.0): """Update the session clock. """ if self.refTime is None: self.timeText.setText("00:00:00") else: - self.timeText.setText(formatTime(round(time() - self.refTime))) + self.timeText.setText(formatTime(round(time() - self.refTime - idleTime))) return # END Class GuiMainStatus diff --git a/nw/guimain.py b/nw/guimain.py index 1e0942c7..1bf3fd8f 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -86,8 +86,8 @@ class GuiMain(QMainWindow): self.theIndex = NWIndex(self.theProject, self) self.hasProject = False self.isFocusMode = False - self.userActive = False - self.lastActive = 0 + self.idleRefTime = time() + self.idleTime = 0.0 # Prepare Main Window self.resize(*self.mainConf.getWinSize()) @@ -485,7 +485,9 @@ class GuiMain(QMainWindow): return False # Project is loaded - self.hasProject = True + self.hasProject = True + self.idleRefTime = time() + self.idleTime = 0.0 # Load the tag index self.theIndex.loadIndex() @@ -1426,7 +1428,20 @@ class GuiMain(QMainWindow): def _timeTick(self): """Triggered on every tick of the timer. """ - self.statusBar.updateTime() + if not self.hasProject: + return + + currTime = time() + editIdle = currTime - self.docEditor.lastEdit > 30.0 + userIdle = qApp.applicationState() != Qt.ApplicationActive + + if editIdle or userIdle: + self.idleTime += currTime - self.idleRefTime + + self.idleRefTime = currTime + self.statusBar.updateTime(idleTime=self.idleTime) + # print(editIdle, userIdle, self.idleTime) + return @pyqtSlot()