-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarvingBasicUI.py
225 lines (196 loc) · 10.7 KB
/
CarvingBasicUI.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
"""
Server version: {tcp_gateway,{ok,"4.67.1-r91102","1.0"}}.
Last update: 10 June 2020
Created: 08 June 2020
Basic UI to control SPECS Carving manipulator
@author: Victor Rogalev
"""
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QAction
import pyqtgraph as pg
class Ui_MainWindow(QMainWindow):
def __init__(self, *args):
super().__init__()
self.w = 300
# self.h = 800
self.h = 350
self.setGeometry(300, 300, self.w, self.h)
self.my_menu_bar = self.menuBar()
self.options_menu = self.my_menu_bar.addMenu('Options')
self.statusbar = self.statusBar()
self.statusbar.showMessage('Ready')
self.toggle_mode_action = QAction('God Mode', self, checkable=True)
self.toggle_mode_action.setStatusTip('Enable God Mode')
self.toggle_mode_action.setChecked(False)
self.options_menu.addAction(self.toggle_mode_action)
self.setup_ui()
def setup_ui(self):
self.layoutWidget = QtWidgets.QWidget(self)
# self.layoutWidget.setGeometry(QtCore.QRect(10, 10, self.w-10, self.h-10))
self.layoutWidget.setObjectName("layoutWidget")
self.layoutWidget.setStyleSheet("background-color:grey;")
self.setCentralWidget(self.layoutWidget)
self.MainVerticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
self.MainHorizontalLayout = QtWidgets.QHBoxLayout()
"""Create axes control labels/buttons and pack them into a dictionary self.axes_objects_dict which looks like
{" X ":SingleAxisControlDict, " Y ":SingleAxisControlDict,...}"""
self.VerticalLayoutXYZ = QtWidgets.QVBoxLayout()
self.VerticalLayoutXYZ.setContentsMargins(0, 0, 0, 0)
self.VerticalLayoutXYZ.setObjectName("VerticalLayoutXYZ")
self.axes_names_tuple = (" X ", " Y ", " Z ", "Pol", "Azi", "Tilt")
self.axes_objects_dict = {}
for i in range(len(self.axes_names_tuple)):
self.SetAxisHorizontalLayout()
self.SingleAxisControlDict[0].setText(self.axes_names_tuple[i])
self.axes_objects_dict[self.axes_names_tuple[i]]=self.SingleAxisControlDict
"""Predefined positions and stop button vertical layout"""
self.VerticalLayoutPredefined = QtWidgets.QVBoxLayout()
self.VerticalLayoutPredefined.setContentsMargins(0, 0, 0, 0)
self.predefined_buttons_names_tuple = (" ARPES ", " SCREW ", " EXCH ", " FREE ", " STOP ")
self.predefined_buttons_objects_dict = {}
for i in range(len(self.predefined_buttons_names_tuple)):
self.predefined_buttons_objects_dict[self.predefined_buttons_names_tuple[i]]=self.SetPredefinedButtons()
self.predefined_buttons_objects_dict[self.predefined_buttons_names_tuple[i]].setText(self.predefined_buttons_names_tuple[i])
self.HorizontalLayoutPath = QtWidgets.QHBoxLayout()
# self.HorizontalLayoutPath.setContentsMargins(0, 0, 0, 0)
"""Set up the backlash RadioButton"""
self.backlash_radiobutton = QtWidgets.QRadioButton("BACKLASH", self.layoutWidget)
self.StyleSheetOn = "QRadioButton::indicator {width: 15px; height: 15px; border-radius: 7px;} " \
"QRadioButton::indicator:checked { background-color: lime; border: 2px solid gray;} " \
"QRadioButton::indicator:unchecked { background-color: black; border: 2px solid gray;}"
self.backlash_radiobutton.setStyleSheet(self.StyleSheetOn)
self.backlash_radiobutton.toggle()
self.HorizontalLayoutPath.addWidget(self.backlash_radiobutton)
"""Path buttons horizontal layout"""
self.path_buttons_names_tuple = (" Add PATH ", " Edit PATH ", " Clear PATH ", " Generate PATH ", "CAMERA")
self.path_buttons_objects_dict = {}
for i in range(len(self.path_buttons_names_tuple)):
self.path_buttons_objects_dict[self.path_buttons_names_tuple[i]]=self.SetPathButtons()
self.path_buttons_objects_dict[self.path_buttons_names_tuple[i]].setText(self.path_buttons_names_tuple[i])
"Add label to show image from camera on it"
# self.graphics_view = pg.GraphicsLayoutWidget()
# self.p1 = self.graphics_view.addViewBox()
# self.imv = pg.ImageItem()
# self.p1.addItem(self.imv)
"""Combine all layouts"""
self.MainHorizontalLayout.addLayout(self.VerticalLayoutXYZ)
self.MainHorizontalLayout.addLayout(self.VerticalLayoutPredefined)
self.MainVerticalLayout.addLayout(self.MainHorizontalLayout)
self.MainVerticalLayout.addLayout(self.HorizontalLayoutPath)
# self.MainVerticalLayout.addWidget(self.graphics_view)
def SetPathButtons(self):
"PushButton to work with path positions and generate path"
self.pushButton = QtWidgets.QPushButton(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setBold(False)
font.setKerning(True)
self.pushButton.setFont(font)
self.pushButton.setLayoutDirection(QtCore.Qt.LeftToRight)
self.pushButton.setCheckable(False)
self.HorizontalLayoutPath.addWidget(self.pushButton)
return self.pushButton
def SetPredefinedButtons(self):
"PushButton to move the axis to a predefined position"
self.pushButton = QtWidgets.QPushButton(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
self.pushButton.setFixedHeight(50)
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
font.setKerning(True)
self.pushButton.setFont(font)
self.pushButton.setLayoutDirection(QtCore.Qt.LeftToRight)
self.pushButton.setCheckable(False)
self.VerticalLayoutPredefined.addWidget(self.pushButton)
return self.pushButton
def SetAxisHorizontalLayout(self):
self.SingleAxisControlDict = {}
self.HorizontalLayout = QtWidgets.QHBoxLayout()
"Label showing name of the axis"
self.Label = QtWidgets.QLabel(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
# sizePolicy.setHeightForWidth(self.Label.sizePolicy().hasHeightForWidth())
self.Label.setFixedWidth(30)
self.Label.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setPointSize(16)
self.Label.setFont(font)
self.Label.setAlignment(QtCore.Qt.AlignCenter)
self.HorizontalLayout.addWidget(self.Label)
self.SingleAxisControlDict[0] = self.Label
self.HorizontalLayout.addStretch()
"Label showing current position of the axis"
self.Label = QtWidgets.QLabel(self.layoutWidget)
# sizePolicy.setHeightForWidth(self.Label.sizePolicy().hasHeightForWidth())
self.Label.setFixedWidth(90)
self.Label.setSizePolicy(sizePolicy)
self.Label.setFont(font)
self.Label.setAlignment(QtCore.Qt.AlignCenter)
self.Label.setStyleSheet("color: rgb(52,181,52); background: rgb(0,0,0);")
self.Label.setText(" 0.00 ")
self.HorizontalLayout.addWidget(self.Label)
self.SingleAxisControlDict[1]=self.Label
"LineEdit to enter the required position of the axis"
self.LineEdit = QtWidgets.QLineEdit(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHeightForWidth(self.LineEdit.sizePolicy().hasHeightForWidth())
self.LineEdit.setSizePolicy(sizePolicy)
self.LineEdit.setFont(font)
self.LineEdit.setAlignment(QtCore.Qt.AlignCenter)
self.HorizontalLayout.addWidget(self.LineEdit)
self.SingleAxisControlDict[2]=self.LineEdit
self.HorizontalLayout.addStretch()
# self.spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
# self.HorizontalLayout.addItem(self.spacerItem)
"PushButton to move the axis by delta to the lower values"
self.pushButton = QtWidgets.QPushButton(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
font.setBold(False)
font.setWeight(50)
font.setKerning(True)
self.pushButton.setFont(font)
self.pushButton.setLayoutDirection(QtCore.Qt.LeftToRight)
self.pushButton.setCheckable(False)
self.pushButton.setText("<<")
self.HorizontalLayout.addWidget(self.pushButton)
self.SingleAxisControlDict[3] = self.pushButton
self.HorizontalLayout.addStretch()
"LineEdit to enter the required position of delta to move the axis"
self.LineEdit = QtWidgets.QLineEdit(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.LineEdit.sizePolicy().hasHeightForWidth())
self.LineEdit.setSizePolicy(sizePolicy)
font.setPointSize(16)
self.LineEdit.setFont(font)
self.LineEdit.setAlignment(QtCore.Qt.AlignCenter)
self.LineEdit.setText("0.10")
self.HorizontalLayout.addWidget(self.LineEdit)
self.SingleAxisControlDict[4]=self.LineEdit
self.HorizontalLayout.addStretch()
"PushButton to move the axis by delta to the lower values"
self.pushButton = QtWidgets.QPushButton(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
font.setBold(False)
font.setWeight(50)
font.setKerning(True)
self.pushButton.setFont(font)
self.pushButton.setLayoutDirection(QtCore.Qt.LeftToRight)
self.pushButton.setCheckable(False)
self.pushButton.setText(">>")
self.HorizontalLayout.addWidget(self.pushButton)
self.SingleAxisControlDict[5] = self.pushButton
self.HorizontalLayout.addStretch()
self.VerticalLayoutXYZ.addLayout(self.HorizontalLayout)