Newer
Older
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from PyQt5 import QtWidgets, QtCore
from pymeasure.display.widgets import TabWidget
class ControlTab(TabWidget, QtWidgets.QWidget):
def __init__(self, name, parent=None):
super().__init__(parent)
self.name = name
self.x_pos = 0
self.y_pos = 0
self.z_pos = 0
self.x_speed = 0
self.y_speed = 0
self.z_speed = 0
self.delay = 200
layout = QtWidgets.QGridLayout()
self.x_label = QtWidgets.QLabel("X Position:")
self.x_value = QtWidgets.QLabel(str(self.x_pos))
layout.addWidget(self.x_label, 0, 0)
layout.addWidget(self.x_value, 0, 1)
self.y_label = QtWidgets.QLabel("Y Position:")
self.y_value = QtWidgets.QLabel(str(self.y_pos))
layout.addWidget(self.y_label, 1, 0)
layout.addWidget(self.y_value, 1, 1)
self.z_label = QtWidgets.QLabel("Z Position:")
self.z_value = QtWidgets.QLabel(str(self.z_pos))
layout.addWidget(self.z_label, 2, 0)
layout.addWidget(self.z_value, 2, 1)
self.x_up_button = QtWidgets.QPushButton("X ↑")
self.x_down_button = QtWidgets.QPushButton("X ↓")
layout.addWidget(self.x_up_button, 0, 2)
layout.addWidget(self.x_down_button, 0, 3)
self.y_up_button = QtWidgets.QPushButton("Y ↑")
self.y_down_button = QtWidgets.QPushButton("Y ↓")
layout.addWidget(self.y_up_button, 1, 2)
layout.addWidget(self.y_down_button, 1, 3)
self.z_up_button = QtWidgets.QPushButton("Z ↑")
self.z_down_button = QtWidgets.QPushButton("Z ↓")
layout.addWidget(self.z_up_button, 2, 2)
layout.addWidget(self.z_down_button, 2, 3)
self.setLayout(layout)
self.x_up_button.pressed.connect(self.start_x_up_timer)
self.x_up_button.released.connect(self.stop_timer)
self.x_up_button.clicked.connect(self.increment_x_up)
self.x_down_button.pressed.connect(self.start_x_down_timer)
self.x_down_button.released.connect(self.stop_timer)
self.x_down_button.clicked.connect(self.increment_x_down)
self.y_up_button.pressed.connect(self.start_y_up_timer)
self.y_up_button.released.connect(self.stop_timer)
self.y_up_button.clicked.connect(self.increment_y_up)
self.y_down_button.pressed.connect(self.start_y_down_timer)
self.y_down_button.released.connect(self.stop_timer)
self.y_down_button.clicked.connect(self.increment_y_down)
self.z_up_button.pressed.connect(self.start_z_up_timer)
self.z_up_button.released.connect(self.stop_timer)
self.z_up_button.clicked.connect(self.increment_z_up)
self.z_down_button.pressed.connect(self.start_z_down_timer)
self.z_down_button.released.connect(self.stop_timer)
self.z_down_button.clicked.connect(self.increment_z_down)
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.update_positions)
def start_x_up_timer(self):
self.x_speed = 1
self.timer.start(self.delay)
def start_x_down_timer(self):
self.x_speed = -1
self.timer.start(self.delay)
def increment_x_up(self):
self.x_pos += 1
self.x_value.setText(str(self.x_pos))
def increment_x_down(self):
self.x_pos -= 1
self.x_value.setText(str(self.x_pos))
def start_y_up_timer(self):
self.y_speed = 1
self.timer.start(self.delay)
def start_y_down_timer(self):
self.y_speed = -1
self.timer.start(self.delay)
def increment_y_up(self):
self.y_pos += 1
self.y_value.setText(str(self.y_pos))
def increment_y_down(self):
self.y_pos -= 1
self.y_value.setText(str(self.y_pos))
def start_z_up_timer(self):
self.z_speed = 1
self.timer.start(self.delay)
def start_z_down_timer(self):
self.z_speed = -1
self.timer.start(self.delay)
def increment_z_up(self):
self.z_pos += 1
self.z_value.setText(str(self.z_pos))
def increment_z_down(self):
self.z_pos -= 1
self.z_value.setText(str(self.z_pos))
def stop_timer(self):
self.x_speed = 0
self.y_speed = 0
self.z_speed = 0
self.delay = 200
self.timer.stop()
def update_positions(self):
self.x_pos += self.x_speed
self.y_pos += self.y_speed
self.z_pos += self.z_speed
self.delay = max(self.delay - 5, 50)
self.timer.start(self.delay)
self.x_value.setText(str(self.x_pos))
self.y_value.setText(str(self.y_pos))
self.z_value.setText(str(self.z_pos))