home.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @文件 :home.py
  5. @时间 :2022/01/22 09:53:31
  6. @作者 :None
  7. @版本 :1.0
  8. @说明 :主页面
  9. '''
  10. from ui.own.frame_theme import MyFrame
  11. from ui.own.switch_button import SwitchButton
  12. from ui.own.led import Led
  13. from ui.own.palette_theme import set_my_palette
  14. from utils.qt import Qt, QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel, QGroupBox, QPushButton, QSizePolicy, QComboBox, QSize, QCoreApplication, QMetaObject
  15. class UiEmvHomePage(object):
  16. def setupUi(self, main):
  17. main.resize(500, 400)
  18. main.setMinimumSize(500, 400)
  19. main.setMaximumSize(500, 400)
  20. set_my_palette(main)
  21. self.central_widget = QWidget(main)
  22. self.main_layout = QHBoxLayout(self.central_widget)
  23. self.main_layout.setContentsMargins(0, 0, 0, 0)
  24. self.main_layout.setSpacing(0)
  25. # 主窗口左侧布局
  26. self.left_widget = QWidget(self.central_widget)
  27. # 主窗口左侧采用垂直布局
  28. self.left_layout = QVBoxLayout(self.left_widget)
  29. self.left_layout.setContentsMargins(0, 0, 0, 0)
  30. self.left_layout.setSpacing(0)
  31. # 数据接口
  32. self.interface_widget = MyFrame(self.left_widget)
  33. self.interface_hlayout = QHBoxLayout(self.interface_widget)
  34. self.interface_hlayout.setContentsMargins(0, 0, 0, 0)
  35. self.interface_hlayout.setSpacing(0)
  36. self.groupbox_interface = QGroupBox(self.interface_widget)
  37. self.interface_vlayout = QVBoxLayout(self.groupbox_interface)
  38. self.cb_interface = QComboBox(self.groupbox_interface)
  39. self.cb_interface.addItems(["CAN通讯", "串口通讯"])
  40. self.interface_vlayout.addWidget(self.cb_interface)
  41. self.interface_hlayout.addWidget(self.groupbox_interface)
  42. self.left_layout.addWidget(self.interface_widget)
  43. # CAN通讯配置
  44. self.can_interface_widget = MyFrame(self.left_widget)
  45. self.can_interface_hlayout = QHBoxLayout(self.can_interface_widget)
  46. self.can_interface_hlayout.setContentsMargins(0, 0, 0, 0)
  47. self.can_interface_hlayout.setSpacing(0)
  48. self.groupbox_can_interface = QGroupBox(self.can_interface_widget)
  49. self.can_interface_glayout = QGridLayout(self.groupbox_can_interface)
  50. self.lb_can_interface_channel = QLabel(self.groupbox_can_interface)
  51. self.lb_can_interface_channel.setText("设备索引号:")
  52. self.can_interface_glayout.addWidget(self.lb_can_interface_channel, 0, 0)
  53. self.cb_can_interface_channel = QComboBox(self.groupbox_can_interface)
  54. self.cb_can_interface_channel.addItems([str(i) for i in range(9)])
  55. self.can_interface_glayout.addWidget(self.cb_can_interface_channel, 0, 1)
  56. self.lb_can_interface_index = QLabel(self.groupbox_can_interface)
  57. self.lb_can_interface_index.setText("设备通道号:")
  58. self.can_interface_glayout.addWidget(self.lb_can_interface_index, 1, 0)
  59. self.cb_can_interface_index = QComboBox(self.groupbox_can_interface)
  60. self.cb_can_interface_index.addItems(["0", "1"])
  61. self.can_interface_glayout.addWidget(self.cb_can_interface_index, 1, 1)
  62. self.lb_can_interface_baudrate = QLabel(self.groupbox_can_interface)
  63. self.lb_can_interface_baudrate.setText("CAN波特率:")
  64. self.can_interface_glayout.addWidget(self.lb_can_interface_baudrate, 2, 0)
  65. self.cb_can_interface_baudrate = QComboBox(self.groupbox_can_interface)
  66. self.cb_can_interface_baudrate.addItems(["125Kbps", "250Kbps", "500Kbps"])
  67. self.cb_can_interface_baudrate.setCurrentText("250Kbps")
  68. self.can_interface_glayout.addWidget(self.cb_can_interface_baudrate, 2, 1)
  69. self.can_interface_hlayout.addWidget(self.groupbox_can_interface)
  70. self.left_layout.addWidget(self.can_interface_widget)
  71. # 串口通讯配置
  72. self.com_interface_widget = MyFrame(self.left_widget)
  73. self.com_interface_hlayout = QHBoxLayout(self.com_interface_widget)
  74. self.com_interface_hlayout.setContentsMargins(0, 0, 0, 0)
  75. self.com_interface_hlayout.setSpacing(0)
  76. self.groupbox_com_interface = QGroupBox(self.interface_widget)
  77. self.com_interface_glayout = QGridLayout(self.groupbox_com_interface)
  78. self.lb_com_interface_port = QLabel(self.groupbox_com_interface)
  79. self.lb_com_interface_port.setText("端口号:")
  80. self.com_interface_glayout.addWidget(self.lb_com_interface_port, 0, 0)
  81. self.cb_com_interface_port = QComboBox(self.groupbox_com_interface)
  82. self.cb_com_interface_port.addItems([str(i + 1) for i in range(9)])
  83. self.com_interface_glayout.addWidget(self.cb_com_interface_port, 0, 1)
  84. self.lb_com_interface_baudrate = QLabel(self.groupbox_com_interface)
  85. self.lb_com_interface_baudrate.setText("波特率:")
  86. self.com_interface_glayout.addWidget(self.lb_com_interface_baudrate, 1, 0)
  87. self.cb_com_interface_baudrate = QComboBox(self.groupbox_com_interface)
  88. self.cb_com_interface_baudrate.addItems(["9600", "115200"])
  89. self.com_interface_glayout.addWidget(self.cb_com_interface_baudrate, 1, 1)
  90. self.lb_com_interface_parity = QLabel(self.groupbox_com_interface)
  91. self.lb_com_interface_parity.setText("校验位:")
  92. self.com_interface_glayout.addWidget(self.lb_com_interface_parity, 2, 0)
  93. self.cb_com_interface_parity = QComboBox(self.groupbox_com_interface)
  94. self.cb_com_interface_parity.addItems(["无校验", "偶校验", "奇校验"])
  95. self.com_interface_glayout.addWidget(self.cb_com_interface_parity, 2, 1)
  96. self.lb_com_interface_word_length = QLabel(self.groupbox_com_interface)
  97. self.lb_com_interface_word_length.setText("数据位:")
  98. self.com_interface_glayout.addWidget(self.lb_com_interface_word_length, 3, 0)
  99. self.cb_com_interface_word_length = QComboBox(self.groupbox_com_interface)
  100. self.cb_com_interface_word_length.addItems(["8", "9"])
  101. self.com_interface_glayout.addWidget(self.cb_com_interface_word_length, 3, 1)
  102. self.lb_com_interface_stop = QLabel(self.groupbox_com_interface)
  103. self.lb_com_interface_stop.setText("停止位:")
  104. self.com_interface_glayout.addWidget(self.lb_com_interface_stop, 4, 0)
  105. self.cb_com_interface_stop = QComboBox(self.groupbox_com_interface)
  106. self.cb_com_interface_stop.addItems(["1", "1.5", "2"])
  107. self.com_interface_glayout.addWidget(self.cb_com_interface_stop, 4, 1)
  108. self.groupbox_com_interface.hide()
  109. self.com_interface_hlayout.addWidget(self.groupbox_com_interface)
  110. self.left_layout.addWidget(self.com_interface_widget)
  111. # BMS连接开关
  112. self.emv_connect_widget = MyFrame(self.left_widget)
  113. self.emv_connect_layout = QHBoxLayout(self.emv_connect_widget)
  114. self.emv_connect_layout.setContentsMargins(0, 0, 0, 0)
  115. self.emv_connect_layout.setSpacing(0)
  116. self.groupbox_emv_connect = QGroupBox(self.emv_connect_widget)
  117. self.bms_connect_hlayout = QHBoxLayout(self.groupbox_emv_connect)
  118. self.emv_switch = SwitchButton(self.groupbox_emv_connect)
  119. size_policy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
  120. size_policy.setHorizontalStretch(0)
  121. size_policy.setVerticalStretch(0)
  122. size_policy.setHeightForWidth(self.emv_switch.sizePolicy().hasHeightForWidth())
  123. self.emv_switch.setSizePolicy(size_policy)
  124. self.emv_switch.setMinimumSize(QSize(70, 30))
  125. self.bms_connect_hlayout.addWidget(self.emv_switch)
  126. self.emv_connect_layout.addWidget(self.groupbox_emv_connect)
  127. self.left_layout.addWidget(self.emv_connect_widget)
  128. # 其他信息
  129. self.bms_widget = MyFrame(self.left_widget)
  130. self.bms_layout = QHBoxLayout(self.bms_widget)
  131. self.bms_layout.setContentsMargins(0, 0, 0, 0)
  132. self.bms_layout.setSpacing(0)
  133. self.groupbox_bms = QGroupBox(self.bms_widget)
  134. self.bms_hlayout = QGridLayout(self.groupbox_bms)
  135. self.lb_bms = QLabel(self.groupbox_bms)
  136. self.lb_bms.setText("簇编号:")
  137. self.bms_hlayout.addWidget(self.lb_bms, 0, 0)
  138. self.cb_bms = QComboBox(self.groupbox_bms)
  139. self.cb_bms.addItems(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
  140. self.bms_hlayout.addWidget(self.cb_bms, 0, 1)
  141. size_policy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
  142. size_policy.setHorizontalStretch(0)
  143. size_policy.setVerticalStretch(0)
  144. size_policy.setHeightForWidth(self.groupbox_bms.sizePolicy().hasHeightForWidth())
  145. self.groupbox_bms.setSizePolicy(size_policy)
  146. self.bms_layout.addWidget(self.groupbox_bms)
  147. self.left_layout.addWidget(self.bms_widget)
  148. # 其他信息
  149. self.other_widget = MyFrame(self.left_widget)
  150. self.other_layout = QHBoxLayout(self.other_widget)
  151. self.other_layout.setContentsMargins(0, 0, 0, 0)
  152. self.other_layout.setSpacing(0)
  153. self.groupbox_other = QGroupBox(self.other_widget)
  154. size_policy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
  155. size_policy.setHorizontalStretch(0)
  156. size_policy.setVerticalStretch(0)
  157. size_policy.setHeightForWidth(self.groupbox_other.sizePolicy().hasHeightForWidth())
  158. self.groupbox_other.setSizePolicy(size_policy)
  159. self.other_layout.addWidget(self.groupbox_other)
  160. self.left_layout.addWidget(self.other_widget)
  161. self.main_layout.addWidget(self.left_widget, stretch=1)
  162. self.right_widget = QWidget(self.central_widget)
  163. # 主窗口右侧采用垂直布局
  164. self.right_layout = QVBoxLayout(self.right_widget)
  165. self.right_layout.setContentsMargins(0, 0, 0, 0)
  166. self.right_layout.setSpacing(0)
  167. # 数据接口
  168. self.relay_widget = MyFrame(self.right_widget)
  169. self.relay_vlayout = QVBoxLayout(self.relay_widget)
  170. self.relay_vlayout.setContentsMargins(0, 0, 0, 0)
  171. self.relay_vlayout.setSpacing(0)
  172. self.groupbox_relay = QGroupBox(self.relay_widget)
  173. self.groupbox_relay.setTitle("电磁阀控制指令")
  174. self.relay_glayout = QGridLayout(self.groupbox_relay)
  175. self.emv_version = QLabel(self.groupbox_relay)
  176. self.emv_version.setText("电磁阀软件版本号:")
  177. self.relay_glayout.addWidget(self.emv_version, 0, 0, 1, 1, Qt.AlignCenter)
  178. self.edt_emv_version = QLabel(self.groupbox_relay)
  179. self.edt_emv_version.setText("")
  180. self.relay_glayout.addWidget(self.edt_emv_version, 0, 1, 1, 1, Qt.AlignCenter)
  181. self.lb_cls = QLabel(self.groupbox_relay)
  182. self.lb_cls.setText("电磁阀:")
  183. self.relay_glayout.addWidget(self.lb_cls, 1, 0, 1, 1, Qt.AlignCenter)
  184. self.cb_cls = QComboBox(self.groupbox_relay)
  185. self.cb_cls.addItems(["总", "1", "2", "3", "4", "5", "6", "7", "8", "9"])
  186. self.relay_glayout.addWidget(self.cb_cls, 1, 1, 1, 1)
  187. self.btn_emv_on = QPushButton(self.groupbox_relay)
  188. self.btn_emv_on.setText("闭合")
  189. self.relay_glayout.addWidget(self.btn_emv_on, 2, 0, 1, 1, Qt.AlignCenter)
  190. self.btn_emv_off = QPushButton(self.groupbox_relay)
  191. self.btn_emv_off.setText("断开")
  192. self.relay_glayout.addWidget(self.btn_emv_off, 2, 1, 1, 1, Qt.AlignCenter)
  193. self.relay_vlayout.addWidget(self.groupbox_relay)
  194. self.right_layout.addWidget(self.relay_widget)
  195. # 数据接口
  196. self.emv_data_widget = MyFrame(self.right_widget)
  197. self.emv_data_hlayout = QHBoxLayout(self.emv_data_widget)
  198. self.emv_data_hlayout.setContentsMargins(0, 0, 0, 0)
  199. self.emv_data_hlayout.setSpacing(0)
  200. self.groupbox_emv_data = QGroupBox(self.emv_data_widget)
  201. self.groupbox_emv_data.setTitle("电磁阀状态")
  202. self.emv_data_glayout = QGridLayout(self.groupbox_emv_data)
  203. # 总
  204. self.led_emv_total = Led(self.groupbox_emv_data)
  205. self.emv_data_glayout.addWidget(self.led_emv_total, 0, 0, 1, 1, Qt.AlignCenter)
  206. self.lb_emv_total = QLabel(self.groupbox_emv_data)
  207. self.lb_emv_total.setText("总")
  208. self.emv_data_glayout.addWidget(self.lb_emv_total, 1, 0, 1, 1, Qt.AlignCenter)
  209. # 1
  210. self.led_emv_1 = Led(self.groupbox_emv_data)
  211. self.emv_data_glayout.addWidget(self.led_emv_1, 0, 1, 1, 1, Qt.AlignCenter)
  212. self.lb_emv_1 = QLabel(self.groupbox_emv_data)
  213. self.lb_emv_1.setText("#1")
  214. self.emv_data_glayout.addWidget(self.lb_emv_1, 1, 1, 1, 1, Qt.AlignCenter)
  215. # 2
  216. self.led_emv_2 = Led(self.groupbox_emv_data)
  217. self.emv_data_glayout.addWidget(self.led_emv_2, 0, 2, 1, 1, Qt.AlignCenter)
  218. self.lb_emv_2 = QLabel(self.groupbox_emv_data)
  219. self.lb_emv_2.setText("#2")
  220. self.emv_data_glayout.addWidget(self.lb_emv_2, 1, 2, 1, 1, Qt.AlignCenter)
  221. # 3
  222. self.led_emv_3 = Led(self.groupbox_emv_data)
  223. self.emv_data_glayout.addWidget(self.led_emv_3, 0, 3, 1, 1, Qt.AlignCenter)
  224. self.lb_emv_3 = QLabel(self.groupbox_emv_data)
  225. self.lb_emv_3.setText("#3")
  226. self.emv_data_glayout.addWidget(self.lb_emv_3, 1, 3, 1, 1, Qt.AlignCenter)
  227. # 4
  228. self.led_emv_4 = Led(self.groupbox_emv_data)
  229. self.emv_data_glayout.addWidget(self.led_emv_4, 0, 4, 1, 1, Qt.AlignCenter)
  230. self.lb_emv_4 = QLabel(self.groupbox_emv_data)
  231. self.lb_emv_4.setText("#4")
  232. self.emv_data_glayout.addWidget(self.lb_emv_4, 1, 4, 1, 1, Qt.AlignCenter)
  233. # 5
  234. self.led_emv_5 = Led(self.groupbox_emv_data)
  235. self.emv_data_glayout.addWidget(self.led_emv_5, 0, 5, 1, 1, Qt.AlignCenter)
  236. self.lb_emv_5 = QLabel(self.groupbox_emv_data)
  237. self.lb_emv_5.setText("#5")
  238. self.emv_data_glayout.addWidget(self.lb_emv_5, 1, 5, 1, 1, Qt.AlignCenter)
  239. # 6
  240. self.led_emv_6 = Led(self.groupbox_emv_data)
  241. self.emv_data_glayout.addWidget(self.led_emv_6, 2, 1, 1, 1, Qt.AlignCenter)
  242. self.lb_emv_6 = QLabel(self.groupbox_emv_data)
  243. self.lb_emv_6.setText("#6")
  244. self.emv_data_glayout.addWidget(self.lb_emv_6, 3, 1, 1, 1, Qt.AlignCenter)
  245. # 7
  246. self.led_emv_7 = Led(self.groupbox_emv_data)
  247. self.emv_data_glayout.addWidget(self.led_emv_7, 2, 2, 1, 1, Qt.AlignCenter)
  248. self.lb_emv_7 = QLabel(self.groupbox_emv_data)
  249. self.lb_emv_7.setText("#7")
  250. self.emv_data_glayout.addWidget(self.lb_emv_7, 3, 2, 1, 1, Qt.AlignCenter)
  251. # 8
  252. self.led_emv_8 = Led(self.groupbox_emv_data)
  253. self.emv_data_glayout.addWidget(self.led_emv_8, 2, 3, 1, 1, Qt.AlignCenter)
  254. self.lb_emv_8 = QLabel(self.groupbox_emv_data)
  255. self.lb_emv_8.setText("#8")
  256. self.emv_data_glayout.addWidget(self.lb_emv_8, 3, 3, 1, 1, Qt.AlignCenter)
  257. # 9
  258. self.led_emv_9 = Led(self.groupbox_emv_data)
  259. self.emv_data_glayout.addWidget(self.led_emv_9, 2, 4, 1, 1, Qt.AlignCenter)
  260. self.lb_emv_9 = QLabel(self.groupbox_emv_data)
  261. self.lb_emv_9.setText("#9")
  262. self.emv_data_glayout.addWidget(self.lb_emv_9, 3, 4, 1, 1, Qt.AlignCenter)
  263. # 10
  264. self.led_emv_10 = Led(self.groupbox_emv_data)
  265. self.emv_data_glayout.addWidget(self.led_emv_10, 2, 5, 1, 1, Qt.AlignCenter)
  266. self.lb_emv_10 = QLabel(self.groupbox_emv_data)
  267. self.lb_emv_10.setText("#10")
  268. self.emv_data_glayout.addWidget(self.lb_emv_10, 3, 5, 1, 1, Qt.AlignCenter)
  269. self.emv_data_hlayout.addWidget(self.groupbox_emv_data)
  270. self.right_layout.addWidget(self.emv_data_widget)
  271. self.main_layout.addWidget(self.right_widget, stretch=2)
  272. main.setCentralWidget(self.central_widget)
  273. self.retranslateUi(main)
  274. QMetaObject.connectSlotsByName(main)
  275. def retranslateUi(self, MainWindow):
  276. _translate = QCoreApplication.translate
  277. MainWindow.setWindowTitle(_translate("MainWindow", "电磁阀控制器"))