def __init__(self, parent = None): super(MainWidget, self).__init__(parent) # member variables self._lTheorySpd = 0 self._rTheorySpd = 0 self._serialSend = SerialSend() # mainWindow properties self.setObjectName('MainWidget') self.setWindowIcon(QIcon(':/image/default/app.icon')) self.setWindowTitle('%s V%s' % ( qApp.applicationDisplayName(), qApp.applicationVersion())) self.resize(800, 480) # mainWindow layout # top self.groupBoxTop = QGroupBox(self) self.groupBoxTop.setObjectName('groupBoxTop') # command dashboard buttonLeftPower = JSwitchButton(parent = self.groupBoxTop) buttonRightPower = JSwitchButton(parent = self.groupBoxTop) buttonSettings = QPushButton(self.groupBoxTop) buttonHistory = QPushButton(self.groupBoxTop) buttonQuit = QPushButton(self.groupBoxTop) buttonLeftPower.setObjectName('buttonLeftPower') buttonRightPower.setObjectName('buttonRightPower') buttonSettings.setObjectName('buttonSettings') buttonHistory.setObjectName('buttonHistory') buttonQuit.setObjectName('buttonQuit') areaPortState = QWidget(self) areaPortState.setObjectName('areaPortState') areaPortState.setStyleSheet('QWidget#areaPortState{border-radius:3px;' 'border:1px solid #505050;' 'background-color:rgba(64,64,64,50);}') vertLayoutPortState = QVBoxLayout(areaPortState) vertLayoutPortState.setContentsMargins(50, 2, 50, 2) vertLayoutPortState.setSpacing(3) buttonPortState = JSwitchButton(pixmap = QPixmap(':/carmonitor/image/button-port-state.png'), parent = areaPortState) buttonPortState.setObjectName('buttonPortState') vertLayoutPortState.addWidget(QLabel('串口', areaPortState), 0, Qt.AlignHCenter) vertLayoutPortState.addWidget(buttonPortState) # horiLayoutTop = QHBoxLayout(self.groupBoxTop) horiLayoutTop.setContentsMargins(0, 0, 0, 0) horiLayoutTop.addSpacing(25) horiLayoutTop.addWidget(buttonSettings, 0, Qt.AlignLeft) horiLayoutTop.addSpacing(20) horiLayoutTop.addWidget(buttonHistory, 0, Qt.AlignLeft) horiLayoutTop.addSpacing(65) horiLayoutTop.addWidget(buttonLeftPower) horiLayoutTop.addWidget(QLabel('左电源开关', self.groupBoxTop)) horiLayoutTop.addStretch() horiLayoutTop.addWidget(areaPortState, 0, Qt.AlignTop) horiLayoutTop.addStretch() horiLayoutTop.addWidget(QLabel('右电源开关', self.groupBoxTop)) horiLayoutTop.addWidget(buttonRightPower) horiLayoutTop.addSpacing(150) horiLayoutTop.addWidget(buttonQuit, 0, Qt.AlignRight) horiLayoutTop.addSpacing(25) # middle # curves self.curveLBP = CurveWidget(title = '左刹车压力(MPa)', parent = self) self.curveLRP = CurveWidget(title = '左转速(r/min)', parent = self) self.curveRBP = CurveWidget(title = '右刹车压力(MPa)', parent = self) self.curveRRP = CurveWidget(title = '右转速(r/min)', parent = self) self.curveLBP.setObjectName('curveLBP') self.curveLRP.setObjectName('curveLRP') self.curveRBP.setObjectName('curveRBP') self.curveRRP.setObjectName('curveRRP') # self.curveLBP.setAxisScale(QwtPlot.yLeft, 0, 30, 5) # areaMiddle self.areaMiddle = QWidget(self) self.areaMiddle.setObjectName('areaMiddle') self.areaMiddle.setFixedWidth(280) # groupBoxStatus = QGroupBox(self) groupBoxStatus.setObjectName('groupBoxStatus') # status-view gridLayoutStatus = QGridLayout(groupBoxStatus) gridLayoutStatus.setContentsMargins(5, 5, 5, 5) gridLayoutStatus.setHorizontalSpacing(8) gridLayoutStatus.setVerticalSpacing(3) # Brake-Command editLeftBrakeCmd = QLineEdit(groupBoxStatus) editRightBrakeCmd = QLineEdit(groupBoxStatus) editLeftBrakeCmd.setObjectName('editLeftBrakeCmd') editRightBrakeCmd.setObjectName('editRightBrakeCmd') editLeftBrakeCmd.setReadOnly(True) editRightBrakeCmd.setReadOnly(True) gridLayoutStatus.addWidget(QLabel('刹车指令:', groupBoxStatus), 0, 0, 1, 2, Qt.AlignCenter) gridLayoutStatus.addWidget(editLeftBrakeCmd, 1, 0, 1, 1) gridLayoutStatus.addWidget(editRightBrakeCmd, 1, 1, 1, 1) # Major Brake Pressure self.editMLeftBrakeP = QLineEdit(groupBoxStatus) self.editMRightBrakeP = QLineEdit(groupBoxStatus) self.editMLeftBrakeP.setObjectName('editMLeftBrakeP') self.editMRightBrakeP.setObjectName('editMRightBrakeP') self.editMLeftBrakeP.setReadOnly(True) self.editMRightBrakeP.setReadOnly(True) gridLayoutStatus.addWidget(QLabel('主刹车压力:', groupBoxStatus), 2, 0, 1, 2, Qt.AlignCenter) gridLayoutStatus.addWidget(self.editMLeftBrakeP, 3, 0, 1, 1) gridLayoutStatus.addWidget(self.editMRightBrakeP, 3, 1, 1, 1) # Assistant Brake Pressure self.editALeftBrakeP = QLineEdit(groupBoxStatus) self.editARightBrakeP = QLineEdit(groupBoxStatus) self.editALeftBrakeP.setObjectName('editALeftBrakeP') self.editARightBrakeP.setObjectName('editARightBrakeP') self.editALeftBrakeP.setReadOnly(True) self.editARightBrakeP.setReadOnly(True) gridLayoutStatus.addWidget(QLabel('副刹车压力:', groupBoxStatus), 4, 0, 1, 2, Qt.AlignCenter) gridLayoutStatus.addWidget(self.editALeftBrakeP, 5, 0, 1, 1) gridLayoutStatus.addWidget(self.editARightBrakeP, 5, 1, 1, 1) # Rotation Rate self.editLeftRotateRate = QLineEdit(groupBoxStatus) self.editRightRotateRate = QLineEdit(groupBoxStatus) self.editLeftRotateRate.setObjectName('editLeftRotateRate') self.editRightRotateRate.setObjectName('editRightRotateRate') gridLayoutStatus.addWidget(QLabel('实际转速:', groupBoxStatus), 6, 0, 1, 2, Qt.AlignCenter) gridLayoutStatus.addWidget(self.editLeftRotateRate, 7, 0, 1, 1) gridLayoutStatus.addWidget(self.editRightRotateRate, 7, 1, 1, 1) # Theory Rotation Rate self.editTheoryLeftRotateRate = QLineEdit(groupBoxStatus) self.editTheoryRightRotateRate = QLineEdit(groupBoxStatus) self.editTheoryLeftRotateRate.setObjectName('editTheoryLeftRotateRate') self.editTheoryRightRotateRate.setObjectName('editTheoryRightRotateRate') gridLayoutStatus.addWidget(QLabel('理论转速:', groupBoxStatus), 8, 0, 1, 2, Qt.AlignCenter) gridLayoutStatus.addWidget(self.editTheoryLeftRotateRate, 9, 0, 1, 1) gridLayoutStatus.addWidget(self.editTheoryRightRotateRate, 9, 1, 1, 1) # groupBoxCtrl = QGroupBox(self) groupBoxCtrl.setObjectName('groupBoxCtrl') # status-view gridLayoutCtrl = QGridLayout(groupBoxCtrl) gridLayoutCtrl.setContentsMargins(5, 5, 5, 5) gridLayoutCtrl.setSpacing(20) # left-button buttonLeftDashboard = JDashButton('左指令旋钮', groupBoxCtrl) buttonLeftSpeedGain = JDashButton('左转速增益', groupBoxCtrl) buttonLeftSpeedKnob = JDashButton('左转速增益', groupBoxCtrl) buttonLeftTracksip = JTracksipButton(parent = groupBoxCtrl) buttonLeftDashboard.setObjectName('buttonLeftDashboard') buttonLeftSpeedGain.setObjectName('buttonLeftSpeedGain') buttonLeftSpeedKnob.setObjectName('buttonLeftSpeedKnob') buttonLeftTracksip.setObjectName('buttonLeftTracksip') buttonLeftTracksip.setFixedSize(110, 45) # right-button buttonRightDashboard = JDashButton('右指令旋钮', groupBoxCtrl) buttonRightSpeedGain = JDashButton('右转速增益', groupBoxCtrl) buttonRightSpeedKnob = JDashButton('右转速增益', groupBoxCtrl) buttonRightTracksip = JTracksipButton(parent = groupBoxCtrl) buttonRightDashboard.setObjectName('buttonRightDashboard') buttonRightSpeedGain.setObjectName('buttonRightSpeedGain') buttonRightSpeedKnob.setObjectName('buttonRightSpeedKnob') buttonRightTracksip.setObjectName('buttonRightTracksip') buttonRightTracksip.setFixedSize(110, 45) horiLayoutTracksip = QHBoxLayout() horiLayoutTracksip.setContentsMargins(0, 0, 0, 0) horiLayoutTracksip.setSpacing(5) horiLayoutTracksip.addWidget(buttonLeftTracksip) horiLayoutTracksip.addWidget(QLabel('打滑', self), 0, Qt.AlignHCenter) horiLayoutTracksip.addWidget(buttonRightTracksip) gridLayoutCtrl.addLayout(horiLayoutTracksip, 0, 0, 1, 2) horiLayoutDashboard = QHBoxLayout() horiLayoutDashboard.setContentsMargins(0, 0, 0, 0) horiLayoutDashboard.setSpacing(5) horiLayoutDashboard.addWidget(buttonLeftDashboard) horiLayoutDashboard.addWidget(QLabel(' ', self), 0, Qt.AlignHCenter) horiLayoutDashboard.addWidget(buttonRightDashboard) gridLayoutCtrl.addLayout(horiLayoutDashboard, 1, 0, 1, 2) horiLayoutSpeedGain = QHBoxLayout() horiLayoutSpeedGain.setContentsMargins(0, 0, 0, 0) horiLayoutSpeedGain.setSpacing(5) horiLayoutSpeedGain.addWidget(buttonLeftSpeedGain) horiLayoutSpeedGain.addWidget(QLabel('(粗调)', self), 0, Qt.AlignHCenter) horiLayoutSpeedGain.addWidget(buttonRightSpeedGain) gridLayoutCtrl.addLayout(horiLayoutSpeedGain, 2, 0, 1, 2) horiLayoutSpeedKnob = QHBoxLayout() horiLayoutSpeedKnob.setContentsMargins(0, 0, 0, 0) horiLayoutSpeedKnob.setSpacing(5) horiLayoutSpeedKnob.addWidget(buttonLeftSpeedKnob) horiLayoutSpeedKnob.addWidget(QLabel('(细调)', self), 0, Qt.AlignHCenter) horiLayoutSpeedKnob.addWidget(buttonRightSpeedKnob) gridLayoutCtrl.addLayout(horiLayoutSpeedKnob, 3, 0, 1, 2) # vertLayoutMid = QVBoxLayout(self.areaMiddle) vertLayoutMid.setContentsMargins(0, 0, 0, 0) vertLayoutMid.setSpacing(0) vertLayoutMid.addWidget(groupBoxStatus) vertLayoutMid.addWidget(groupBoxCtrl) vertLayoutMid.addSpacing(20) # gridLayoutBottom = QGridLayout() gridLayoutBottom.setContentsMargins(0, 0, 0, 0) gridLayoutBottom.setSpacing(1) gridLayoutBottom.addWidget(self.curveLBP, 0, 0, 1, 1) gridLayoutBottom.addWidget(self.curveLRP, 1, 0, 1, 1) gridLayoutBottom.addWidget(self.areaMiddle, 0, 1, 2, 1) gridLayoutBottom.addWidget(self.curveRBP, 0, 2, 1, 1) gridLayoutBottom.addWidget(self.curveRRP, 1, 2, 1, 1) # main-layout vertLayoutMain = QVBoxLayout(self) vertLayoutMain.setContentsMargins(5, 5, 5, 5) vertLayoutMain.addWidget(self.groupBoxTop) vertLayoutMain.addLayout(gridLayoutBottom) # global properties qApp.setProperty('MainWidget', self) self._serialProxy = SerialPortProxy(self) self._serialProxy._serialSimulate = SerialSimulate(self._serialProxy) # qApp.setProperty('SerialProxy', self._serialProxy) # buttonSettings.clicked.connect(self.onButtonSettingsClicked) buttonHistory.clicked.connect(self.onButtonHistoryClicked) buttonPortState.clicked.connect(self.onButtonPortStateClicked) buttonQuit.clicked.connect(self.onButtonQuitClicked) # curves self.curveLBP.doubleClicked.connect(self.onCurveDoubleClicked) self.curveLRP.doubleClicked.connect(self.onCurveDoubleClicked) self.curveRBP.doubleClicked.connect(self.onCurveDoubleClicked) self.curveRRP.doubleClicked.connect(self.onCurveDoubleClicked) # switch-power buttonLeftPower.stateChanged.connect(self.onButtonLeftPowerStateChanged) buttonRightPower.stateChanged.connect(self.onButtonRightPowerStateChanged) # switch-tracksip buttonLeftTracksip.stateChanged.connect(self.onButtonLeftTracksipStateChanged) buttonRightTracksip.stateChanged.connect(self.onButtonRightTracksipStateChanged) self._serialProxy.stateChanged.connect(self.onSerialStateChanged) self._serialProxy.serialPortError.connect(self.onSerialPortError) self._serialProxy.displayRespond.connect(self.onSerialDisplayRespond) # buttonLeftSpeedGain.clicked.connect(self.execSliderWidget) buttonLeftSpeedKnob.clicked.connect(self.execSliderWidget) buttonRightSpeedGain.clicked.connect(self.execSliderWidget) buttonRightSpeedKnob.clicked.connect(self.execSliderWidget) # final initialization self.editMLeftBrakeP.setText('0 MPa') self.editMRightBrakeP.setText('0 MPa') self.editALeftBrakeP.setText('0 MPa') self.editARightBrakeP.setText('0 MPa') self.editLeftRotateRate.setText('0 r/min') self.editRightRotateRate.setText('0 r/min') self.editTheoryLeftRotateRate.setText('0 r/min') self.editTheoryRightRotateRate.setText('0 r/min') # c_memset(self._serialSend, 0, ctypes.sizeof(self._serialSend)) # SQL sqlName = applicationDirPath() \ + '/../data/cm-' \ + QDateTime.currentDateTime().toLocalTime().toString('yyyy-MM-dd-HH-mm-ss') \ + '.db' if not DatabaseMgr().create(sqlName): assert(False) # start serialport self._serialProxy.start() # buttonLeftTracksip.setState(self._serialSend.ctrlWord.lTracksip) buttonRightTracksip.setState(self._serialSend.ctrlWord.lTracksip)
def __init__(self, parent=None): super(HistoryWidget, self).__init__(parent) self.setObjectName("HistoryWidget") self.resize(800, 480) self.setWindowTitle("历史数据查看") # layout - top horiLayoutTop = QHBoxLayout() buttonQuit = QPushButton(self) buttonQuit.setObjectName("buttonQuit") horiLayoutTop.addSpacing(25) horiLayoutTop.addWidget(buttonQuit, 0, Qt.AlignLeft) horiLayoutTop.addStretch() # button-export buttonExport = QPushButton(self) buttonExport.setObjectName("buttonExport") horiLayoutTop.addWidget(buttonExport) horiLayoutTop.addStretch() # button-open buttonOpen = QPushButton(self) buttonOpen.setObjectName("buttonOpen") horiLayoutTop.addWidget(buttonOpen) horiLayoutTop.addStretch() formLayoutTime = QFormLayout() formLayoutTime.setFormAlignment(Qt.AlignVCenter) horiLayoutTop.addLayout(formLayoutTime) horiLayoutTop.addStretch() self.dateTimeEditStart = QDateTimeEdit(self) self.dateTimeEditStart.setObjectName("dateTimeEditStart") self.dateTimeEditStart.setDisplayFormat("yyyy-MM-dd HH:mm:ss") formLayoutTime.addRow("起始时间:", self.dateTimeEditStart) self.dateTimeEditEnd = QDateTimeEdit(self) self.dateTimeEditEnd.setObjectName("dateTimeEditEnd") self.dateTimeEditEnd.setDisplayFormat("yyyy-MM-dd HH:mm:ss") formLayoutTime.addRow("结束时间:", self.dateTimeEditEnd) # LBP formLayoutLBP = QFormLayout() formLayoutLBP.setFormAlignment(Qt.AlignVCenter) formLayoutLBP.setLabelAlignment(Qt.AlignRight) horiLayoutTop.addLayout(formLayoutLBP) horiLayoutTop.addStretch() self.checkBoxLBPMajor = QCheckBox("主", self) self.checkBoxLBPMajor.setProperty("curveColor", "#101010") self.checkBoxLBPMinor = QCheckBox("副", self) self.checkBoxLBPMinor.setProperty("curveColor", "#101010") formLayoutLBP.addRow("左刹车压力:", self.checkBoxLBPMajor) formLayoutLBP.addRow("", self.checkBoxLBPMinor) # RBP formLayoutRBP = QFormLayout() formLayoutRBP.setFormAlignment(Qt.AlignVCenter) formLayoutRBP.setLabelAlignment(Qt.AlignRight) horiLayoutTop.addLayout(formLayoutRBP) horiLayoutTop.addStretch() self.checkBoxRBPMajor = QCheckBox("主", self) self.checkBoxRBPMajor.setProperty("curveColor", "#101010") self.checkBoxRBPMinor = QCheckBox("副", self) self.checkBoxRBPMinor.setProperty("curveColor", "#101010") formLayoutRBP.addRow("右刹车压力:", self.checkBoxRBPMajor) formLayoutRBP.addRow("", self.checkBoxRBPMinor) # LRP formLayoutLRP = QFormLayout() formLayoutLRP.setFormAlignment(Qt.AlignVCenter) formLayoutLRP.setLabelAlignment(Qt.AlignRight) horiLayoutTop.addLayout(formLayoutLRP) horiLayoutTop.addStretch() self.checkBoxLRPTheory = QCheckBox("理论", self) self.checkBoxLRPTheory.setProperty("curveColor", "#101010") self.checkBoxLRPReal = QCheckBox("实际", self) self.checkBoxLRPReal.setProperty("curveColor", "#101010") formLayoutLRP.addRow("左转速:", self.checkBoxLRPTheory) formLayoutLRP.addRow("", self.checkBoxLRPReal) # RRP formLayoutRRP = QFormLayout() formLayoutRRP.setFormAlignment(Qt.AlignVCenter) formLayoutRRP.setLabelAlignment(Qt.AlignRight) horiLayoutTop.addLayout(formLayoutRRP) horiLayoutTop.addStretch() self.checkBoxRRPTheory = QCheckBox("理论", self) self.checkBoxRRPTheory.setProperty("curveColor", "#101010") self.checkBoxRRPReal = QCheckBox("实际", self) self.checkBoxRRPReal.setProperty("curveColor", "#101010") formLayoutRRP.addRow("右转速:", self.checkBoxRRPTheory) formLayoutRRP.addRow("", self.checkBoxRRPReal) # button-update buttonUpdate = QPushButton(self) buttonUpdate.setObjectName("buttonUpdate") horiLayoutTop.addWidget(buttonUpdate) horiLayoutTop.addStretch() # middle-curves self.curveHistory = CurveWidget("历史数据回放", True, self) self.curveHistory.setMaximumWidth(10e5) self.curveHistory.setScaleLabelFormat("yyyy/MM/dd\n HH:mm:ss") self.curveHistory.clear() # vertLayoutMain = QVBoxLayout(self) vertLayoutMain.addLayout(horiLayoutTop) vertLayoutMain.addWidget(self.curveHistory) buttonQuit.clicked.connect(self.accept) buttonOpen.clicked.connect(self.buttonOpenClicked) buttonExport.clicked.connect(self.buttonExportClicked) self.dateTimeEditStart.dateTimeChanged.connect(self.dateTimeStartChanged) self.dateTimeEditEnd.dateTimeChanged.connect(self.dateTimeEndChanged) self.checkBoxLBPMajor.toggled.connect(self.checkBoxLBPMajorToggled) self.checkBoxLBPMinor.toggled.connect(self.checkBoxLBPMinorToggled) self.checkBoxRBPMajor.toggled.connect(self.checkBoxRBPMajorToggled) self.checkBoxRBPMinor.toggled.connect(self.checkBoxRBPMinorToggled) self.checkBoxLRPTheory.toggled.connect(self.checkBoxLRPTheoryToggled) self.checkBoxLRPReal.toggled.connect(self.checkBoxLRPRealToggled) self.checkBoxRRPTheory.toggled.connect(self.checkBoxRRPTheoryToggled) self.checkBoxRRPReal.toggled.connect(self.checkBoxRRPRealToggled) buttonUpdate.clicked.connect(self.buttonUpdateClicked) # finalLy initialize self.checkBoxLBPMajor.setChecked(self._v_curve_checked[0]) self.checkBoxLBPMinor.setChecked(self._v_curve_checked[1]) self.checkBoxRBPMajor.setChecked(self._v_curve_checked[2]) self.checkBoxRBPMinor.setChecked(self._v_curve_checked[3]) self.checkBoxLRPTheory.setChecked(self._v_curve_checked[4]) self.checkBoxLRPReal.setChecked(self._v_curve_checked[5]) self.checkBoxRRPTheory.setChecked(self._v_curve_checked[6]) self.checkBoxRRPReal.setChecked(self._v_curve_checked[7])
class MainWidget(QWidget): ''' class MainWidget ''' def __init__(self, parent = None): super(MainWidget, self).__init__(parent) # member variables self._lTheorySpd = 0 self._rTheorySpd = 0 self._serialSend = SerialSend() # mainWindow properties self.setObjectName('MainWidget') self.setWindowIcon(QIcon(':/image/default/app.icon')) self.setWindowTitle('%s V%s' % ( qApp.applicationDisplayName(), qApp.applicationVersion())) self.resize(800, 480) # mainWindow layout # top self.groupBoxTop = QGroupBox(self) self.groupBoxTop.setObjectName('groupBoxTop') # command dashboard buttonLeftPower = JSwitchButton(parent = self.groupBoxTop) buttonRightPower = JSwitchButton(parent = self.groupBoxTop) buttonSettings = QPushButton(self.groupBoxTop) buttonHistory = QPushButton(self.groupBoxTop) buttonQuit = QPushButton(self.groupBoxTop) buttonLeftPower.setObjectName('buttonLeftPower') buttonRightPower.setObjectName('buttonRightPower') buttonSettings.setObjectName('buttonSettings') buttonHistory.setObjectName('buttonHistory') buttonQuit.setObjectName('buttonQuit') areaPortState = QWidget(self) areaPortState.setObjectName('areaPortState') areaPortState.setStyleSheet('QWidget#areaPortState{border-radius:3px;' 'border:1px solid #505050;' 'background-color:rgba(64,64,64,50);}') vertLayoutPortState = QVBoxLayout(areaPortState) vertLayoutPortState.setContentsMargins(50, 2, 50, 2) vertLayoutPortState.setSpacing(3) buttonPortState = JSwitchButton(pixmap = QPixmap(':/carmonitor/image/button-port-state.png'), parent = areaPortState) buttonPortState.setObjectName('buttonPortState') vertLayoutPortState.addWidget(QLabel('串口', areaPortState), 0, Qt.AlignHCenter) vertLayoutPortState.addWidget(buttonPortState) # horiLayoutTop = QHBoxLayout(self.groupBoxTop) horiLayoutTop.setContentsMargins(0, 0, 0, 0) horiLayoutTop.addSpacing(25) horiLayoutTop.addWidget(buttonSettings, 0, Qt.AlignLeft) horiLayoutTop.addSpacing(20) horiLayoutTop.addWidget(buttonHistory, 0, Qt.AlignLeft) horiLayoutTop.addSpacing(65) horiLayoutTop.addWidget(buttonLeftPower) horiLayoutTop.addWidget(QLabel('左电源开关', self.groupBoxTop)) horiLayoutTop.addStretch() horiLayoutTop.addWidget(areaPortState, 0, Qt.AlignTop) horiLayoutTop.addStretch() horiLayoutTop.addWidget(QLabel('右电源开关', self.groupBoxTop)) horiLayoutTop.addWidget(buttonRightPower) horiLayoutTop.addSpacing(150) horiLayoutTop.addWidget(buttonQuit, 0, Qt.AlignRight) horiLayoutTop.addSpacing(25) # middle # curves self.curveLBP = CurveWidget(title = '左刹车压力(MPa)', parent = self) self.curveLRP = CurveWidget(title = '左转速(r/min)', parent = self) self.curveRBP = CurveWidget(title = '右刹车压力(MPa)', parent = self) self.curveRRP = CurveWidget(title = '右转速(r/min)', parent = self) self.curveLBP.setObjectName('curveLBP') self.curveLRP.setObjectName('curveLRP') self.curveRBP.setObjectName('curveRBP') self.curveRRP.setObjectName('curveRRP') # self.curveLBP.setAxisScale(QwtPlot.yLeft, 0, 30, 5) # areaMiddle self.areaMiddle = QWidget(self) self.areaMiddle.setObjectName('areaMiddle') self.areaMiddle.setFixedWidth(280) # groupBoxStatus = QGroupBox(self) groupBoxStatus.setObjectName('groupBoxStatus') # status-view gridLayoutStatus = QGridLayout(groupBoxStatus) gridLayoutStatus.setContentsMargins(5, 5, 5, 5) gridLayoutStatus.setHorizontalSpacing(8) gridLayoutStatus.setVerticalSpacing(3) # Brake-Command editLeftBrakeCmd = QLineEdit(groupBoxStatus) editRightBrakeCmd = QLineEdit(groupBoxStatus) editLeftBrakeCmd.setObjectName('editLeftBrakeCmd') editRightBrakeCmd.setObjectName('editRightBrakeCmd') editLeftBrakeCmd.setReadOnly(True) editRightBrakeCmd.setReadOnly(True) gridLayoutStatus.addWidget(QLabel('刹车指令:', groupBoxStatus), 0, 0, 1, 2, Qt.AlignCenter) gridLayoutStatus.addWidget(editLeftBrakeCmd, 1, 0, 1, 1) gridLayoutStatus.addWidget(editRightBrakeCmd, 1, 1, 1, 1) # Major Brake Pressure self.editMLeftBrakeP = QLineEdit(groupBoxStatus) self.editMRightBrakeP = QLineEdit(groupBoxStatus) self.editMLeftBrakeP.setObjectName('editMLeftBrakeP') self.editMRightBrakeP.setObjectName('editMRightBrakeP') self.editMLeftBrakeP.setReadOnly(True) self.editMRightBrakeP.setReadOnly(True) gridLayoutStatus.addWidget(QLabel('主刹车压力:', groupBoxStatus), 2, 0, 1, 2, Qt.AlignCenter) gridLayoutStatus.addWidget(self.editMLeftBrakeP, 3, 0, 1, 1) gridLayoutStatus.addWidget(self.editMRightBrakeP, 3, 1, 1, 1) # Assistant Brake Pressure self.editALeftBrakeP = QLineEdit(groupBoxStatus) self.editARightBrakeP = QLineEdit(groupBoxStatus) self.editALeftBrakeP.setObjectName('editALeftBrakeP') self.editARightBrakeP.setObjectName('editARightBrakeP') self.editALeftBrakeP.setReadOnly(True) self.editARightBrakeP.setReadOnly(True) gridLayoutStatus.addWidget(QLabel('副刹车压力:', groupBoxStatus), 4, 0, 1, 2, Qt.AlignCenter) gridLayoutStatus.addWidget(self.editALeftBrakeP, 5, 0, 1, 1) gridLayoutStatus.addWidget(self.editARightBrakeP, 5, 1, 1, 1) # Rotation Rate self.editLeftRotateRate = QLineEdit(groupBoxStatus) self.editRightRotateRate = QLineEdit(groupBoxStatus) self.editLeftRotateRate.setObjectName('editLeftRotateRate') self.editRightRotateRate.setObjectName('editRightRotateRate') gridLayoutStatus.addWidget(QLabel('实际转速:', groupBoxStatus), 6, 0, 1, 2, Qt.AlignCenter) gridLayoutStatus.addWidget(self.editLeftRotateRate, 7, 0, 1, 1) gridLayoutStatus.addWidget(self.editRightRotateRate, 7, 1, 1, 1) # Theory Rotation Rate self.editTheoryLeftRotateRate = QLineEdit(groupBoxStatus) self.editTheoryRightRotateRate = QLineEdit(groupBoxStatus) self.editTheoryLeftRotateRate.setObjectName('editTheoryLeftRotateRate') self.editTheoryRightRotateRate.setObjectName('editTheoryRightRotateRate') gridLayoutStatus.addWidget(QLabel('理论转速:', groupBoxStatus), 8, 0, 1, 2, Qt.AlignCenter) gridLayoutStatus.addWidget(self.editTheoryLeftRotateRate, 9, 0, 1, 1) gridLayoutStatus.addWidget(self.editTheoryRightRotateRate, 9, 1, 1, 1) # groupBoxCtrl = QGroupBox(self) groupBoxCtrl.setObjectName('groupBoxCtrl') # status-view gridLayoutCtrl = QGridLayout(groupBoxCtrl) gridLayoutCtrl.setContentsMargins(5, 5, 5, 5) gridLayoutCtrl.setSpacing(20) # left-button buttonLeftDashboard = JDashButton('左指令旋钮', groupBoxCtrl) buttonLeftSpeedGain = JDashButton('左转速增益', groupBoxCtrl) buttonLeftSpeedKnob = JDashButton('左转速增益', groupBoxCtrl) buttonLeftTracksip = JTracksipButton(parent = groupBoxCtrl) buttonLeftDashboard.setObjectName('buttonLeftDashboard') buttonLeftSpeedGain.setObjectName('buttonLeftSpeedGain') buttonLeftSpeedKnob.setObjectName('buttonLeftSpeedKnob') buttonLeftTracksip.setObjectName('buttonLeftTracksip') buttonLeftTracksip.setFixedSize(110, 45) # right-button buttonRightDashboard = JDashButton('右指令旋钮', groupBoxCtrl) buttonRightSpeedGain = JDashButton('右转速增益', groupBoxCtrl) buttonRightSpeedKnob = JDashButton('右转速增益', groupBoxCtrl) buttonRightTracksip = JTracksipButton(parent = groupBoxCtrl) buttonRightDashboard.setObjectName('buttonRightDashboard') buttonRightSpeedGain.setObjectName('buttonRightSpeedGain') buttonRightSpeedKnob.setObjectName('buttonRightSpeedKnob') buttonRightTracksip.setObjectName('buttonRightTracksip') buttonRightTracksip.setFixedSize(110, 45) horiLayoutTracksip = QHBoxLayout() horiLayoutTracksip.setContentsMargins(0, 0, 0, 0) horiLayoutTracksip.setSpacing(5) horiLayoutTracksip.addWidget(buttonLeftTracksip) horiLayoutTracksip.addWidget(QLabel('打滑', self), 0, Qt.AlignHCenter) horiLayoutTracksip.addWidget(buttonRightTracksip) gridLayoutCtrl.addLayout(horiLayoutTracksip, 0, 0, 1, 2) horiLayoutDashboard = QHBoxLayout() horiLayoutDashboard.setContentsMargins(0, 0, 0, 0) horiLayoutDashboard.setSpacing(5) horiLayoutDashboard.addWidget(buttonLeftDashboard) horiLayoutDashboard.addWidget(QLabel(' ', self), 0, Qt.AlignHCenter) horiLayoutDashboard.addWidget(buttonRightDashboard) gridLayoutCtrl.addLayout(horiLayoutDashboard, 1, 0, 1, 2) horiLayoutSpeedGain = QHBoxLayout() horiLayoutSpeedGain.setContentsMargins(0, 0, 0, 0) horiLayoutSpeedGain.setSpacing(5) horiLayoutSpeedGain.addWidget(buttonLeftSpeedGain) horiLayoutSpeedGain.addWidget(QLabel('(粗调)', self), 0, Qt.AlignHCenter) horiLayoutSpeedGain.addWidget(buttonRightSpeedGain) gridLayoutCtrl.addLayout(horiLayoutSpeedGain, 2, 0, 1, 2) horiLayoutSpeedKnob = QHBoxLayout() horiLayoutSpeedKnob.setContentsMargins(0, 0, 0, 0) horiLayoutSpeedKnob.setSpacing(5) horiLayoutSpeedKnob.addWidget(buttonLeftSpeedKnob) horiLayoutSpeedKnob.addWidget(QLabel('(细调)', self), 0, Qt.AlignHCenter) horiLayoutSpeedKnob.addWidget(buttonRightSpeedKnob) gridLayoutCtrl.addLayout(horiLayoutSpeedKnob, 3, 0, 1, 2) # vertLayoutMid = QVBoxLayout(self.areaMiddle) vertLayoutMid.setContentsMargins(0, 0, 0, 0) vertLayoutMid.setSpacing(0) vertLayoutMid.addWidget(groupBoxStatus) vertLayoutMid.addWidget(groupBoxCtrl) vertLayoutMid.addSpacing(20) # gridLayoutBottom = QGridLayout() gridLayoutBottom.setContentsMargins(0, 0, 0, 0) gridLayoutBottom.setSpacing(1) gridLayoutBottom.addWidget(self.curveLBP, 0, 0, 1, 1) gridLayoutBottom.addWidget(self.curveLRP, 1, 0, 1, 1) gridLayoutBottom.addWidget(self.areaMiddle, 0, 1, 2, 1) gridLayoutBottom.addWidget(self.curveRBP, 0, 2, 1, 1) gridLayoutBottom.addWidget(self.curveRRP, 1, 2, 1, 1) # main-layout vertLayoutMain = QVBoxLayout(self) vertLayoutMain.setContentsMargins(5, 5, 5, 5) vertLayoutMain.addWidget(self.groupBoxTop) vertLayoutMain.addLayout(gridLayoutBottom) # global properties qApp.setProperty('MainWidget', self) self._serialProxy = SerialPortProxy(self) self._serialProxy._serialSimulate = SerialSimulate(self._serialProxy) # qApp.setProperty('SerialProxy', self._serialProxy) # buttonSettings.clicked.connect(self.onButtonSettingsClicked) buttonHistory.clicked.connect(self.onButtonHistoryClicked) buttonPortState.clicked.connect(self.onButtonPortStateClicked) buttonQuit.clicked.connect(self.onButtonQuitClicked) # curves self.curveLBP.doubleClicked.connect(self.onCurveDoubleClicked) self.curveLRP.doubleClicked.connect(self.onCurveDoubleClicked) self.curveRBP.doubleClicked.connect(self.onCurveDoubleClicked) self.curveRRP.doubleClicked.connect(self.onCurveDoubleClicked) # switch-power buttonLeftPower.stateChanged.connect(self.onButtonLeftPowerStateChanged) buttonRightPower.stateChanged.connect(self.onButtonRightPowerStateChanged) # switch-tracksip buttonLeftTracksip.stateChanged.connect(self.onButtonLeftTracksipStateChanged) buttonRightTracksip.stateChanged.connect(self.onButtonRightTracksipStateChanged) self._serialProxy.stateChanged.connect(self.onSerialStateChanged) self._serialProxy.serialPortError.connect(self.onSerialPortError) self._serialProxy.displayRespond.connect(self.onSerialDisplayRespond) # buttonLeftSpeedGain.clicked.connect(self.execSliderWidget) buttonLeftSpeedKnob.clicked.connect(self.execSliderWidget) buttonRightSpeedGain.clicked.connect(self.execSliderWidget) buttonRightSpeedKnob.clicked.connect(self.execSliderWidget) # final initialization self.editMLeftBrakeP.setText('0 MPa') self.editMRightBrakeP.setText('0 MPa') self.editALeftBrakeP.setText('0 MPa') self.editARightBrakeP.setText('0 MPa') self.editLeftRotateRate.setText('0 r/min') self.editRightRotateRate.setText('0 r/min') self.editTheoryLeftRotateRate.setText('0 r/min') self.editTheoryRightRotateRate.setText('0 r/min') # c_memset(self._serialSend, 0, ctypes.sizeof(self._serialSend)) # SQL sqlName = applicationDirPath() \ + '/../data/cm-' \ + QDateTime.currentDateTime().toLocalTime().toString('yyyy-MM-dd-HH-mm-ss') \ + '.db' if not DatabaseMgr().create(sqlName): assert(False) # start serialport self._serialProxy.start() # buttonLeftTracksip.setState(self._serialSend.ctrlWord.lTracksip) buttonRightTracksip.setState(self._serialSend.ctrlWord.lTracksip) def onButtonSettingsClicked(self): self._serialProxy.save() # settingsWidget = SettingsWidget(self) settingsWidget.exec_() self._serialProxy.restore() def onButtonHistoryClicked(self): self._serialProxy.save() DatabaseMgr().save() # historyWidget = HistoryWidget(self) historyWidget.showMaximized() historyWidget.exec_() DatabaseMgr().restore() self._serialProxy.restore() def onButtonPortStateClicked(self, checked): if checked: self._serialProxy.start() else: self._serialProxy.stop() def onButtonQuitClicked(self): if QMessageBox.warning(self, '警告', '你确定要退出软件吗?', QMessageBox.Ok | QMessageBox.No) == QMessageBox.Ok: self.close() def onCurveDoubleClicked(self, checked): objectName = self.sender().objectName() if objectName == 'curveLBP': self.groupBoxTop.setVisible(checked) self.areaMiddle.setVisible(checked) self.curveLRP.setVisible(checked) self.curveRBP.setVisible(checked) self.curveRRP.setVisible(checked) elif objectName == 'curveLRP': self.groupBoxTop.setVisible(checked) self.areaMiddle.setVisible(checked) self.curveLBP.setVisible(checked) self.curveRBP.setVisible(checked) self.curveRRP.setVisible(checked) elif objectName == 'curveRBP': self.groupBoxTop.setVisible(checked) self.areaMiddle.setVisible(checked) self.curveLBP.setVisible(checked) self.curveLRP.setVisible(checked) self.curveRRP.setVisible(checked) elif objectName == 'curveRRP': self.groupBoxTop.setVisible(checked) self.areaMiddle.setVisible(checked) self.curveLBP.setVisible(checked) self.curveLRP.setVisible(checked) self.curveRBP.setVisible(checked) def onButtonLeftPowerStateChanged(self, checked): self._serialSend.ctrlWord.lPowerSw = checked self._serialSend.sum = SerialPortProxy.serialPortSendSum(self._serialSend) self._serialProxy.writeData(self._serialSend) def onButtonRightPowerStateChanged(self, checked): self._serialSend.ctrlWord.rPowerSw = checked self._serialSend.sum = SerialPortProxy.serialPortSendSum(self._serialSend) self._serialProxy.writeData(self._serialSend) def onButtonLeftTracksipStateChanged(self, checked): self._serialSend.ctrlWord.lTracksip = checked self._serialSend.sum = SerialPortProxy.serialPortSendSum(self._serialSend) self._serialProxy.writeData(self._serialSend) def onButtonRightTracksipStateChanged(self, checked): self._serialSend.ctrlWord.rTracksip = checked self._serialSend.sum = SerialPortProxy.serialPortSendSum(self._serialSend) self._serialProxy.writeData(self._serialSend) def onSerialStateChanged(self, info): text = '串口: [%s] %s' % (self._serialProxy.config().__str__(), info) print(text) def onSerialDisplayRespond(self, data, dateTime): # Major Brake Pressure suffix = self.editMLeftBrakeP.text().split(' ')[1] self.editMLeftBrakeP.setText('%.2f %s' % (data.lMBrakeP * 1.0, suffix)) suffix = self.editMRightBrakeP.text().split(' ')[1] self.editMRightBrakeP.setText('%.2f %s' % (data.rMBrakeP * 1.0, suffix)) # Minor Brake Pressure suffix = self.editALeftBrakeP.text().split(' ')[1] self.editALeftBrakeP.setText('%.2f %s' % (data.lABrakeP * 1.0, suffix)) suffix = self.editARightBrakeP.text().split(' ')[1] self.editARightBrakeP.setText('%.2f %s' % (data.rABrakeP * 1.0, suffix)) # Rotation Rate suffix = self.editLeftRotateRate.text().split(' ')[1] self.editLeftRotateRate.setText('%d %s' % (data.lWheelSpd * 1.0, suffix)) suffix = self.editRightRotateRate.text().split(' ')[1] self.editRightRotateRate.setText('%d %s' % (data.rWheelSpd * 1.0, suffix)) # curves timeT = dateTime.toMSecsSinceEpoch() # curve - LBP self.curveLBP.curve(0).sheft(QPoint(timeT, data.lMBrakeP)) self.curveLBP.curve(1).sheft(QPoint(timeT, data.lABrakeP)) # curve - LRP self.curveLRP.curve(0).sheft(QPoint(timeT, data.lWheelSpd)) self.curveLRP.curve(1).sheft(QPoint(timeT, self._lTheorySpd)) # curve - RBP self.curveRBP.curve(0).sheft(QPoint(timeT, data.rMBrakeP)) self.curveRBP.curve(1).sheft(QPoint(timeT, data.rABrakeP)) # curve - RRP self.curveRRP.curve(0).sheft(QPoint(timeT, data.rWheelSpd)) self.curveRRP.curve(1).sheft(QPoint(timeT, self._rTheorySpd)) if not DatabaseMgr().write(data, self._lTheorySpd, self._rTheorySpd, timeT): assert(False) def onSerialPortError(self, error, info): buttonPortState = self.findChild(JSwitchButton, 'buttonPortState') if not buttonPortState: return if error == QSerialPort.NoError: buttonPortState.setState(True) else: buttonPortState.setState(False) text = '串口: [%s] %s' % (self._serialProxy.config().__str__(), info) print(text) def execSliderWidget(self): sliderWidget = SliderWidget(self.sender().text(), self) objName = self.sender().objectName() if objName == 'buttonLeftSpeedGain': lineEdit = self.findChild(QLineEdit, 'editTheoryLeftRotateRate') text = lineEdit.text().split(' ') suffix = ' ' + text[1] curValue = float(text[0]) sliderWidget.setRange(0, 3000) # sliderWidget.setDecimals(2) # sliderWidget.setSingleStep(0.01) sliderWidget.setSuffix(suffix) sliderWidget.setValue(curValue) def valueChanged(value): self._lTheorySpd = value buttonLeftSpeedSwitch = self.findChild(QPushButton, 'buttonLeftSpeedSwitch') if buttonLeftSpeedSwitch: buttonLeftSpeedSwitch.setText('左转速关' if value == 0.0 else '左转速开'); lineEdit.setText(('%.2f' % value) + suffix) # send self._serialSend.index += 1 self._serialSend.lWheelSpd = int(value * 42.94967296) self._serialSend.sum = SerialPortProxy.serialPortSendSum(self._serialSend) self._serialProxy.writeData(self._serialSend) sliderWidget.valueChanged.connect(valueChanged) elif objName == 'buttonRightSpeedGain': lineEdit = self.findChild(QLineEdit, 'editTheoryRightRotateRate') text = lineEdit.text().split(' ') suffix = ' ' + text[1] curValue = float(text[0]) sliderWidget.setRange(0, 3000) # sliderWidget.setDecimals(2) # sliderWidget.setSingleStep(0.01) sliderWidget.setSuffix(suffix) sliderWidget.setValue(curValue) def valueChanged(value): self._rTheorySpd = value buttonRightSpeedSwitch = self.findChild(QPushButton, 'buttonRightSpeedSwitch') if buttonRightSpeedSwitch: buttonRightSpeedSwitch.setText('右转速关' if value == 0.0 else '右转速开') lineEdit.setText(('%.2f' % value) + suffix) # send self._serialSend.index += 1 self._serialSend.rWheelSpd = int(value * 42.94967296) self._serialSend.sum = SerialPortProxy.serialPortSendSum(self._serialSend) self._serialProxy.writeData(self._serialSend) sliderWidget.valueChanged.connect(valueChanged) elif objName == 'buttonLeftSpeedKnob': lineEdit = self.findChild(QLineEdit, 'editTheoryLeftRotateRate') text = lineEdit.text().split(' ') suffix = ' ' + text[1] curValue = float(text[0]) minValue = max(0, curValue - 50) maxValue = min(3000, curValue + 50) if maxValue < 100: maxValue = minValue + 100 if minValue > 3000 - 100: minValue = maxValue - 100 sliderWidget.setRange(minValue, maxValue) # sliderWidget.setDecimals(2) # sliderWidget.setSingleStep(0.01) sliderWidget.setSuffix(suffix) sliderWidget.setValue(curValue) def valueChanged(value): self._lTheorySpd = value buttonLeftSpeedSwitch = self.findChild(QPushButton, 'buttonLeftSpeedSwitch') if buttonLeftSpeedSwitch: buttonLeftSpeedSwitch.setText('左转速关' if value == 0.0 else '左转速开') lineEdit.setText(('%.2f' % value) + suffix) # send self._serialSend.index += 1 self._serialSend.lWheelSpd = int(value * 42.94967296) self._serialSend.sum = SerialPortProxy.serialPortSendSum(self._serialSend) self._serialProxy.writeData(self._serialSend) sliderWidget.valueChanged.connect(valueChanged) elif objName == 'buttonRightSpeedKnob': lineEdit = self.findChild(QLineEdit, 'editTheoryRightRotateRate') text = lineEdit.text().split(' ') suffix = ' ' + text[1] curValue = float(text[0]) minValue = max(0, curValue - 50) maxValue = min(3000, curValue + 50) if maxValue < 100: maxValue = minValue + 100 if minValue > 3000 - 100: minValue = maxValue - 100 sliderWidget.setRange(minValue, maxValue) # sliderWidget.setDecimals(2) # sliderWidget.setSingleStep(0.01) sliderWidget.setSuffix(suffix) sliderWidget.setValue(curValue) def valueChanged(value): self._rTheorySpd = value buttonRightSpeedSwitch = self.findChild(QPushButton, 'buttonRightSpeedSwitch') if buttonRightSpeedSwitch: buttonRightSpeedSwitch.setText('右转速关' if value == 0.0 else '右转速开'); lineEdit.setText(('%.2f' % value) + suffix) # send self._serialSend.index += 1 self._serialSend.rWheelSpd = int(value * 42.94967296) self._serialSend.sum = SerialPortProxy.serialPortSendSum(self._serialSend) self._serialProxy.writeData(self._serialSend) sliderWidget.valueChanged.connect(valueChanged) else: pass sliderWidget.exec_()
class HistoryWidget(QDialog): """ class HistonWidget """ _v_curve_colors = [Qt.white, Qt.gray, Qt.red, Qt.green, Qt.blue, Qt.cyan, Qt.magenta, Qt.darkYellow] _v_curve_checked = [True, True, True, True, True, True, True, True] def __init__(self, parent=None): super(HistoryWidget, self).__init__(parent) self.setObjectName("HistoryWidget") self.resize(800, 480) self.setWindowTitle("历史数据查看") # layout - top horiLayoutTop = QHBoxLayout() buttonQuit = QPushButton(self) buttonQuit.setObjectName("buttonQuit") horiLayoutTop.addSpacing(25) horiLayoutTop.addWidget(buttonQuit, 0, Qt.AlignLeft) horiLayoutTop.addStretch() # button-export buttonExport = QPushButton(self) buttonExport.setObjectName("buttonExport") horiLayoutTop.addWidget(buttonExport) horiLayoutTop.addStretch() # button-open buttonOpen = QPushButton(self) buttonOpen.setObjectName("buttonOpen") horiLayoutTop.addWidget(buttonOpen) horiLayoutTop.addStretch() formLayoutTime = QFormLayout() formLayoutTime.setFormAlignment(Qt.AlignVCenter) horiLayoutTop.addLayout(formLayoutTime) horiLayoutTop.addStretch() self.dateTimeEditStart = QDateTimeEdit(self) self.dateTimeEditStart.setObjectName("dateTimeEditStart") self.dateTimeEditStart.setDisplayFormat("yyyy-MM-dd HH:mm:ss") formLayoutTime.addRow("起始时间:", self.dateTimeEditStart) self.dateTimeEditEnd = QDateTimeEdit(self) self.dateTimeEditEnd.setObjectName("dateTimeEditEnd") self.dateTimeEditEnd.setDisplayFormat("yyyy-MM-dd HH:mm:ss") formLayoutTime.addRow("结束时间:", self.dateTimeEditEnd) # LBP formLayoutLBP = QFormLayout() formLayoutLBP.setFormAlignment(Qt.AlignVCenter) formLayoutLBP.setLabelAlignment(Qt.AlignRight) horiLayoutTop.addLayout(formLayoutLBP) horiLayoutTop.addStretch() self.checkBoxLBPMajor = QCheckBox("主", self) self.checkBoxLBPMajor.setProperty("curveColor", "#101010") self.checkBoxLBPMinor = QCheckBox("副", self) self.checkBoxLBPMinor.setProperty("curveColor", "#101010") formLayoutLBP.addRow("左刹车压力:", self.checkBoxLBPMajor) formLayoutLBP.addRow("", self.checkBoxLBPMinor) # RBP formLayoutRBP = QFormLayout() formLayoutRBP.setFormAlignment(Qt.AlignVCenter) formLayoutRBP.setLabelAlignment(Qt.AlignRight) horiLayoutTop.addLayout(formLayoutRBP) horiLayoutTop.addStretch() self.checkBoxRBPMajor = QCheckBox("主", self) self.checkBoxRBPMajor.setProperty("curveColor", "#101010") self.checkBoxRBPMinor = QCheckBox("副", self) self.checkBoxRBPMinor.setProperty("curveColor", "#101010") formLayoutRBP.addRow("右刹车压力:", self.checkBoxRBPMajor) formLayoutRBP.addRow("", self.checkBoxRBPMinor) # LRP formLayoutLRP = QFormLayout() formLayoutLRP.setFormAlignment(Qt.AlignVCenter) formLayoutLRP.setLabelAlignment(Qt.AlignRight) horiLayoutTop.addLayout(formLayoutLRP) horiLayoutTop.addStretch() self.checkBoxLRPTheory = QCheckBox("理论", self) self.checkBoxLRPTheory.setProperty("curveColor", "#101010") self.checkBoxLRPReal = QCheckBox("实际", self) self.checkBoxLRPReal.setProperty("curveColor", "#101010") formLayoutLRP.addRow("左转速:", self.checkBoxLRPTheory) formLayoutLRP.addRow("", self.checkBoxLRPReal) # RRP formLayoutRRP = QFormLayout() formLayoutRRP.setFormAlignment(Qt.AlignVCenter) formLayoutRRP.setLabelAlignment(Qt.AlignRight) horiLayoutTop.addLayout(formLayoutRRP) horiLayoutTop.addStretch() self.checkBoxRRPTheory = QCheckBox("理论", self) self.checkBoxRRPTheory.setProperty("curveColor", "#101010") self.checkBoxRRPReal = QCheckBox("实际", self) self.checkBoxRRPReal.setProperty("curveColor", "#101010") formLayoutRRP.addRow("右转速:", self.checkBoxRRPTheory) formLayoutRRP.addRow("", self.checkBoxRRPReal) # button-update buttonUpdate = QPushButton(self) buttonUpdate.setObjectName("buttonUpdate") horiLayoutTop.addWidget(buttonUpdate) horiLayoutTop.addStretch() # middle-curves self.curveHistory = CurveWidget("历史数据回放", True, self) self.curveHistory.setMaximumWidth(10e5) self.curveHistory.setScaleLabelFormat("yyyy/MM/dd\n HH:mm:ss") self.curveHistory.clear() # vertLayoutMain = QVBoxLayout(self) vertLayoutMain.addLayout(horiLayoutTop) vertLayoutMain.addWidget(self.curveHistory) buttonQuit.clicked.connect(self.accept) buttonOpen.clicked.connect(self.buttonOpenClicked) buttonExport.clicked.connect(self.buttonExportClicked) self.dateTimeEditStart.dateTimeChanged.connect(self.dateTimeStartChanged) self.dateTimeEditEnd.dateTimeChanged.connect(self.dateTimeEndChanged) self.checkBoxLBPMajor.toggled.connect(self.checkBoxLBPMajorToggled) self.checkBoxLBPMinor.toggled.connect(self.checkBoxLBPMinorToggled) self.checkBoxRBPMajor.toggled.connect(self.checkBoxRBPMajorToggled) self.checkBoxRBPMinor.toggled.connect(self.checkBoxRBPMinorToggled) self.checkBoxLRPTheory.toggled.connect(self.checkBoxLRPTheoryToggled) self.checkBoxLRPReal.toggled.connect(self.checkBoxLRPRealToggled) self.checkBoxRRPTheory.toggled.connect(self.checkBoxRRPTheoryToggled) self.checkBoxRRPReal.toggled.connect(self.checkBoxRRPRealToggled) buttonUpdate.clicked.connect(self.buttonUpdateClicked) # finalLy initialize self.checkBoxLBPMajor.setChecked(self._v_curve_checked[0]) self.checkBoxLBPMinor.setChecked(self._v_curve_checked[1]) self.checkBoxRBPMajor.setChecked(self._v_curve_checked[2]) self.checkBoxRBPMinor.setChecked(self._v_curve_checked[3]) self.checkBoxLRPTheory.setChecked(self._v_curve_checked[4]) self.checkBoxLRPReal.setChecked(self._v_curve_checked[5]) self.checkBoxRRPTheory.setChecked(self._v_curve_checked[6]) self.checkBoxRRPReal.setChecked(self._v_curve_checked[7]) def buttonOpenClicked(self): fileDialog = QFileDialog( self, "打开历史数据文件", QApplication.applicationDirPath() + "/../data", "Database File (*.db *.mdb)" ) if fileDialog.exec_() == QDialog.Rejected: return # clear curve self.curveHistory.clear() # filePaths = fileDialog.selectedFiles() if filePaths.isEmpty(): return filePath = filePaths.first() if filePath.isEmpty(): return # open database if not DatabaseMgr().open(filePath): return # startTime = QDateTime.fromMSecsSinceEpoch(DatabaseMgr().startTime()) endTime = QDateTime.fromMSecsSinceEpoch(DatabaseMgr().endTime()) self.dateTimeEditStart.setDateTimeRange(startTime, endTime) self.dateTimeEditEnd.setDateTimeRange(startTime, endTime) self.dateTimeEditEnd.setDateTime(endTime) self.dateTimeEditStart.setDateTime(startTime) # title of curve self.curveHistory.setTitle("历史数据回放" + "(" + QFileInfo(filePath).fileName() + ")") def buttonExportClicked(self): (filePaths, filter) = QFileDialog.getOpenFileNames( parent=self, caption="转换数据库文件为文本格式", directory=QApplication.applicationDirPath() + "/../data", filter="Database file (*.db * mdb)", ) if not filePaths: return # if DatabaseMgr().convertToText(filePaths): QMessageBox.information(self, "格式转换", "转换成功!") else: QMessageBox.warning(self, "格式转换", "转换失败!") def dateTimeStartChanged(self, dateTime): dateTimeEnd = self.dateTimeEditEnd.dateTime() if dateTime > dateTimeEnd: self.dateTimeEditStart.setDateTime(dateTimeEnd) def dateTimeEndChanged(self, dateTime): dateTimeStart = self.dateTimeEditStart.dateTime() if dateTime < dateTimeStart: self.dateTimeEditEnd.setDateTime(dateTimeStart) def checkBoxLBPMajorToggled(self, checked): self._v_curve_checked[0] = checked def checkBoxLBPMinorToggled(self, checked): self._v_curve_checked[1] = checked def checkBoxRBPMajorToggled(self, checked): self._v_curve_checked[2] = checked def checkBoxRBPMinorToggled(self, checked): self._v_curve_checked[3] = checked def checkBoxLRPTheoryToggled(self, checked): self._v_curve_checked[4] = checked def checkBoxLRPRealToggled(self, checked): self._v_curve_checked[5] = checked def checkBoxRRPTheoryToggled(self, checked): self._v_curve_checked[6] = checked def checkBoxRRPRealToggled(self, checked): self._v_curve_checked[7] = checked def buttonUpdateClicked(self): # clear curve self.curveHistory.clear() points = [] startTime = self.dateTimeEditStart.dateTime().toMSecsSinceEpoch() endTime = self.dateTimeEditEnd.dateTime().toMSecsSinceEpoch() # LBP-Major if self.checkBoxLBPMajor.isChecked(): # read points.clear() if DatabaseMgr().read("lMBrakeP", points, startTime, endTime): self.curveHistory.addCurve("左刹压力-主", QPen(self.randomColor(0)), points) # LBP-Minor if self.checkBoxLBPMinor.isChecked(): # read points.clear() if DatabaseMgr().read("lABrakeP", points, startTime, endTime): self.curveHistory.addCurve("左刹压力-副", QPen(self.randomColor(1)), points) # RBP-Major if self.checkBoxRBPMajor.isChecked(): # read points.clear() if DatabaseMgr().read("rMBrakeP", points, startTime, endTime): self.curveHistory.addCurve("右刹压力-主", QPen(self.randomColor(2)), points) # RBP-Minor if self.checkBoxRBPMinor.isChecked(): # read points.clear() if DatabaseMgr().read("rABrakeP", points, startTime, endTime): self.curveHistory.addCurve("右刹压力-副", QPen(self.randomColor(3)), points) # LRP-Theory if self.checkBoxLRPTheory.isChecked(): # read points.clear() if DatabaseMgr().read("lTheorySpd", points, startTime, endTime): self.curveHistory.addCurve("左转速-理论", QPen(self.randomColor(4)), points) # LRP-Real if self.checkBoxLRPReal.isChecked(): # read points.clear() if DatabaseMgr().read("lWheelSpd", points, startTime, endTime): self.curveHistory.addCurve("左转速-实际", QPen(self.randomColor(5)), points) # RRP-Theory if self.checkBoxRRPTheory.isChecked(): # read points.clear() if DatabaseMgr().read("rTheorySpd", points, startTime, endTime): self.curveHistory.addCurve("右转速-理论", QPen(self.randomColor(6)), points) # RRP-Real if self.checkBoxRRPReal.isChecked(): # read points.clear() if DatabaseMgr().read("rWheelSpd", points, startTime, endTime): self.curveHistory.addCurve("右转速-实际", QPen(self.randomColor(7)), points) @staticmethod def randomColor(index): return HistoryWidget._v_curve_colors[index]