From 479975fdff5c3c7b96ef1c2c6365a6c46d1a9244 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 8 Feb 2021 21:33:06 +0100 Subject: [PATCH] Move clock tick timer to main GUI --- nw/gui/statusbar.py | 15 ++------------- nw/guimain.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/nw/gui/statusbar.py b/nw/gui/statusbar.py index f17af853..5997561d 100644 --- a/nw/gui/statusbar.py +++ b/nw/gui/statusbar.py @@ -29,7 +29,6 @@ import logging from time import time -from PyQt5.QtCore import QTimer from PyQt5.QtGui import QColor, QPainter from PyQt5.QtWidgets import qApp, QStatusBar, QLabel, QAbstractButton @@ -110,12 +109,6 @@ class GuiMainStatus(QStatusBar): # Other Settings self.setSizeGripEnabled(True) - # Start the Clock - self.sessionTimer = QTimer() - self.sessionTimer.setInterval(1000) - self.sessionTimer.timeout.connect(self._updateTime) - self.sessionTimer.start() - logger.debug("GuiMainStatus initialisation complete") self.clearStatus() @@ -130,7 +123,7 @@ class GuiMainStatus(QStatusBar): self.setStats(0, 0) self.setProjectStatus(None) self.setDocumentStatus(None) - self._updateTime() + self.updateTime() return True ## @@ -182,11 +175,7 @@ class GuiMainStatus(QStatusBar): self.statsText.setToolTip("Project word count (session change)") return - ## - # Internal Functions - ## - - def _updateTime(self): + def updateTime(self): """Update the session clock. """ if self.refTime is None: diff --git a/nw/guimain.py b/nw/guimain.py index 1511009e..1e0942c7 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -86,6 +86,8 @@ class GuiMain(QMainWindow): self.theIndex = NWIndex(self.theProject, self) self.hasProject = False self.isFocusMode = False + self.userActive = False + self.lastActive = 0 # Prepare Main Window self.resize(*self.mainConf.getWinSize()) @@ -241,6 +243,12 @@ class GuiMain(QMainWindow): self.asDocTimer = QTimer() self.asDocTimer.timeout.connect(self._autoSaveDocument) + # Main Clock + self.mainTimer = QTimer() + self.mainTimer.setInterval(1000) + self.mainTimer.timeout.connect(self._timeTick) + self.mainTimer.start() + # Shortcuts and Actions self._connectMenuActions() @@ -1414,6 +1422,13 @@ class GuiMain(QMainWindow): # Slots ## + @pyqtSlot() + def _timeTick(self): + """Triggered on every tick of the timer. + """ + self.statusBar.updateTime() + return + @pyqtSlot() def _treeSingleClick(self): """Single click on a project tree item just updates the details