-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
119 lines (99 loc) · 4.61 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
# Required libraries for the complete tool:
## os, serial (pyserial), errno, gphoto2 (run as subprocess), time, math, subprocess, PyQt5, sqlite3
from PyQt5 import QtWidgets as qtw
from interfaz.interfaz import Ui_interfaz
from db.controllerDB import createDataBase, getParams, changeData
from arduino.pruebaSerial import placeSample, takeSamples
import os
import serial
import errno #
class WindInterfaz(qtw.QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.ui = Ui_interfaz()
params = getParams()
self.ui.setupUi(self, params)
# control parameters
self.ui.offset.valueChanged.connect(
lambda: changeData("OFFSET", self.ui.offset.value()))
self.ui.stepSpeed.valueChanged.connect(
lambda: changeData("SPEED_STEP", self.ui.stepSpeed.value()))
self.ui.initSpeed.valueChanged.connect(
lambda: changeData("INITIAL_SPEED", self.ui.initSpeed.value()))
self.ui.tamanioMuestra.valueChanged.connect(
lambda: changeData("SAMPLE_SIZE", self.ui.tamanioMuestra.value()))
self.ui.sizeStep.valueChanged.connect(
lambda: changeData("SIZE_STEP", self.ui.sizeStep.value()))
self.ui.tamanioHusillo.valueChanged.connect(
lambda: changeData("SPINDLE_SIZE", self.ui.tamanioHusillo.value()))
self.ui.platform.valueChanged.connect(
lambda: changeData("PLATFORM", self.ui.platform.value()))
self.ui.newcoreName.clicked.connect(self.coreNamef)
self.ui.crearMuestra.clicked.connect(lambda: self.createSample())
def coreNamef(self):
global coreName
coreName = self.ui.nameCore.text()
global corePath
corePath = "Outputs/" + coreName
if coreName.strip() == "" or coreName.strip() == "None":
qtw.QMessageBox.critical(
self, "Fail", "No valid name for the core.")
else:
if not os.path.isdir(corePath):
qtw.QMessageBox.information(
self, "New directory", 'The Sample Name folder does not exist. New one created.')
try:
os.mkdir(corePath)
except OSError as exc:
if exc.errno != errno.EEXIST:
pass
else:
qtw.QMessageBox.warning(
self, "Duplicated Name",'New images will overwrite the existing ones.\n Are you sure to continue?')
def createSample(self):
conn = serial.Serial('/dev/ttyUSB0', 250000, timeout=1, exclusive=True)
aux = True
reply = qtw.QMessageBox
###
try:
coreName
except NameError:
qtw.QMessageBox.critical(
self, "Incorrect Core Name", "Input a valid (alphanumeric) Core Name.")
else:
if coreName.strip() == '' or coreName.strip() == "None":
qtw.QMessageBox.critical(
self, "Empty Core Name", "Input a valid (alphanumeric) Core Name.")
else:
placeSample(conn,
self.ui.offset.value(),
self.ui.initSpeed.value(),
self.ui.tamanioMuestra.value(),
self.ui.tamanioHusillo.value(),
self.ui.platform.value())
reply = qtw.QMessageBox.information(
self, "Check placement", "Is the sample correctly placed?", qtw.QMessageBox.Yes, qtw.QMessageBox.No)
if reply == qtw.QMessageBox.Yes:
takeSamples(conn,
self.ui.offset.value(),
self.ui.stepSpeed.value(),
self.ui.tamanioMuestra.value(),
self.ui.sizeStep.value(),
self.ui.tamanioHusillo.value(),
self.ui.platform.value(),
##
coreName)
reply2 = qtw.QMessageBox.information(
self, "Task finished", "Image shooting finished", qtw.QMessageBox.Ok)
else:
reply3 = qtw.QMessageBox.critical(
self, "Incorrect placement", "Fix the core correctly and retry", qtw.QMessageBox.Ok)
def createDB():
if not os.path.isfile('.CaptuRING.db'):
createDataBase()
if __name__ == "__main__":
app = qtw.QApplication([])
createDB()
widget = WindInterfaz()
widget.show()
app.exec_()