-
Notifications
You must be signed in to change notification settings - Fork 1
/
Spectrometer_GUI.py
102 lines (81 loc) · 2.94 KB
/
Spectrometer_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
import time
from PyQt5 import QtCore, QtWidgets, uic
from PyQt5.QtWidgets import QMessageBox
from spectrometer_commands import spectrometer
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
import matplotlib
matplotlib.use('Qt5Agg')
class MplCanvas(FigureCanvasQTAgg):
# noinspection PyUnusedLocal
def __init__(self, parent=None, width=5, height=4, dpi=100):
self.fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = self.fig.add_subplot(111)
super(MplCanvas, self).__init__(self.fig)
class GUI:
def __init__(self):
self.root = spectrometer()
self.avg = 10
self.sec = 0
self.msec = 100
self.brate = 9600
self.mode = "z"
self.spectrum = []
self.app = QtWidgets.QApplication([])
self.call = uic.loadUi("spectrometer1.ui")
self.sc = MplCanvas(self.call.centralwidget, width=5, height=4, dpi=100)
self.call.gridLayout.addWidget(self.sc)
def open(self):
self.call.show()
self.app.exec()
def set_val(self):
self.avg = int(self.call.avg.text())
self.sec = int(self.call.sec.currentText())
self.msec = int(self.call.msec.currentText())
self.brate = int(self.call.baud.currentText())
self.root.set_baud(self.brate)
self.root.set_avg_num(self.avg)
self.root.set_acquisition_time(self.sec * 1000 + self.msec)
if self.call.bin.isChecked():
self.mode = "b"
self.root.spec_mode("b")
print("Binary Mode Selected")
if self.call.ascii.isChecked():
self.mode = "a"
self.root.spec_mode("a")
print("Ascii Mode Selected")
# graph mode
if self.call.single.isChecked():
if self.mode == "b":
self.root.capture_binary()
if self.call.cont.isChecked():
print("continuous Mode Selected")
def start(self):
self.root.spec_init()
self.call.timer = QtCore.QTimer()
if self.call.single.isChecked():
self.update_plot()
else:
self.call.timer.setInterval(100)
self.call.timer.timeout.connect(self.update_plot)
self.call.timer.start()
def stop(self):
self.root.port.close()
def pause(self):
self.call.timer.stop()
def capture(self):
msg = QMessageBox()
msg.setWindowTitle("Capture")
msg.setText("Figure Saved Successfully")
msg.exec_()
self.sc.fig.savefig('/home/devanshu/Desktop/sprctrometer/Figures/figure.png')
self.sc.fig.savefig('/home/devanshu/Desktop/sprctrometer/Figures/figure.pdf')
def update_plot(self):
arr = self.root.capture(self.mode)
self.sc.axes.plot(arr, color='grey')
# sc.axes.set_xlim(left=max(0, i - 10), right=i + 10)
self.sc.fig.canvas.draw()
time.sleep(0.1)
#
ui = GUI()
ui.open()