Add preferences for controlling session timer behaviour

This commit is contained in:
Veronica K. B. Olsen
2021-02-09 18:54:44 +01:00
parent b1eca89a05
commit f1b31f26d0
5 changed files with 70 additions and 12 deletions
+11
View File
@@ -144,6 +144,9 @@ class Config:
self.allowOpenDQuote = True # Allow open-ended double quotes self.allowOpenDQuote = True # Allow open-ended double quotes
self.highlightEmph = True # Add colour to text emphasis self.highlightEmph = True # Add colour to text emphasis
self.stopWhenIdle = True # Stop the status bar clock when the user is idle
self.userIdleTime = 300 # Time of inactivity to consider user idle
## User-Selected Symbols ## User-Selected Symbols
self.fmtApostrophe = nwUnicode.U_RSQUO self.fmtApostrophe = nwUnicode.U_RSQUO
self.fmtSingleQuotes = [nwUnicode.U_LSQUO, nwUnicode.U_RSQUO] self.fmtSingleQuotes = [nwUnicode.U_LSQUO, nwUnicode.U_RSQUO]
@@ -532,6 +535,12 @@ class Config:
self.highlightEmph = self._parseLine( self.highlightEmph = self._parseLine(
cnfParse, cnfSec, "highlightemph", self.CNF_BOOL, self.highlightEmph cnfParse, cnfSec, "highlightemph", self.CNF_BOOL, self.highlightEmph
) )
self.stopWhenIdle = self._parseLine(
cnfParse, cnfSec, "stopwhenidle", self.CNF_BOOL, self.stopWhenIdle
)
self.userIdleTime = self._parseLine(
cnfParse, cnfSec, "useridletime", self.CNF_INT, self.userIdleTime
)
## Backup ## Backup
cnfSec = "Backup" cnfSec = "Backup"
@@ -672,6 +681,8 @@ class Config:
cnfParse.set(cnfSec, "allowopensquote", str(self.allowOpenSQuote)) cnfParse.set(cnfSec, "allowopensquote", str(self.allowOpenSQuote))
cnfParse.set(cnfSec, "allowopendquote", str(self.allowOpenDQuote)) cnfParse.set(cnfSec, "allowopendquote", str(self.allowOpenDQuote))
cnfParse.set(cnfSec, "highlightemph", str(self.highlightEmph)) cnfParse.set(cnfSec, "highlightemph", str(self.highlightEmph))
cnfParse.set(cnfSec, "stopwhenidle", str(self.stopWhenIdle))
cnfParse.set(cnfSec, "useridletime", str(self.userIdleTime))
## Backup ## Backup
cnfSec = "Backup" cnfSec = "Backup"
+15 -10
View File
@@ -91,6 +91,7 @@ class GuiDocEditor(QTextEdit):
self.wordCount = 0 # Word count self.wordCount = 0 # Word count
self.paraCount = 0 # Paragraph count self.paraCount = 0 # Paragraph count
self.lastEdit = 0 # Time stamp of last edit self.lastEdit = 0 # Time stamp of last edit
self.lastActive = 0 # Time stamp of last activity
self.lastFind = None # Position of the last found search word self.lastFind = None # Position of the last found search word
self.bigDoc = False # Flag for very large document size self.bigDoc = False # Flag for very large document size
self.doReplace = False # Switch to temporarily disable auto-replace self.doReplace = False # Switch to temporarily disable auto-replace
@@ -169,15 +170,16 @@ class GuiDocEditor(QTextEdit):
self.clear() self.clear()
self.wcTimer.stop() self.wcTimer.stop()
self.theHandle = None self.theHandle = None
self.charCount = 0 self.charCount = 0
self.wordCount = 0 self.wordCount = 0
self.paraCount = 0 self.paraCount = 0
self.lastEdit = 0 self.lastEdit = 0
self.lastFind = None self.lastActive = 0
self.bigDoc = False self.lastFind = None
self.doReplace = False self.bigDoc = False
self.queuePos = None self.doReplace = False
self.queuePos = None
self.setDocumentChanged(False) self.setDocumentChanged(False)
self.docHeader.setTitleFromHandle(self.theHandle) self.docHeader.setTitleFromHandle(self.theHandle)
@@ -319,6 +321,7 @@ class GuiDocEditor(QTextEdit):
logger.debug("Document highlighted in %.3f ms" % (1000*(afTime-bfTime))) logger.debug("Document highlighted in %.3f ms" % (1000*(afTime-bfTime)))
self.lastEdit = time() self.lastEdit = time()
self.lastActive = time()
self._runCounter() self._runCounter()
self.wcTimer.start() self.wcTimer.start()
self.theHandle = tHandle self.theHandle = tHandle
@@ -722,6 +725,7 @@ class GuiDocEditor(QTextEdit):
return False return False
self._allowAutoReplace(True) self._allowAutoReplace(True)
self.lastActive = time()
return True return True
@@ -839,6 +843,7 @@ class GuiDocEditor(QTextEdit):
* The undo/redo/select all sequences bypasses the docAction * The undo/redo/select all sequences bypasses the docAction
pathway from the menu, so we redirect them back from here. pathway from the menu, so we redirect them back from here.
""" """
self.lastActive = time()
isReturn = keyEvent.key() == Qt.Key_Return isReturn = keyEvent.key() == Qt.Key_Return
isReturn |= keyEvent.key() == Qt.Key_Enter isReturn |= keyEvent.key() == Qt.Key_Enter
if isReturn and self.docSearch.anyFocus(): if isReturn and self.docSearch.anyFocus():
@@ -1083,7 +1088,7 @@ class GuiDocEditor(QTextEdit):
logger.verbose("Word counter is busy") logger.verbose("Word counter is busy")
return return
if time() - self.lastEdit < 5*self.wcInterval: if time() - self.lastEdit < 5 * self.wcInterval:
logger.verbose("Running word counter") logger.verbose("Running word counter")
self.theParent.threadPool.start(self.wCounter) self.theParent.threadPool.start(self.wCounter)
+31
View File
@@ -358,6 +358,33 @@ class GuiPreferencesProjects(QWidget):
"If off, backups will run in the background." "If off, backups will run in the background."
) )
# Session Timer
# =============
self.mainForm.addGroupLabel("Session Timer")
## Pause when idle
self.stopWhenIdle = QSwitch()
self.stopWhenIdle.setChecked(self.mainConf.stopWhenIdle)
self.mainForm.addRow(
"Pause the session timer when not writing",
self.stopWhenIdle,
"Also pauses when the application window does not have focus."
)
## Inactive time for idle
self.userIdleTime = QDoubleSpinBox()
self.userIdleTime.setMinimum(0.5)
self.userIdleTime.setMaximum(600.0)
self.userIdleTime.setSingleStep(0.5)
self.userIdleTime.setDecimals(1)
self.userIdleTime.setValue(self.mainConf.userIdleTime/60.0)
self.mainForm.addRow(
"Editor inactive time before pausing timer",
self.userIdleTime,
"User activity includes typing and changing the content.",
theUnit="minutes"
)
return return
def saveValues(self): def saveValues(self):
@@ -372,6 +399,10 @@ class GuiPreferencesProjects(QWidget):
self.mainConf.backupOnClose = self.backupOnClose.isChecked() self.mainConf.backupOnClose = self.backupOnClose.isChecked()
self.mainConf.askBeforeBackup = self.askBeforeBackup.isChecked() self.mainConf.askBeforeBackup = self.askBeforeBackup.isChecked()
# Session Timer
self.mainConf.stopWhenIdle = self.stopWhenIdle.isChecked()
self.mainConf.userIdleTime = round(self.userIdleTime.value() * 60)
self.mainConf.confChanged = True self.mainConf.confChanged = True
return return
+8 -1
View File
@@ -182,6 +182,9 @@ class GuiMainStatus(QStatusBar):
def setUserIdle(self, userIdle): def setUserIdle(self, userIdle):
"""Change the idle status icon. """Change the idle status icon.
""" """
if not self.mainConf.stopWhenIdle:
userIdle = False
if self.userIdle != userIdle: if self.userIdle != userIdle:
if userIdle: if userIdle:
self.timeIcon.setPixmap(self.idlePixmap) self.timeIcon.setPixmap(self.idlePixmap)
@@ -198,7 +201,11 @@ class GuiMainStatus(QStatusBar):
if self.refTime is None: if self.refTime is None:
self.timeText.setText("00:00:00") self.timeText.setText("00:00:00")
else: else:
self.timeText.setText(formatTime(round(time() - self.refTime - idleTime))) if self.mainConf.stopWhenIdle:
sessTime = round(time() - self.refTime - idleTime)
else:
sessTime = round(time() - self.refTime)
self.timeText.setText(formatTime(sessTime))
return return
# END Class GuiMainStatus # END Class GuiMainStatus
+5 -1
View File
@@ -420,7 +420,11 @@ class GuiMain(QMainWindow):
self.closeDocument() self.closeDocument()
self.docViewer.clearNavHistory() self.docViewer.clearNavHistory()
self.projView.closeOutline() self.projView.closeOutline()
self.theProject.closeProject(self.idleTime) self.theProject.closeProject(self.idleTime)
self.idleRefTime = time()
self.idleTime = 0.0
self.theIndex.clearIndex() self.theIndex.clearIndex()
self.clearGUI() self.clearGUI()
self.hasProject = False self.hasProject = False
@@ -1432,7 +1436,7 @@ class GuiMain(QMainWindow):
return return
currTime = time() currTime = time()
editIdle = currTime - self.docEditor.lastEdit > 30.0 editIdle = currTime - self.docEditor.lastActive > self.mainConf.userIdleTime
userIdle = qApp.applicationState() != Qt.ApplicationActive userIdle = qApp.applicationState() != Qt.ApplicationActive
if editIdle or userIdle: if editIdle or userIdle: