-
Notifications
You must be signed in to change notification settings - Fork 0
/
userStudy1Client.py
82 lines (66 loc) · 2.73 KB
/
userStudy1Client.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from PyQt5 import QtGui, QtCore
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtGui import QPainter, QBrush, QPen
from PyQt5.QtCore import Qt, QThread, pyqtSignal
import sys
class Listener(QThread):
isTouchSignal = pyqtSignal(str)
def __init__(self, parent, listenerQueue):
super().__init__(parent)
self.parent = parent
self.working = True
self.listenerQueue = listenerQueue
def run(self):
while self.working:
result = self.listenerQueue.get()
self.isTouchSignal.emit(result) # "middle, 3"
class Window(QMainWindow):
def __init__(self, serverQueue):
super().__init__()
self.title = "PyQt5 Drawing Tutorial"
self.top= 150
self.left= 150
self.width = 500
self.height = 500
self.InitWindow()
self.handTrackingResults = "1, 1"
self.handTrackingListener = Listener(self, serverQueue)
self.handTrackingListener.isTouchSignal.connect(self.handTrackingHandler)
self.handTrackingListener.start()
def InitWindow(self):
self.setWindowTitle(self.title)
self.setGeometry(self.top, self.left, self.width, self.height)
self.show()
def initListener(self, listenerQueue):
self.listener = Listener(self, listenerQueue)
self.listener.isTouchSignal.connect(self.handler)
self.listener.start()
@QtCore.pyqtSlot(str)
def handTrackingHandler(self, result):
results = result.split(",")
self.handTrackingResults = (int(results[0]), int(results[1]))
#self.handTrackingResults = result
self.repaint()
# @QtCore.pyqtSlot(str)
# def touchSensingHandler(self, result):
# self.touchSensingResults = bool(int(result))
# print(self.touchSensingResults)
# #self.repaint()
def paintEvent(self, event):
painter = QPainter(self)
#painter.setPen(QPen(Qt.green, 8, Qt.SolidLine))
#painter.setBrush(QBrush(Qt.red, Qt.SolidPattern))
#painter.drawEllipse(40, 40, 400, 400)
#painter.drawText(20, 40, self.handTrackingResults)
painter.drawText(20, 40, str(self.handTrackingResults[0]) + ", " + str(self.handTrackingResults[1]))
width = 30
height = 20
xPadding = 10
yPadding = 15
for finger in range(1, 5):
for node in range(3):
if self.handTrackingResults[0] == finger and self.handTrackingResults[1] == node:
painter.setBrush(QBrush(Qt.red, Qt.SolidPattern))
else:
painter.setBrush(QBrush(Qt.yellow, Qt.SolidPattern))
painter.drawRect((width + xPadding)*node, (height + yPadding) * finger, width, height)