-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.py
438 lines (343 loc) · 18.7 KB
/
main.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QPushButton, QCheckBox, QGridLayout, QComboBox, QDoubleSpinBox, QTabWidget, QSpacerItem, QSizePolicy, QMessageBox, QStackedWidget
import json
from iobt_options import default_enabled, default_offsets, default_misc_toggles, default_misc, tooltips_enabled, tooltips_misc_toggles, tooltips_misc
import qdarktheme
import os
import subprocess
def process_exists(process_name):
call = 'TASKLIST', '/FI', 'imagename eq %s' % process_name
# use buildin check_output right away
try:
output = subprocess.check_output(call).decode(errors='ignore')
except UnicodeDecodeError:
output = subprocess.check_output(call).decode('cp1252', errors='ignore') # Windows specific encoding
# check in last line for process name
last_line = output.strip().split('\r\n')[-1]
# because Fail message could be translated
return last_line.lower().startswith(process_name.lower())
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Virtual Desktop Body Tracking Configurator v1.7")
if process_exists("vrserver.exe"):
dlg2 = QMessageBox()
dlg2.setWindowTitle("Virtual Desktop Body Tracking Configurator")
dlg2.setText("Error!\n\nvrserver.exe running!\n\nPlease close SteamVR and try again")
dlg2.exec()
if QMessageBox.StandardButton.Ok:
app.exit()
self.steam = ""
try:
with open(f"{os.getenv('LOCALAPPDATA')}\\openvr\\openvrpaths.vrpath", "r", encoding="utf-8", errors='ignore') as file:
self.steam = json.load(file)["config"][0].replace("\\", "/")
except Exception as e:
dlg2 = QMessageBox()
dlg2.setWindowTitle("Virtual Desktop Body Tracking Configurator")
dlg2.setText(f"Error: {e}")
dlg2.exec()
if QMessageBox.StandardButton.Ok:
app.exit()
self.checkboxes = {}
self.offsets = {}
self.misc = {}
self.stackedwidgets = {}
self.miscOpened = False
layoutTab1 = QGridLayout()
self.layoutTab2 = QGridLayout()
self.layoutTab2.setColumnMinimumWidth(1,150)
layoutTab3 = QVBoxLayout()
for variable in default_misc_toggles:
button = QCheckBox(variable.replace("_", " ").title())
button.setCheckable(True)
button.setChecked(default_misc_toggles.get(variable))
button.setToolTip(tooltips_misc_toggles[variable])
self.misc[variable] = button
layoutTab3.addWidget(button)
for variable in default_misc:
box = QDoubleSpinBox()
box.setPrefix(f"{variable.replace('_', ' ').title()}: ")
box.setMinimum(0)
box.setMaximum(1)
if variable == "hand_data_debounce_time":
box.setMaximum(5)
box.setSingleStep(0.05)
box.setDecimals(3)
box.setValue(default_misc[variable])
box.setToolTip(tooltips_misc[variable])
self.misc[variable] = box
layoutTab3.addWidget(box)
spacer = QSpacerItem(20, 20, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Fixed)
spacer2 = QSpacerItem(100, 0, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Fixed)
spacer3 = QSpacerItem(20, 20, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Fixed)
layoutTab1.addItem(spacer, 16, 0)
layoutTab1.addItem(spacer3,1,0)
self.layoutTab2.addItem(spacer2,0, 1)
self.upperWithHip = QPushButton("Upper Body (With Hip)")
self.upperWithHip.setStyleSheet("QPushButton {background-color: rgb(180,230,255); color: black} QPushButton:hover {background-color: rgb(150,200,235)}")
self.upperWithHip.clicked.connect(self.Upper_With_Hip_clicked)
layoutTab1.addWidget(self.upperWithHip, 0, 0)
self.upper = QPushButton("Upper Body Only")
self.upper.setStyleSheet("QPushButton {background-color: rgb(180,230,255); color: black} QPushButton:hover {background-color: rgb(150,200,235)}")
self.upper.clicked.connect(self.upper_only_clicked)
layoutTab1.addWidget(self.upper, 0, 1)
self.elbows = QPushButton("Elbows Only")
self.elbows.setStyleSheet("QPushButton {background-color: rgb(180,230,255); color: black} QPushButton:hover {background-color: rgb(150,200,235)}")
self.elbows.clicked.connect(self.elbows_only_clicked)
layoutTab1.addWidget(self.elbows, 0, 2)
self.defaults = QPushButton("Reset Enabled Trackers to Defaults")
self.defaults.setStyleSheet("QPushButton {background-color: rgb(100,200,255); color: black} QPushButton:hover {background-color: rgb(70,150,230)}")
self.defaults.clicked.connect(self.reset_clicked)
layoutTab1.addWidget(self.defaults, 17, 0)
self.load = QPushButton("Load Current Settings")
self.load.setStyleSheet("QPushButton {background-color: rgb(140,220,255); color: black} QPushButton:hover {background-color: rgb(130,190,235)}")
self.load.clicked.connect(self.load_settings_clicked)
layoutTab1.addWidget(self.load, 17, 1)
self.load2 = QPushButton("Load Current Settings")
self.load2.setStyleSheet("QPushButton {background-color: rgb(140,220,255); color: black} QPushButton:hover {background-color: rgb(130,190,235)}")
self.load2.clicked.connect(self.load_settings_clicked)
self.layoutTab2.addWidget(self.load2, 3, 0)
self.load3 = QPushButton("Load Current Settings")
self.load3.setStyleSheet("QPushButton {background-color: rgb(140,220,255); color: black} QPushButton:hover {background-color: rgb(130,190,235)}")
self.load3.clicked.connect(self.load_settings_clicked)
layoutTab3.addWidget(self.load3)
self.export = QPushButton("Apply Settings (All Pages)")
self.export.setStyleSheet("QPushButton {background-color: rgb(60,250,60); color: black} QPushButton:hover {background-color: rgb(0,200,150)}")
self.export.clicked.connect(self.export_clicked)
layoutTab1.addWidget(self.export, 17, 2)
self.export2 = QPushButton("Apply Settings (All Pages)")
self.export2.setStyleSheet("QPushButton {background-color: rgb(60,250,60); color: black} QPushButton:hover {background-color: rgb(0,200,150)}")
self.export2.clicked.connect(self.export_clicked)
self.layoutTab2.addWidget(self.export2, 4, 0)
self.export3 = QPushButton("Apply Settings (All Pages)")
self.export3.setStyleSheet("QPushButton {background-color: rgb(60,250,60); color: black} QPushButton:hover {background-color: rgb(0,200,150)}")
self.export3.clicked.connect(self.export_clicked)
layoutTab3.addWidget(self.export3, 10)
first = 0
row = 3
column = 0
for variable in default_enabled:
button = QCheckBox(variable[:-8].replace("_", " ").title())
button.setCheckable(True)
button.setChecked(default_enabled.get(variable))
button.setToolTip(tooltips_enabled[variable])
button.clicked.connect(lambda checked, b=button: self.checkbox_interacted(b))
self.checkboxes[variable] = button
layoutTab1.addWidget(button, row, column)
row += 1
first += 1
if row >= 16 or first == 7:
row = 3
column += 1
widgetTab1 = QWidget()
widgetTab1.setLayout(layoutTab1)
self.dropdown = QComboBox()
for axis in ["Translate X", "Translate Y", "Translate Z", "Rotate X", "Rotate Y", "Rotate Z"]:
self.stackedwidgets[axis] = QStackedWidget()
row = 0
column = 0
for variable in default_enabled:
self.dropdown.addItem(variable[:-8].replace("_", " ").title())
self.offsets[variable] = {}
for axis in ["Translate X", "Translate Y", "Translate Z", "Rotate X", "Rotate Y", "Rotate Z"]:
box = QDoubleSpinBox()
box.setPrefix(f"{axis}: ")
if axis[:-2] == "Rotate":
box.setMaximum(360)
box.setMinimum(-360)
box.setSingleStep(90)
box.setValue(default_offsets[f"{variable[:-8]}_rot_{axis[-1].lower()}"])
else:
box.setSingleStep(0.01)
box.setMaximum(1)
box.setMinimum(-1)
box.setDecimals(3)
box.setValue(default_offsets[f"{variable[:-8]}_offset_{axis[-1].lower()}"])
self.offsets[variable][axis] = box
self.stackedwidgets[axis].addWidget(box)
#layoutTab2.addWidget(box, row, column)
row += 1
if row >= 9:
row = 0
column += 1
self.layoutTab2.addWidget(self.dropdown, 2, 0)
i=1
for axis in ["Translate X", "Translate Y", "Translate Z", "Rotate X", "Rotate Y", "Rotate Z"]:
self.layoutTab2.addWidget(self.stackedwidgets[axis], i, 2)
i+=1
self.dropdown.currentIndexChanged.connect(self.offset_index_changed)
widgetTab2 = QWidget()
widgetTab2.setLayout(self.layoutTab2)
widgetTab3 = QWidget()
widgetTab3.setLayout(layoutTab3)
tabs = QTabWidget()
tabs.currentChanged.connect(self.tabChanged)
tabs.setTabPosition(QTabWidget.TabPosition.North)
tabs.setMovable(True)
tabs.addTab(widgetTab1, "Enabled Trackers")
tabs.addTab(widgetTab2, "Tracker Offsets")
tabs.addTab(widgetTab3, "Miscellaneous")
self.setCentralWidget(tabs)
def tabChanged(self, index: int):
if not self.miscOpened and index == 2:
dlg3 = QMessageBox()
dlg3.setWindowTitle("Virtual Desktop Body Tracking Configurator")
dlg3.setText(f"Do NOT modify miscellaneous options if you do not understand them!")
dlg3.exec()
self.miscOpened = True
def offset_index_changed(self, index):
i=1
for axis in ["Translate X", "Translate Y", "Translate Z", "Rotate X", "Rotate Y", "Rotate Z"]:
self.stackedwidgets[axis].setCurrentIndex(index)
i+=1
def checkbox_interacted(self, checkbox):
()
#print(f"{checkbox.text()} is {checkbox.isChecked()}")
def reset_clicked(self):
#print("Reset Defaults clicked")
for variable, checkbox in self.checkboxes.items():
default_state = default_enabled.get(variable, False)
checkbox.setChecked(default_state)
def Upper_With_Hip_clicked(self):
#print("Upper With Hip clicked")
for variable, checkbox in self.checkboxes.items():
if variable == "left_arm_upper_joint_enabled" or variable == "left_arm_lower_joint_enabled" or variable == "right_arm_upper_joint_enabled" or variable == "right_arm_lower_joint_enabled" or variable == "chest_joint_enabled" or variable == "hips_joint_enabled":
checkbox.setChecked(True)
else:
checkbox.setChecked(False)
def upper_only_clicked(self):
#print("Upper Only clicked")
for variable, checkbox in self.checkboxes.items():
if variable == "left_arm_upper_joint_enabled" or variable == "left_arm_lower_joint_enabled" or variable == "right_arm_upper_joint_enabled" or variable == "right_arm_lower_joint_enabled" or variable == "chest_joint_enabled":
checkbox.setChecked(True)
else:
checkbox.setChecked(False)
def elbows_only_clicked(self):
#print("Elbows Only clicked")
for variable, checkbox in self.checkboxes.items():
if variable == "left_arm_upper_joint_enabled" or variable == "left_arm_lower_joint_enabled" or variable == "right_arm_upper_joint_enabled" or variable == "right_arm_lower_joint_enabled":
checkbox.setChecked(True)
else:
checkbox.setChecked(False)
def load_settings_clicked(self):
try:
with open(f"{self.steam}/steamvr.vrsettings", "r", encoding="utf-8", errors='ignore') as file:
current = json.load(file)["driver_VirtualDesktop"]
for variable in default_enabled:
try:
self.checkboxes[variable].setChecked(current[variable])
except:
()
for variable in default_enabled:
for axis in ["Translate X", "Translate Y", "Translate Z", "Rotate X", "Rotate Y", "Rotate Z"]:
try:
if axis[:-2] == "Rotate":
self.offsets[variable][axis].setValue(current[f"{variable[:-8]}_rot_{axis[-1].lower()}"])
else:
self.offsets[variable][axis].setValue(current[f"{variable[:-8]}_offset_{axis[-1].lower()}"])
except:
()
for variable in default_misc:
try:
self.misc[variable].setValue(current[variable])
except:
()
for variable in default_misc_toggles:
try:
self.misc[variable].setChecked(current[variable])
except:
()
except Exception as e:
if str(e) == r"'driver_VirtualDesktop'":
()
else:
dlg2 = QMessageBox()
dlg2.setWindowTitle("Virtual Desktop Body Tracking Configurator")
dlg2.setText(f"Error: {e}")
dlg2.exec()
if QMessageBox.StandardButton.Ok:
app.exit()
def export_clicked(self):
if process_exists("vrserver.exe"):
dlg2 = QMessageBox()
dlg2.setWindowTitle("Virtual Desktop Body Tracking Configurator")
dlg2.setText("Error!\n\nvrserver.exe running!\n\nPlease close SteamVR and try again")
dlg2.exec()
if QMessageBox.StandardButton.Ok:
app.exit()
#print("Export clicked")
export_dict = {}
for variable, checkbox in self.checkboxes.items():
if default_enabled[variable] != checkbox.isChecked():
export_dict[variable] = checkbox.isChecked()
for variable, joint in self.offsets.items():
for axis, box in joint.items():
if axis[:-2] == "Rotate":
try:
if abs(box.value() - default_offsets[f"{variable[:-8]}_rot_{axis[-1].lower()}"]) < 0.001:
()
else:
export_dict[f"{variable[:-8]}_rot_{axis[-1].lower()}"] = box.value()
except:
if box.value() >= 0.001:
export_dict[f"{variable[:-8]}_rot_{axis[-1].lower()}"] = box.value()
else:
try:
if abs(box.value() - default_offsets[f"{variable[:-8]}_offset_{axis[-1].lower()}"]) < 0.001:
()
else:
export_dict[f"{variable[:-8]}_offset_{axis[-1].lower()}"] = box.value()
except:
if box.value() >= 0.001:
export_dict[f"{variable[:-8]}_offset_{axis[-1].lower()}"] = box.value()
for variable, input in self.misc.items():
try:
if abs(default_misc[variable] - input.value()) >= 0.001:
export_dict[variable] = input.value()
except:
()
try:
if default_misc_toggles[variable] != input.isChecked():
export_dict[variable] = input.isChecked()
except:
()
# with open("output.json", "w", encoding="utf-8", errors='ignore') as outfile:
# json.dump(export_dict, indent=2, fp=outfile)
try:
with open(f"{self.steam}/steamvr.vrsettings", "r+", encoding="utf-8", errors='ignore') as settings:
temp = json.load(settings)
try:
with open(f"{self.steam}/steamvr.vrsettings.originalbackup", "x", encoding="utf-8", errors='ignore') as backup:
json.dump(temp, fp=backup)
backup.close()
except:
()
try:
with open(f"{self.steam}/steamvr.vrsettings.lastbackup", "w", encoding="utf-8", errors='ignore') as backup:
json.dump(temp, fp=backup)
backup.close()
except:
()
temp["driver_VirtualDesktop"] = export_dict
#print(temp)
settings.seek(0)
json.dump(temp, indent=3, fp=settings)
settings.truncate()
settings.close()
dlg = QMessageBox(self)
dlg.setWindowTitle("Virtual Desktop Body Tracking Configurator")
dlg.setText(f"Successfully exported to SteamVR!\n\nBackup of original is saved at: {self.steam}/steamvr.vrsettings.originalbackup\n\nAnd backup of previous settings is saved at: {self.steam}/steamvr.vrsettings.lastbackup")
dlg.exec()
if QMessageBox.StandardButton.Ok:
app.exit()
except Exception as e:
dlg = QMessageBox(self)
dlg.setWindowTitle("Virtual Desktop Body Tracking Configurator")
dlg.setText(f"Error: {e}")
dlg.exec()
if QMessageBox.StandardButton.Ok:
app.exit()
app = QApplication([])
qdarktheme.setup_theme(additional_qss="QToolTip { border: 0px; }")
window = MainWindow()
window.show()
app.exec()