-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathpredworker.py
More file actions
40 lines (34 loc) · 1.21 KB
/
predworker.py
File metadata and controls
40 lines (34 loc) · 1.21 KB
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
import queue
from PyQt5.QtCore import Qt, QObject, QThread, pyqtSignal
import predictions, decoder
class PredictionsWorker(QObject):
finished = pyqtSignal()
dataReady = pyqtSignal()
newChar = pyqtSignal(str)
def __init__(self, preds, dataq):
super().__init__()
self.preds = preds
self.dataq = dataq
self.running = True
self.decoder = decoder.MorseDecoderRegen()
def set_dit_len(self, dit_len):
self.decoder.set_dit_len(dit_len)
def set_thr(self, thr):
self.decoder.set_thr(thr)
def reset_hist(self):
self.decoder.reset_hist()
def run(self):
while self.running:
try:
data = self.dataq.get(timeout=1) # give a chance to stop thread
except queue.Empty:
continue
self.preds.new_data(data)
if self.preds.p_preds_t is not None:
self.dataReady.emit()
for i in range(self.preds.p_preds_t.shape[1]):
s = self.preds.p_preds_t[:,i]
char, env = self.decoder.new_sample(s)
if char:
self.newChar.emit(self.decoder.char)
self.finished.emit()