forked from sehHeiden/uPyCraft_src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Preferences.py
144 lines (111 loc) · 5.07 KB
/
Preferences.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
# -*- coding: utf-8 -*
import serial
import serial.tools.list_ports
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QComboBox, QLabel, QGridLayout, QPushButton, QWidget, QSpacerItem, QTabWidget, QDialog
class SerialWidget(QWidget):
def __init__(self, parent=None):
super(SerialWidget, self).__init__(parent)
serialBaund = QLabel("Baudrate")
self.baundComboBox = QComboBox()
self.baundComboBox.addItems(
['100', '300', '600', '1200', '2400', '4800', '9600', '14400', '19200', '38400', '56000', '57600', '115200',
'128000', '256000'])
self.baundComboBox.setCurrentIndex(12)
serialBytesize = QLabel("Bytesize")
self.bytesizeComboBox = QComboBox()
self.bytesizeComboBox.addItems(['5', '6', '7', '8'])
self.bytesizeComboBox.setCurrentIndex(3)
serialParity = QLabel("Parity")
self.parityComboBox = QComboBox()
self.parityComboBox.addItems(['NONE', 'EVEN', 'ODD', 'MARK', 'SPACE'])
self.parityComboBox.setCurrentIndex(0)
# serialTimeout
serialStopbits = QLabel("Stopbits")
self.stopbitsComboBox = QComboBox()
self.stopbitsComboBox.addItems(['1', '1.5', '2'])
self.stopbitsComboBox.setCurrentIndex(0)
self.okButton = QPushButton(self.tr("Ok"))
self.cancelButton = QPushButton(self.tr("Cancel"))
self.detailWidget = QWidget()
detailLayout = QGridLayout(self.detailWidget)
detailLayout.addWidget(serialBaund, 0, 0)
detailLayout.addWidget(self.baundComboBox, 0, 1)
detailLayout.addWidget(serialBytesize, 1, 0)
detailLayout.addWidget(self.bytesizeComboBox, 1, 1)
detailLayout.addWidget(serialStopbits, 2, 0)
detailLayout.addWidget(self.stopbitsComboBox, 2, 1)
detailLayout.addWidget(serialParity, 3, 0)
detailLayout.addWidget(self.parityComboBox, 3, 1)
# self.detailWidget.hide()
detailLayout.addItem(QSpacerItem(200, 200), 4, 0)
self.setLayout(detailLayout)
self.ser = serial.Serial()
def Port_List(self):
Com_List = []
port_list = list(serial.tools.list_ports.comports())
for port in port_list:
Com_List.append(port[0])
return Com_List
def comChooseOk(self, com):
self.ser.port = com
self.ser.baudrate = self.baundComboBox.currentText()
self.ser.bytesize = int(self.bytesizeComboBox.currentText())
ParityValue = self.parityComboBox.currentText()
self.ser.parity = ParityValue[0]
self.ser.stopbits = int(self.stopbitsComboBox.currentText())
self.ser.timeout = 0.001
self.ser.flow = "N"
self.ser.open()
class LanLocWidget(QWidget):
def __init__(self, parent=None):
super(LanLocWidget, self).__init__(parent)
languageLabel = QLabel(self.tr("Language"))
self.languageComBox = QComboBox()
self.languageComBox.addItems(['English'])
self.languageComBox.setCurrentIndex(0)
locationLabel = QLabel(self.tr("Location"))
self.locationComboBox = QComboBox()
self.locationComboBox.addItems(['China Mainland', 'Others'])
self.locationComboBox.setCurrentIndex(1)
self.detailWidget = QWidget()
detailLayout = QGridLayout(self.detailWidget)
# detailLayout.addWidget(serialPort,0,0)
# detailLayout.addWidget(self.portComboBox,0,1)
detailLayout.addWidget(languageLabel, 0, 0)
detailLayout.addWidget(self.languageComBox, 0, 1)
detailLayout.addWidget(locationLabel, 1, 0)
detailLayout.addWidget(self.locationComboBox, 1, 1)
# self.detailWidget.hide()
detailLayout.addItem(QSpacerItem(200, 200), 2, 0)
self.setLayout(detailLayout)
class updateConfig(QWidget):
def __init__(self, parent=None):
super(updateConfig, self).__init__(parent)
checkFirmware = QLabel(self.tr("Check Firmware"))
self.checkBinComBox = QComboBox()
self.checkBinComBox.addItems(['check update', 'no check'])
self.checkBinComBox.setCurrentIndex(0)
self.detailWidget = QWidget()
detailLayout = QGridLayout(self.detailWidget)
detailLayout.addWidget(checkFirmware, 0, 0)
detailLayout.addWidget(self.checkBinComBox, 0, 1)
detailLayout.addItem(QSpacerItem(200, 200), 1, 0)
self.setLayout(detailLayout)
class Preferences(QDialog):
def __init__(self, parent=None):
super(Preferences, self).__init__(parent)
self.widget = QWidget()
layout = QGridLayout(self.widget)
self.landlocation = LanLocWidget(self)
self.configUpdate = updateConfig()
tabWidget = QTabWidget()
tabWidget.setTabPosition(QTabWidget.West);
tabWidget.addTab(SerialWidget(self), "Serial")
tabWidget.addTab(self.landlocation, "Language Location")
tabWidget.addTab(self.configUpdate, "Config")
layout.addWidget(tabWidget, 1, 0)
self.setLayout(layout)
self.resize(300, 200)
self.setWindowTitle("Preferences")
self.setWindowIcon(QIcon(':/logo.png'))