From 11bd24d22417f81b4abf29d1b0835e9002a26216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20Zi=C3=B3=C5=82kowski?= Date: Sun, 15 Sep 2024 18:36:12 +0200 Subject: [PATCH] make rows slimmer, enable shutter stopping, bump max shutters to 8 (#277) --- tdmgr/GUI/delegates/devices.py | 34 +++++++++++----------------------- tdmgr/GUI/devices.py | 7 +++++-- tdmgr/GUI/widgets.py | 2 +- tdmgr/models/devices.py | 4 ---- tdmgr/util/__init__.py | 6 +++--- 5 files changed, 20 insertions(+), 33 deletions(-) diff --git a/tdmgr/GUI/delegates/devices.py b/tdmgr/GUI/delegates/devices.py index 8412ef8..f7ecfad 100644 --- a/tdmgr/GUI/delegates/devices.py +++ b/tdmgr/GUI/delegates/devices.py @@ -25,9 +25,7 @@ class RectSpacing: RECT_ADJUSTMENT = (2, 2, -1, -1) -SHUTTER_RECT_SIZE = QSize( - RECT_SIZE.width() * 3 + RectSpacing.h * 2, RECT_SIZE.height() * 2 + RectSpacing.v -) +SHUTTER_RECT_SIZE = QSize(RECT_SIZE.width() * 2 + RectSpacing.h * 2, RECT_SIZE.height()) def get_pixmap_for_rssi(rssi: int) -> QPixmap: @@ -73,7 +71,7 @@ def get_relays_height(): return 6 + self.get_relays_rect_size(relay_data).height() return 0 - hint_height = max(42, get_relays_height(), 6 + SHUTTER_RECT_SIZE.height()) + hint_height = max(28, get_relays_height()) return QSize(QStyledItemDelegate().sizeHint(option, index).width(), hint_height) return QStyledItemDelegate().sizeHint(option, index) @@ -218,17 +216,13 @@ def paint(self, p: QPainter, option, index): def draw_rssi_pixmap(self, index, option, p): p.save() px = self.rssi_offline - rssi = 'offln' if index.data(DeviceRoles.LWTRole): rssi = index.data(DeviceRoles.RSSIRole) px = get_pixmap_for_rssi(rssi) - px_y = option.rect.y() + (option.rect.height() - 38) // 2 + px_y = option.rect.y() + (option.rect.height() - 24) // 2 px_rect = QRect(option.rect.x() + 2, px_y, 24, 24) p.drawPixmap(px_rect, px.scaled(24, 24)) - rssi_rect = QRect(option.rect.x() + 2, px_rect.y() + px_rect.height() + 2, 24, 12) - p.setFont(self.font_8pt) - p.drawText(rssi_rect, Qt.AlignCenter, str(rssi)) p.restore() def draw_relay_state(self, p: QPainter, target_rect: QRect, relay_data: dict): @@ -259,32 +253,26 @@ def draw_shutters_state(self, p: QPainter, target_rect: QRect, shutter_pos_data: title_rect = QRect(rect) title_rect.setHeight(RECT_SIZE.height()) - state_rect = QRect(rect) - state_rect.moveTop(title_rect.bottom() + 1) - state_rect.setBottom(rect.bottom()) - state_rect.adjust(*RECT_ADJUSTMENT) - - p.drawText(title_rect, Qt.AlignCenter, f'Shutter {shutter}') - direction = shutter_state['Direction'] + arrow_direction = {-1: ARROW_DN, 1: ARROW_UP} + position = ( - 'CLOSED' + 'CLS' if shutter_state['Position'] == 0 - else 'OPEN' if shutter_state['Position'] == 100 else shutter_state['Position'] + else 'OPN' if shutter_state['Position'] == 100 else shutter_state['Position'] ) - arrow_direction = {-1: ARROW_DN, 1: ARROW_UP} - if direction != 0: p.save() p.setPen(self.hltext_pen) - p.fillRect(state_rect, GREEN) - p.drawText(state_rect, Qt.AlignCenter, f"{arrow_direction[direction]} {position}") + p.fillRect(title_rect, GREEN) + p.drawText(title_rect, Qt.AlignCenter, f"{arrow_direction[direction]} {position}") p.restore() else: - p.drawText(state_rect, Qt.AlignCenter, f"{position}") + p.drawText(title_rect, Qt.AlignCenter, f'SHT{shutter} {position}') for r in [title_rect, rect]: p.drawRect(r) + shutter_col += 1 def draw_rssi_rect(self, p: QPainter, rect, index): diff --git a/tdmgr/GUI/devices.py b/tdmgr/GUI/devices.py index 60d0038..0939547 100644 --- a/tdmgr/GUI/devices.py +++ b/tdmgr/GUI/devices.py @@ -198,7 +198,7 @@ def create_actions(self): self.agShutters = QActionGroup(self) self.agShutters.setVisible(False) self.agShutters.setExclusive(False) - for shutter_idx in range(1, 5): + for shutter_idx in range(1, 9): for idx, arrow in enumerate([ARROW_UP, ARROW_DN]): px = make_relay_pixmap(arrow) self.agShutters.addAction( @@ -410,7 +410,10 @@ def toggle_power_all(self, action): def move_shutter(self, action): idx = 1 + self.agShutters.actions().index(action) shutter = (idx + 1) // 2 - action = "ShutterClose" if idx % 2 == 0 else "ShutterOpen" + direction = self.device.p[f"Shutter{shutter}"]["Direction"] + action = ( + "ShutterStop" if direction != 0 else "ShutterClose" if idx % 2 == 0 else "ShutterOpen" + ) self.mqtt.publish(self.device.cmnd_topic(f"{action}{shutter}")) def set_color(self): diff --git a/tdmgr/GUI/widgets.py b/tdmgr/GUI/widgets.py index 9c7f506..46a1c5d 100644 --- a/tdmgr/GUI/widgets.py +++ b/tdmgr/GUI/widgets.py @@ -209,7 +209,7 @@ def setupColumns(self, columns, hidden=None): def setupView(self, view): for i, c in enumerate(view): - if c in ("Device", "Module", "Topic", "FullTopic"): + if c in ("Device",): self.horizontalHeader().setSectionResizeMode(i, QHeaderView.Stretch) else: self.horizontalHeader().setSectionResizeMode(i, QHeaderView.ResizeToContents) diff --git a/tdmgr/models/devices.py b/tdmgr/models/devices.py index 0a4399e..7bf5c5f 100644 --- a/tdmgr/models/devices.py +++ b/tdmgr/models/devices.py @@ -33,10 +33,6 @@ def deviceAtRow(self, row): def notify_change(self, d, key): row = self.tasmota_env.devices.index(d) - # if key.startswith("POWER") and "Power" in self.columns: - # power_idx = self.columns.index("Power") - # idx = self.index(row, power_idx) - # self.dataChanged.emit(idx, idx) if any( [ diff --git a/tdmgr/util/__init__.py b/tdmgr/util/__init__.py index b0c6eb6..1a207f4 100644 --- a/tdmgr/util/__init__.py +++ b/tdmgr/util/__init__.py @@ -62,7 +62,7 @@ def initial_commands(): commands = [(command, "") for command in commands] commands += [("status", "0"), ("gpios", "255")] - for sht in range(4): + for sht in range(8): commands.append([f"shutterrelay{sht + 1}", ""]) commands.append([f"shutterposition{sht + 1}", ""]) @@ -343,12 +343,12 @@ def power(self): def shutters(self) -> dict: return { k: self.p[f"ShutterRelay{k}"] - for k in range(1, 5) + for k in range(1, 9) if f"ShutterRelay{k}" in self.p and self.p[f"ShutterRelay{k}"] != 0 } def shutter_positions(self) -> dict: - x = {k: self.p[f"Shutter{k}"] for k in range(1, 5) if f"Shutter{k}" in self.p} + x = {k: self.p[f"Shutter{k}"] for k in range(1, 9) if f"Shutter{k}" in self.p} return x def pwm(self):