-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainWindow.py
124 lines (94 loc) · 3.66 KB
/
mainWindow.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
from PyQt5 import QtCore, QtWidgets
from adcWindow import adcWindow
import sys
from port import Port
# 这里我们提供必要的引用。基本控件位于pyqt5.qtwidgets模块中。
from PyQt5.QtWidgets import QApplication, QLabel, QLineEdit, QMessageBox, QWidget, QDesktopWidget, QPushButton, QHBoxLayout, QVBoxLayout, QSizePolicy
from PyQt5.QtGui import QIcon
from settings import Settings
class MainAPP(QWidget):
def __init__(self):
super().__init__()
self.port = Port()
# draw UI
self.initUI()
def initUI(self):
# size and location
# self.setGeometry(500, 500, 500, 500)
self.resize(500, 400)
self.center()
self.setWindowTitle("UART")
self.setWindowIcon(QIcon("./icon/title.ico"))
self.button()
self.show()
def center(self):
window = self.frameGeometry()
# 获取中心点
centerPoint = QDesktopWidget().availableGeometry().center()
window.moveCenter(centerPoint)
# self.move(window.topLeft())
def button(self):
self.spectrum = QPushButton("Spectrum")
self.spectrum.clicked.connect(self.spectrumAction)
# self.spectrum.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
self.colorMap = QPushButton("ColorMap")
self.colorMap.clicked.connect(self.colorMapAction)
# self.colorMap.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
self.adc = QPushButton("ADC")
self.adc.clicked.connect(self.adcAction)
self.statusBox = QLabel()
self.statusBox.setText(self.statusText())
self.statusBox.setAlignment(QtCore.Qt.AlignCenter)
self.connection = QPushButton('连接串口')
self.connection.clicked.connect(self.connect)
self.setting = QPushButton('串口设置')
self.setting.clicked.connect(self.settingAction)
vbox = QVBoxLayout()
vbox.addWidget(self.adc)
vbox.addWidget(self.spectrum)
vbox.addWidget(self.colorMap)
hbox = QHBoxLayout()
# hbox.addStretch(1)
hbox.addLayout(vbox)
vbox2 = QVBoxLayout()
vbox2.addStretch(1)
vbox2.addWidget(self.statusBox)
vbox2.addStretch(1)
vbox2.addWidget(self.connection)
vbox2.addWidget(self.setting)
vbox2.addStretch(1)
hbox.addLayout(vbox2)
# hbox.addStretch(1)
self.setLayout(hbox)
def statusText(self):
status = '当前配置\n波特率 ' + \
str(self.port.bandradte) + '\n停止位 1\nADC数据接收类型 uint8\nADC采样精度 8bit'
return status
def spectrumAction(self):
if self.spectrum.isEnabled():
# print("yes")
self.port.spectrum_one_figure()
# self.spectrum.setEnabled(False)
def colorMapAction(self):
if self.spectrum.isEnabled():
self.port.colormap()
def adcAction(self):
self.ADC_Window = adcWindow(self.port)
self.ADC_Window.show()
# QtWidgets.QFileDialog.getExistingDirectory(self, "@2", "./")
def connect(self):
if(self.port.ser is None or self.port.ser.isOpen() is False):
self.port.openPort()
if(self.port.ser.isOpen()):
QMessageBox.information(self, '提示', '连接成功', QMessageBox.Ok)
def settingAction(self):
# QMessageBox.information(self, '提示', '正在建设', QMessageBox.Ok)
self.settings = Settings(self.port)
self.settings.show()
@staticmethod
def refresh():
QApplication.processEvents()
if __name__ == '__main__':
app = QApplication(sys.argv)
a = MainAPP()
sys.exit(app.exec_())