From a4733d3578e86c1b9546b78863fd75cfd3cb2b5d Mon Sep 17 00:00:00 2001 From: Tobias Petrich Date: Tue, 19 Jul 2022 03:18:17 +0200 Subject: [PATCH] implement class for stack elements and add poetry dependency management --- poetry.lock | 66 +++++++++++++++++ pyproject.toml | 15 ++++ test.py | 196 ++++++++++++++++++++++--------------------------- 3 files changed, 169 insertions(+), 108 deletions(-) create mode 100644 poetry.lock create mode 100644 pyproject.toml diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..5c77a36 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,66 @@ +[[package]] +name = "pyqt5" +version = "5.15.7" +description = "Python bindings for the Qt cross platform application toolkit" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +PyQt5-Qt5 = ">=5.15.0" +PyQt5-sip = ">=12.11,<13" + +[[package]] +name = "pyqt5-qt5" +version = "5.15.2" +description = "The subset of a Qt installation needed by PyQt5." +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "pyqt5-sip" +version = "12.11.0" +description = "The sip module support for PyQt5" +category = "main" +optional = false +python-versions = ">=3.7" + +[metadata] +lock-version = "1.1" +python-versions = "^3.10" +content-hash = "ce4feb2a6a42610a01d5e986a40980aaf9f73c3fdc2368f55ec75e70f39c70cf" + +[metadata.files] +pyqt5 = [ + {file = "PyQt5-5.15.7-cp37-abi3-macosx_10_13_x86_64.whl", hash = "sha256:1a793748c60d5aff3850b7abf84d47c1d41edb11231b7d7c16bef602c36be643"}, + {file = "PyQt5-5.15.7-cp37-abi3-manylinux1_x86_64.whl", hash = "sha256:e319c9d8639e0729235c1b09c99afdadad96fa3dbd8392ab561b5ab5946ee6ef"}, + {file = "PyQt5-5.15.7-cp37-abi3-win32.whl", hash = "sha256:08694f0a4c7d4f3d36b2311b1920e6283240ad3b7c09b515e08262e195dcdf37"}, + {file = "PyQt5-5.15.7-cp37-abi3-win_amd64.whl", hash = "sha256:232fe5b135a095cbd024cf341d928fc672c963f88e6a52b0c605be8177c2fdb5"}, + {file = "PyQt5-5.15.7.tar.gz", hash = "sha256:755121a52b3a08cb07275c10ebb96576d36e320e572591db16cfdbc558101594"}, +] +pyqt5-qt5 = [ + {file = "PyQt5_Qt5-5.15.2-py3-none-macosx_10_13_intel.whl", hash = "sha256:76980cd3d7ae87e3c7a33bfebfaee84448fd650bad6840471d6cae199b56e154"}, + {file = "PyQt5_Qt5-5.15.2-py3-none-manylinux2014_x86_64.whl", hash = "sha256:1988f364ec8caf87a6ee5d5a3a5210d57539988bf8e84714c7d60972692e2f4a"}, + {file = "PyQt5_Qt5-5.15.2-py3-none-win32.whl", hash = "sha256:9cc7a768b1921f4b982ebc00a318ccb38578e44e45316c7a4a850e953e1dd327"}, + {file = "PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl", hash = "sha256:750b78e4dba6bdf1607febedc08738e318ea09e9b10aea9ff0d73073f11f6962"}, +] +pyqt5-sip = [ + {file = "PyQt5_sip-12.11.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:f1f9e312ff8284d6dfebc5366f6f7d103f84eec23a4da0be0482403933e68660"}, + {file = "PyQt5_sip-12.11.0-cp310-cp310-manylinux1_x86_64.whl", hash = "sha256:4031547dfb679be309094bfa79254f5badc5ddbe66b9ad38e319d84a7d612443"}, + {file = "PyQt5_sip-12.11.0-cp310-cp310-win32.whl", hash = "sha256:ad21ca0ee8cae2a41b61fc04949dccfab6fe008749627d94e8c7078cb7a73af1"}, + {file = "PyQt5_sip-12.11.0-cp310-cp310-win_amd64.whl", hash = "sha256:3126c84568ab341c12e46ded2230f62a9a78752a70fdab13713f89a71cd44f73"}, + {file = "PyQt5_sip-12.11.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0f77655c62ec91d47c2c99143f248624d44dd2d8a12d016e7c020508ad418aca"}, + {file = "PyQt5_sip-12.11.0-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:ec5e9ef78852e1f96f86d7e15c9215878422b83dde36d44f1539a3062942f19c"}, + {file = "PyQt5_sip-12.11.0-cp37-cp37m-win32.whl", hash = "sha256:d12b81c3a08abf7657a2ebc7d3649852a1f327eb2146ebadf45930486d32e920"}, + {file = "PyQt5_sip-12.11.0-cp37-cp37m-win_amd64.whl", hash = "sha256:b69a1911f768b489846335e31e49eb34795c6b5a038ca24d894d751e3b0b44da"}, + {file = "PyQt5_sip-12.11.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:51e377789d59196213eddf458e6927f33ba9d217b614d17d20df16c9a8b2c41c"}, + {file = "PyQt5_sip-12.11.0-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:4e5c1559311515291ea0ab0635529f14536954e3b973a7c7890ab7e4de1c2c23"}, + {file = "PyQt5_sip-12.11.0-cp38-cp38-win32.whl", hash = "sha256:9bca450c5306890cb002fe36bbca18f979dd9e5b810b766dce8e3ce5e66ba795"}, + {file = "PyQt5_sip-12.11.0-cp38-cp38-win_amd64.whl", hash = "sha256:f6b72035da4e8fecbb0bc4a972e30a5674a9ad5608dbddaa517e983782dbf3bf"}, + {file = "PyQt5_sip-12.11.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:9356260d4feb60dbac0ab66f8a791a0d2cda1bf98c9dec8e575904a045fbf7c5"}, + {file = "PyQt5_sip-12.11.0-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:205f3e1b3eea3597d8e878936c1a06e04bd23a59e8b179ee806465d72eea3071"}, + {file = "PyQt5_sip-12.11.0-cp39-cp39-win32.whl", hash = "sha256:686071be054e5be6ca5aaaef7960931d4ba917277e839e2e978c7cbe3f43bb6e"}, + {file = "PyQt5_sip-12.11.0-cp39-cp39-win_amd64.whl", hash = "sha256:42320e7a94b1085ed85d49794ed4ccfe86f1cae80b44a894db908a8aba2bc60e"}, + {file = "PyQt5_sip-12.11.0.tar.gz", hash = "sha256:b4710fd85b57edef716cc55fae45bfd5bfac6fc7ba91036f1dcc3f331ca0eb39"}, +] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9f88869 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "charger-display" +version = "0.1.0" +description = "" +authors = ["Your Name "] + +[tool.poetry.dependencies] +python = "^3.10" +PyQt5 = "^5.15.7" + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/test.py b/test.py index 4e0470b..75c4b76 100644 --- a/test.py +++ b/test.py @@ -65,6 +65,60 @@ class AccumulatorData: self.panic_errorcode = self.panic_errorarg = 0 +class StackGuiElement: + title: str + min_voltage_label: QLabel + max_voltage_label: QLabel + min_temp_label: QLabel + max_temp_label: QLabel + groupBox: QGroupBox + + def __init__(self, title: str): + self.title = title + self.min_voltage_label = QLabel() + self.max_voltage_label = QLabel() + self.min_temp_label = QLabel() + self.max_temp_label = QLabel() + self.groupBox = QGroupBox() + self.__post__init__() + + def __post__init__(self): + l1 = QLabel("Min Voltage [V]") + l2 = QLabel("Max Voltage [V]") + l3 = QLabel("Min Temperature [°C]") + l4 = QLabel("Max Temperature [°C]") + + l1.setAlignment(Qt.AlignLeft) + l2.setAlignment(Qt.AlignLeft) + l3.setAlignment(Qt.AlignLeft) + l4.setAlignment(Qt.AlignLeft) + + self.min_voltage_label.setAlignment(Qt.AlignLeft) + self.max_voltage_label.setAlignment(Qt.AlignLeft) + self.min_temp_label.setAlignment(Qt.AlignLeft) + self.max_temp_label.setAlignment(Qt.AlignLeft) + + grid = QGridLayout() + grid.addWidget(l1, 0, 0) + grid.addWidget(l2, 1, 0) + grid.addWidget(l3, 0, 2) + grid.addWidget(l4, 1, 2) + + grid.addWidget(self.min_voltage_label, 0, 1) + grid.addWidget(self.max_voltage_label, 1, 1) + grid.addWidget(self.min_temp_label, 0, 3) + grid.addWidget(self.max_temp_label, 1, 3) + + self.groupBox.setTitle(self.title) + self.groupBox.setLayout(grid) + + def update_data_from_slave(self, slave: SlaveData): + self.min_voltage_label.setNum(min(slave.cell_voltages)) + self.max_voltage_label.setNum(max(slave.cell_voltages)) + self.min_temp_label.setNum(min(slave.cell_temps)) + self.max_temp_label.setNum(max(slave.cell_temps)) + + def fill_dummy_data(): data.min_voltage = random.uniform(1, 3) data.max_voltage = random.uniform(3, 5) @@ -193,90 +247,19 @@ class Window(QWidget): ### STACKS ### - ### STACK 0 ### - - self.l1_s0 = QLabel("Min Voltage [V]") - self.l1_s0.setAlignment(Qt.AlignLeft) - self.l_min_voltage_s0 = QLabel() - self.l_min_voltage_s0.setNum(min(data.slaves[0].cell_voltages)) - self.l_min_voltage_s0.setAlignment(Qt.AlignLeft) - - self.l2_s0 = QLabel("Max Voltage [V]") - self.l2_s0.setAlignment(Qt.AlignLeft) - self.l_max_voltage_s0 = QLabel() - self.l_max_voltage_s0.setNum(max(data.slaves[0].cell_voltages)) - self.l_max_voltage_s0.setAlignment(Qt.AlignLeft) - - self.l3_s0 = QLabel("Min Temperature [°C]") - self.l3_s0.setAlignment(Qt.AlignLeft) - self.l_min_temp_s0 = QLabel() - self.l_min_temp_s0.setNum(min(data.slaves[0].cell_temps)) - self.l_min_temp_s0.setAlignment(Qt.AlignLeft) - - self.l4_s0 = QLabel("Max Temperature [°C]") - self.l4_s0.setAlignment(Qt.AlignLeft) - self.l_max_temp_s0 = QLabel() - self.l_max_temp_s0.setNum(max(data.slaves[0].cell_temps)) - self.l_max_temp_s0.setAlignment(Qt.AlignLeft) - - grid_stack_s0 = QGridLayout() - grid_stack_s0.addWidget(self.l1_s0, 0, 0) - grid_stack_s0.addWidget(self.l2_s0, 1, 0) - grid_stack_s0.addWidget(self.l3_s0, 0, 2) - grid_stack_s0.addWidget(self.l4_s0, 1, 2) - - grid_stack_s0.addWidget(self.l_min_voltage_s0, 0, 1) - grid_stack_s0.addWidget(self.l_max_voltage_s0, 1, 1) - grid_stack_s0.addWidget(self.l_min_temp_s0, 0, 3) - grid_stack_s0.addWidget(self.l_max_temp_s0, 1, 3) - - groupBox_stack_s0 = QGroupBox("Stack 0") - groupBox_stack_s0.setLayout(grid_stack_s0) - - ### STACK 1 ### - - self.l1_s1 = QLabel("Min Voltage [V]") - self.l1_s1.setAlignment(Qt.AlignLeft) - self.l_min_voltage_s1 = QLabel() - self.l_min_voltage_s1.setNum(min(data.slaves[1].cell_voltages)) - self.l_min_voltage_s1.setAlignment(Qt.AlignLeft) - - self.l2_s1 = QLabel("Max Voltage [V]") - self.l2_s1.setAlignment(Qt.AlignLeft) - self.l_max_voltage_s1 = QLabel() - self.l_max_voltage_s1.setNum(max(data.slaves[1].cell_voltages)) - self.l_max_voltage_s1.setAlignment(Qt.AlignLeft) - - self.l3_s1 = QLabel("Min Temperature [°C]") - self.l3_s1.setAlignment(Qt.AlignLeft) - self.l_min_temp_s1 = QLabel() - self.l_min_temp_s1.setNum(min(data.slaves[1].cell_temps)) - self.l_min_temp_s1.setAlignment(Qt.AlignLeft) - - self.l4_s1 = QLabel("Max Temperature [°C]") - self.l4_s1.setAlignment(Qt.AlignLeft) - self.l_max_temp_s1 = QLabel() - self.l_max_temp_s1.setNum(max(data.slaves[1].cell_temps)) - self.l_max_temp_s1.setAlignment(Qt.AlignLeft) - - grid_stack_s1 = QGridLayout() - grid_stack_s1.addWidget(self.l1_s1, 0, 0) - grid_stack_s1.addWidget(self.l2_s1, 1, 0) - grid_stack_s1.addWidget(self.l3_s1, 0, 2) - grid_stack_s1.addWidget(self.l4_s1, 1, 2) - - grid_stack_s1.addWidget(self.l_min_voltage_s1, 0, 1) - grid_stack_s1.addWidget(self.l_max_voltage_s1, 1, 1) - grid_stack_s1.addWidget(self.l_min_temp_s1, 0, 3) - grid_stack_s1.addWidget(self.l_max_temp_s1, 1, 3) - - groupBox_stack_s1 = QGroupBox("Stack 1") - groupBox_stack_s1.setLayout(grid_stack_s1) + self.stack_gui_elements = [] + for i in range(N_SLAVES): + sge = StackGuiElement(f"Stack {i}") + sge.update_data_from_slave(data.slaves[i]) + self.stack_gui_elements.append(sge) ### Layout Stacks ### + n_slaves_half = N_SLAVES // 2 grid_stacks = QGridLayout() - grid_stacks.addWidget(groupBox_stack_s0, 0, 0) - grid_stacks.addWidget(groupBox_stack_s1, 0, 1) + for i, sge in enumerate(self.stack_gui_elements): + grid_stacks.addWidget( + sge.groupBox, 0 if i < n_slaves_half else 1, i % n_slaves_half + ) groupBox_stacks = QGroupBox("Individual Stacks") groupBox_stacks.setLayout(grid_stacks) @@ -286,36 +269,33 @@ class Window(QWidget): self.setLayout(win) self.setWindowTitle("FT22 Charger Display") + def update(self): + # Accumulator + self.l_min_voltage.setNum(data.min_voltage) + self.l_max_voltage.setNum(data.max_voltage) + self.l_min_temp.setNum(data.min_temp) + self.l_max_temp.setNum(data.max_temp) + self.l_current.setNum(data.current) + self.l_error.setText(str(data.panic)) + self.l_errorcode.setText(str(data.panic_errorcode)) + self.l_errorarg.setText(str(data.panic_errorarg)) -def update_gui(): - # Accumulator - gui.l_min_voltage.setNum(data.min_voltage) - gui.l_max_voltage.setNum(data.max_voltage) - gui.l_min_temp.setNum(data.min_temp) - gui.l_max_temp.setNum(data.max_temp) - gui.l_current.setNum(data.current) - gui.l_error.setText(str(data.panic)) - gui.l_errorcode.setText(str(data.panic_errorcode)) - gui.l_errorarg.setText(str(data.panic_errorarg)) - - # Cells - gui.l_min_voltage_s0.setNum(min(data.slaves[0].cell_voltages)) - gui.l_max_voltage_s0.setNum(max(data.slaves[0].cell_voltages)) - gui.l_min_temp_s0.setNum(min(data.slaves[0].cell_temps)) - gui.l_max_temp_s0.setNum(max(data.slaves[0].cell_temps)) + # Cells + for i, sge in enumerate(self.stack_gui_elements): + sge.update_data_from_slave(data.slaves[i]) -data = AccumulatorData() -app = QApplication(sys.argv) -gui = Window() -gui.show() +if __name__ == "__main__": + data = AccumulatorData() + app = QApplication(sys.argv) + gui = Window() + gui.show() + timer = QTimer() + timer.timeout.connect(gui.update) + timer.timeout.connect(fill_dummy_data) + timer.start(1000) # every 1,000 milliseconds -timer = QTimer() -timer.timeout.connect(update_gui) -timer.timeout.connect(fill_dummy_data) -timer.start(1000) # every 1,000 milliseconds + # update_display() -# update_display() - -sys.exit(app.exec_()) + sys.exit(app.exec_())