Separated the idle timer from the idle checkbox. Having the latter active doesn't break the former, and the former won't deactivate the latter when you come back.

This commit is contained in:
karxi 2016-12-09 07:55:03 -05:00
parent daeaa74f61
commit 6efac5cd07
3 changed files with 76 additions and 39 deletions

View file

@ -63,7 +63,6 @@ Features
* Right-click Time entry field to see those used? (Replace left/right buttons?) * Right-click Time entry field to see those used? (Replace left/right buttons?)
* Make the memo name entry box accept a comma-separated list * Make the memo name entry box accept a comma-separated list
* Make right-clicking on a tab open up the right-click menu one would get on right-clicking the title (frame??) * Make right-clicking on a tab open up the right-click menu one would get on right-clicking the title (frame??)
* Separate auto-idle and checkbox idle so they don't share a state
Todo/Done Todo/Done
---- ----
@ -73,6 +72,7 @@ Todo/Done
* Toggle individual tab flash / alert sounds (from the same right-click memo that lets us toggle OOC) * Toggle individual tab flash / alert sounds (from the same right-click memo that lets us toggle OOC)
* Make CTRL+PGUP/PGDN switch memo/pester tabs * Make CTRL+PGUP/PGDN switch memo/pester tabs
* Color tags are now posted as their shorter hexadecimal forms, if applicable (255,255,255 -> #FFFFFF, for example) * Color tags are now posted as their shorter hexadecimal forms, if applicable (255,255,255 -> #FFFFFF, for example)
* Separate auto-idle and checkbox idle so they don't share a state (and make the first send set the timer for additional idle responses)
Debugging Debugging
---- ----

View file

@ -405,7 +405,7 @@ class PesterText(QtGui.QTextEdit):
if chum is me: if chum is me:
window.chatlog.log(parent.chum.handle, lexmsg) window.chatlog.log(parent.chum.handle, lexmsg)
else: else:
if window.idleaction.isChecked() and parent.chumopen: if (window.idler.auto or window.idler.manual) and parent.chumopen:
idlethreshhold = 60 idlethreshhold = 60
if (not hasattr(self, 'lastmsg')) or \ if (not hasattr(self, 'lastmsg')) or \
datetime.now() - self.lastmsg > timedelta(0,idlethreshhold): datetime.now() - self.lastmsg > timedelta(0,idlethreshhold):
@ -532,7 +532,7 @@ class PesterInput(QtGui.QLineEdit):
self.setText(prev) self.setText(prev)
elif event.key() in [QtCore.Qt.Key_PageUp, QtCore.Qt.Key_PageDown]: elif event.key() in [QtCore.Qt.Key_PageUp, QtCore.Qt.Key_PageDown]:
self.parent().textArea.keyPressEvent(event) self.parent().textArea.keyPressEvent(event)
self.parent().mainwindow.idletime = 0 self.parent().mainwindow.idler.time = 0
super(PesterInput, self).keyPressEvent(event) super(PesterInput, self).keyPressEvent(event)
class PesterConvo(QtGui.QFrame): class PesterConvo(QtGui.QFrame):

View file

@ -10,6 +10,7 @@ import random
import re import re
from time import time from time import time
import threading, Queue import threading, Queue
from pnc.dep.attrdict import AttrDict
reqmissing = [] reqmissing = []
optmissing = [] optmissing = []
@ -1205,14 +1206,25 @@ class PesterWindow(MovingWindow):
self.waitingMessages = waitingMessageHolder(self) self.waitingMessages = waitingMessageHolder(self)
self.autoidle = False self.idler = AttrDict(dict(
self.idlethreshold = 60*self.config.idleTime() # autoidle
self.idletimer = QtCore.QTimer(self) auto = False,
self.idleposition = QtGui.QCursor.pos() # setidle
self.idletime = 0 manual = False,
self.connect(self.idletimer, QtCore.SIGNAL('timeout()'), # idlethreshold
threshold = 60*self.config.idleTime(),
# idleaction
action = self.idleaction,
# idletimer
timer = QtCore.QTimer(self),
# idleposition
pos = QtGui.QCursor.pos(),
# idletime
time = 0
))
self.connect(self.idler.timer, QtCore.SIGNAL('timeout()'),
self, QtCore.SLOT('checkIdle()')) self, QtCore.SLOT('checkIdle()'))
self.idletimer.start(1000) self.idler.timer.start(1000)
if not self.config.defaultprofile(): if not self.config.defaultprofile():
self.changeProfile() self.changeProfile()
@ -2026,44 +2038,64 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot(bool) @QtCore.pyqtSlot(bool)
def toggleIdle(self, idle): def toggleIdle(self, idle):
if idle: if idle:
# We checked the box to go idle.
self.idler.manual = True
self.setAway.emit(True) self.setAway.emit(True)
self.randhandler.setIdle(True) self.randhandler.setIdle(True)
sysColor = QtGui.QColor(self.theme["convo/systemMsgColor"]) self._sendIdleMsgs()
verb = self.theme["convo/text/idle"]
for (h, convo) in self.convos.iteritems():
# karxi: There's an irritating issue here involving a lack of
# consideration for case-sensitivity.
# This fix is a little sloppy, and I need to look into what it
# might affect, but I've been using it for months and haven't
# noticed any issues....
handle = convo.chum.handle
# karxi: Now we just use 'handle' instead of 'h'.
if convo.chumopen:
msg = self.profile().idlemsg(sysColor, verb)
convo.textArea.append(convertTags(msg))
self.chatlog.log(handle, msg)
self.sendMessage.emit("PESTERCHUM:IDLE", handle)
else: else:
self.idler.manual = False
self.setAway.emit(False) self.setAway.emit(False)
self.randhandler.setIdle(False) self.randhandler.setIdle(False)
self.idletime = 0 self.idler.time = 0
# karxi: TODO: Need to consider sticking an idle-setter here.
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def checkIdle(self): def checkIdle(self):
# TODO: Streamline this later, because ew.
newpos = QtGui.QCursor.pos() newpos = QtGui.QCursor.pos()
if newpos == self.idleposition: if self.idler.manual:
self.idletime += 1 # We're already idle - because the user said to be.
self.idler.pos = newpos
return
if newpos == self.idler.pos:
if not self.idler.auto:
# We're not already automatically idle.
# The cursor hasn't moved; we're that much closer to being idle.
self.idler.time += 1
else: else:
self.idletime = 0 # The cursor moved; reset the idle timer.
if self.idletime >= self.idlethreshold: self.idler.time = 0
if not self.idleaction.isChecked():
self.idleaction.toggle() if self.idler.time >= self.idler.threshold:
self.autoidle = True # We've been idle for long enough to fall automatically idle.
self.idler.auto = True
# We don't need this anymore.
self.idler.time = 0
self._sendIdleMsgs()
else: else:
if self.autoidle: # The mouse moved, and we were auto-away'd.
if self.idleaction.isChecked(): if self.idler.auto:
self.idleaction.toggle() # ...so un-idle us.
self.autoidle = False self.idler.auto = False
self.idleposition = newpos self.idler.pos = newpos
def _sendIdleMsgs(self):
# Tell everyone we're in a chat with that we just went idle.
sysColor = QtGui.QColor(self.theme["convo/systemMsgColor"])
verb = self.theme["convo/text/idle"]
for (h, convo) in self.convos.iteritems():
# karxi: There's an irritating issue here involving a lack of
# consideration for case-sensitivity.
# This fix is a little sloppy, and I need to look into what it
# might affect, but I've been using it for months and haven't
# noticed any issues....
handle = convo.chum.handle
# karxi: Now we just use 'handle' instead of 'h'.
if convo.chumopen:
msg = self.profile().idlemsg(sysColor, verb)
convo.textArea.append(convertTags(msg))
self.chatlog.log(handle, msg)
self.sendMessage.emit("PESTERCHUM:IDLE", handle)
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def importExternalConfig(self): def importExternalConfig(self):
f = QtGui.QFileDialog.getOpenFileName(self) f = QtGui.QFileDialog.getOpenFileName(self)
@ -2428,7 +2460,7 @@ class PesterWindow(MovingWindow):
curidle = self.config.idleTime() curidle = self.config.idleTime()
if idlesetting != curidle: if idlesetting != curidle:
self.config.set('idleTime', idlesetting) self.config.set('idleTime', idlesetting)
self.idlethreshold = 60*idlesetting self.idler.threshold = 60*idlesetting
# theme # theme
ghostchumsetting = self.optionmenu.ghostchum.isChecked() ghostchumsetting = self.optionmenu.ghostchum.isChecked()
curghostchum = self.config.ghostchum() curghostchum = self.config.ghostchum()
@ -3120,6 +3152,11 @@ Click this message to never see this again.")
self.showLoading(self.widget) self.showLoading(self.widget)
sys.exit(self.app.exec_()) sys.exit(self.app.exec_())
def _retrieveGlobals():
# NOTE: Yes, this is a terrible kludge so that the console can work
# properly. I'm open to alternatives.
return globals()
if __name__ == "__main__": if __name__ == "__main__":
# We're being run as a script - not being imported. # We're being run as a script - not being imported.
pesterchum = MainProgram() pesterchum = MainProgram()