180 lines
6.4 KiB
Python
180 lines
6.4 KiB
Python
|
import IOCard_ui
|
||
|
import sys
|
||
|
from PyQt5.QtWidgets import QApplication, QFileDialog, QLabel, QMainWindow, QWidget, QPushButton, QMessageBox
|
||
|
from PyQt5 import QtWidgets, uic, QtCore, QtGui
|
||
|
from PyQt5.QtGui import QImage, QPixmap, QPainter, QPen, QIcon
|
||
|
from PyQt5.QtCore import QRect, Qt, QCoreApplication, QObject
|
||
|
from IOcardQthread import IOcard
|
||
|
import time
|
||
|
|
||
|
|
||
|
ui = IOCard_ui.Ui_MainWindow
|
||
|
|
||
|
class PyQtMain(QtWidgets.QMainWindow, ui):
|
||
|
# region 初始化
|
||
|
def __init__(self):
|
||
|
QtWidgets.QMainWindow.__init__(self) # 創建主界面對象
|
||
|
ui.__init__(self) # 主界面對象初始化
|
||
|
self.setupUi(self) # 配置主界面對象
|
||
|
# QtCore.QMetaObject.connectSlotsByName(self) # 使用裝飾器取代信號槽
|
||
|
# self.iniGuiEvent()
|
||
|
|
||
|
self.IOCardThread = IOcard(SERVER_HOST= '192.168.0.150',SERVER_PORT = 502)
|
||
|
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_IOCardConnect_clicked(self):
|
||
|
self.IOCardThread.IOCard_connect()
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.open()
|
||
|
self.IOCardThread.start()
|
||
|
self.IOCardThread.rawdataINPUT.connect(self.showInput)
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
def showInput(self, input0,input1,input2,input3,input4,input5,input6,input7,input8,input9):
|
||
|
self.state_input0.setVisible(input0)
|
||
|
self.state_input1.setVisible(input1)
|
||
|
self.state_input2.setVisible(input2)
|
||
|
self.state_input3.setVisible(input3)
|
||
|
self.state_input4.setVisible(input4)
|
||
|
self.state_input5.setVisible(input5)
|
||
|
self.state_input6.setVisible(input6)
|
||
|
self.state_input7.setVisible(input7)
|
||
|
self.state_input8.setVisible(input8)
|
||
|
self.state_input9.setVisible(input9)
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_motorMove_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
try:
|
||
|
self.IOCardThread.updataDisSpeed(int(self.lineEdit_Dist.text()), int(self.lineEdit_speed.text()))
|
||
|
except:
|
||
|
self.IOCardThread.updataDisSpeed(-310, 400)
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_motorGoHome_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.goHome()
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_openAll_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.openAll()
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_closeAll_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.closeAll()
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_openBuzzer_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.openBuzzer()
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_openRedLight_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.openRedLight()
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_openYellowLight_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.openYellowLight()
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_openGreenLight_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.openGreenLight()
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_openAILight_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.openAILight()
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_openAOILight_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.openAOILight()
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_motor_out_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.updataDisSpeed(310, 400)#出來
|
||
|
# self.IOCardThread.updataDisSpeed(375, 320)#出來
|
||
|
# while not self.IOCardThread.MOTORSTATE[2]:
|
||
|
# time.sleep(0.01)
|
||
|
# self.IOCardThread.updataDisSpeed(-30, 50)#出來
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
@QtCore.pyqtSlot()
|
||
|
def on_btn_motor_in_clicked(self):
|
||
|
if self.IOCardThread.connect:
|
||
|
self.debugBar('IOCard Connection!!!')
|
||
|
self.IOCardThread.updataDisSpeed(-310, 400)#進去
|
||
|
# self.IOCardThread.updataDisSpeed(-280, 320)#進去
|
||
|
# while not self.IOCardThread.MOTORSTATE[2]:
|
||
|
# time.sleep(0.01)
|
||
|
# self.IOCardThread.updataDisSpeed(30, 50)#進去
|
||
|
else:
|
||
|
self.debugBar('IOCard Disconnection!!!')
|
||
|
|
||
|
# region 顯示MessageBox 並獲取選取按鍵狀態
|
||
|
def showdialog(seelf):
|
||
|
msg = QMessageBox()
|
||
|
msg.setIcon(QMessageBox.Information)
|
||
|
msg.setText("This is a message box")
|
||
|
msg.setInformativeText("This is additional information")
|
||
|
msg.setWindowTitle("MessageBox demo")
|
||
|
msg.setWindowIcon(QIcon(r"yuntech.png"))
|
||
|
msg.setDetailedText("The details are as follows:")
|
||
|
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
|
||
|
msg.buttonClicked.connect(seelf.msgbtn)
|
||
|
retval = msg.exec_() # 執行
|
||
|
|
||
|
def msgbtn(self, i):
|
||
|
self.debugBar(f"MessageBox Button pressed is:{i.text()}")
|
||
|
|
||
|
def debugBar(self, msg):
|
||
|
self.statusBar.showMessage(str(msg), 5000)
|
||
|
# endregion
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
app = QApplication(sys.argv)
|
||
|
MainWindow = PyQtMain()
|
||
|
MainWindow.show()
|
||
|
sys.exit(app.exec_())
|