Merged in bugfix/PYPE-578_idle_manager_bug (pull request #340)

Bugfix/PYPE-578 idle manager bug

Approved-by: Milan Kolar <milan@orbi.tools>
This commit is contained in:
Jakub Trllo 2019-10-30 11:56:18 +00:00 committed by Milan Kolar
commit 3898158144

View file

@ -1,4 +1,5 @@
import time
import collections
from Qt import QtCore, QtGui, QtWidgets
from pype.vendor.pynput import mouse, keyboard
from pypeapp import Logger
@ -9,7 +10,7 @@ class IdleManager(QtCore.QThread):
Idle time resets on keyboard/mouse input.
Is able to emit signals at specific time idle.
"""
time_signals = {}
time_signals = collections.defaultdict(list)
idle_time = 0
signal_reset_timer = QtCore.Signal()
@ -35,8 +36,6 @@ class IdleManager(QtCore.QThread):
:param signal: signal that will be emitted (without objects)
:type signal: QtCore.Signal
"""
if emit_time not in self.time_signals:
self.time_signals[emit_time] = []
self.time_signals[emit_time].append(signal)
@property
@ -70,12 +69,22 @@ class IdleManager(QtCore.QThread):
if self.qaction and self.failed_icon:
self.qaction.setIcon(self.failed_icon)
thread_mouse.signal_stop.emit()
thread_mouse.terminate()
thread_mouse.wait()
thread_keyboard.signal_stop.emit()
thread_keyboard.terminate()
thread_keyboard.wait()
# Threads don't have their attrs when Qt application already finished
try:
thread_mouse.signal_stop.emit()
thread_mouse.terminate()
thread_mouse.wait()
except AttributeError:
pass
try:
thread_keyboard.signal_stop.emit()
thread_keyboard.terminate()
thread_keyboard.wait()
except AttributeError:
pass
self._is_running = False
self.log.info('IdleManager has stopped')