emv_home.py 2.0 KB

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