-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSessionController.py
40 lines (32 loc) · 1.19 KB
/
SessionController.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Class with an instance shared by the main event controller and the session worker
# Using mutex-lock, basic status such as "cancel the thread" can be set by the main controller
# and safely read and responded to by the worker.
from PyQt5.QtCore import QMutex
class SessionController:
def __init__(self):
self._mutex = QMutex()
self._thread_ok_to_run = True
self._show_adus = True
def cancel_thread(self):
"""Set flag to cancel the controlled thread"""
self._mutex.lock()
self._thread_ok_to_run = False
self._mutex.unlock()
def thread_running(self):
"""Indicate if the controlled thread is still running"""
self._mutex.lock()
result = self._thread_ok_to_run
self._mutex.unlock()
return result
def thread_cancelled(self):
"""Indicate if the controlled thread is cancelled"""
return not self.thread_running()
def get_show_adus(self) -> bool:
self._mutex.lock()
result = self._show_adus
self._mutex.unlock()
return result
def set_show_adus(self, flag: bool):
self._mutex.lock()
self._show_adus = flag
self._mutex.unlock()