pcs_home.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @文件 :bms_home.py
  5. @时间 :2021/12/09 13:33:56
  6. @作者 :None
  7. @版本 :1.0
  8. @说明 :主页面逻辑
  9. '''
  10. from ui.home import UiPcsHomePage
  11. from utils.qt import QMainWindow, Qt, QStyle, QMessageBox, QGuiApplication, Signal
  12. class Win_Pcs_Home(UiPcsHomePage, QMainWindow):
  13. # 跳转连接页面
  14. interface_signal = Signal(int)
  15. connect_signal = Signal()
  16. disconnect_signal = Signal()
  17. def __init__(self, parent=None):
  18. super(Win_Pcs_Home, self).__init__(parent)
  19. self.setupUi(self)
  20. self.cb_interface.currentIndexChanged.connect(self._interface_chose)
  21. self.pcs_switch.checkedChanged.connect(self._get_state)
  22. # 居中显示
  23. def center(self):
  24. # 新方法
  25. self.setGeometry(
  26. QStyle.alignedRect(
  27. Qt.LeftToRight,
  28. Qt.AlignCenter,
  29. self.size(),
  30. QGuiApplication.primaryScreen().availableGeometry(),
  31. ),
  32. )
  33. def _interface_chose(self):
  34. self.interface_signal.emit(self.cb_interface.currentIndex())
  35. # BMS连接
  36. def _get_state(self, checked):
  37. if checked:
  38. self.connect_signal.emit()
  39. else:
  40. self.disconnect_signal.emit()
  41. def can_connect_error(self):
  42. QMessageBox.critical(self, "失败!", "CAN 连接失败!")
  43. self.pcs_switch.state = False
  44. return
  45. def no_can_device(self):
  46. QMessageBox.critical(self, "失败!", "无CAN 设备!")
  47. self.pcs_switch.state = False
  48. return
  49. def com_connect_error(self):
  50. QMessageBox.critical(self, "失败!", "串口连接失败!")
  51. self.pcs_switch.state = False
  52. return
  53. def no_com_device(self):
  54. QMessageBox.critical(self, "失败!", "无法连接此串口设备!")
  55. self.pcs_switch.state = False
  56. return