-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_gui.py
133 lines (109 loc) · 4.48 KB
/
main_gui.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
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QFileDialog
import os.path
import sys
import threading
# imports for layout
from menulayout import MainMenu
from popuplayout import Ui_CaptureData
# imports for functionality
from capture_test import *
from view import *
from run_system import *
# Class handling for main menu
class MyMenu(QtWidgets.QDialog):
def __init__(self):
super(MyMenu, self).__init__()
self.ui = MainMenu()
self.ui.setupUi(self)
self.show()
self.dirName = ""
# Define button actions to functions
self.ui.CaptureData.clicked.connect(self.capture)
self.ui.Reg.clicked.connect(self.registration)
self.ui.LoadDir.clicked.connect(self.dir_open)
self.ui.Deselect.clicked.connect(self.deselect)
self.ui.ViewPointCloud.clicked.connect(self.view_pointcloud)
self.ui.ViewMesh.clicked.connect(self.view_mesh)
def capture(self):
self.hide() # Hide window
# Always pull up popup
self.popup = CaptureDataDialog(self.dirName)
test = self.popup.exec_() # Blocking action
if (test): # If the user did not click the x in the corner
self.dirName = self.popup.dirName
self.ui.DirText.setText("Directory Selected: " + self.dirName)
self.ui.Reg.setEnabled(True)
self.ui.Deselect.setEnabled(True)
thread = threading.Thread(target=main_capture, args=[self.dirName])
thread.start()
thread.join()
self.show()
def registration(self):
self.hide()
thread = threading.Thread(target=main_register_capture, args=[self.dirName])
thread.start()
thread.join()
self.show()
def dir_open(self):
self.dirName = QFileDialog.getExistingDirectory()
self.ui.DirText.setText("Directory Selected: " + self.dirName)
if (self.dirName != ""): # i.e. they exit without selecting a directory
self.ui.Reg.setEnabled(True) # Reg should be allowed only when a directory is selected
self.ui.Deselect.setEnabled(True) # Deselect should be allowed only when a directory is selected
def deselect(self):
self.dirName = ""
self.ui.DirText.setText("Directory Selected: " + self.dirName)
self.ui.Reg.setEnabled(False)
self.ui.Deselect.setEnabled(False)
def view_pointcloud(self):
fileName = QFileDialog.getOpenFileName()
if (fileName != ""): # file must be selected
self.hide()
thread = threading.Thread(target=main_view_cloud, args=[fileName[0]])
thread.start()
thread.join()
self.show()
def view_mesh(self):
fileName = QFileDialog.getOpenFileName()
if (fileName != ""): # file must be selected
self.hide()
thread = threading.Thread(target=main_view_mesh, args=[fileName[0]])
thread.start()
thread.join()
self.show()
# Class handling for popup dialog
class CaptureDataDialog(QtWidgets.QDialog):
def __init__(self, givendirName):
super(CaptureDataDialog, self).__init__()
self.ui = Ui_CaptureData()
self.ui.setupUi(self)
self.show()
# set up buttons
self.ui.LoadDir_3.clicked.connect(self.dir_open)
self.ui.Deselect.clicked.connect(self.deselect)
self.ui.lineEdit.textChanged.connect(self.textchanged)
self.ui.pushButton.clicked.connect(self.select)
# set dirName from main menu, empty if nothing selected
self.dirName = givendirName
self.ui.lineEdit.setText(self.dirName)
def dir_open(self):
self.dirName = QFileDialog.getExistingDirectory()
self.ui.lineEdit.setText(self.dirName)
def deselect(self): # clears input
self.dirName = ""
self.ui.lineEdit.setText(self.dirName)
self.ui.Deselect.setEnabled(False)
def textchanged(self):
if (self.ui.lineEdit.text() != ""):
self.ui.Deselect.setEnabled(True) # enable deselect whenever text is input
def select(self):
self.dirName = self.ui.lineEdit.text()
if not(os.path.isdir(self.dirName)): # warning for not a directory
self.ui.DirText.setText("You did not enter in a valid directory.")
else:
self.accept() #exit out
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
Menu = MyMenu()
sys.exit(app.exec_())