update design bl

This commit is contained in:
cheykrym 2026-04-01 01:04:02 +03:00
parent 28a920cd94
commit 6d96edbdfc
3 changed files with 70 additions and 3 deletions

View File

@ -30,6 +30,7 @@ class BluetoothDeviceCard(QFrame):
super().__init__(parent)
self._device = device
self._connected = connected
self._busy = False
self.setObjectName("BluetoothDeviceCard")
self.setFrameShape(QFrame.StyledPanel)
@ -96,13 +97,35 @@ class BluetoothDeviceCard(QFrame):
"""Обновить статус подключения."""
self._connected = connected
self._update_status_indicator()
def set_busy(self, busy: bool, action_text: str = ""):
"""Установить состояние выполнения действия."""
self._busy = busy
if busy:
self.setCursor(Qt.WaitCursor)
self.status_label.setText(action_text)
self.status_label.setStyleSheet("color: #fbbf24;") # янтарный для процесса
else:
self.setCursor(Qt.PointingHandCursor)
self._update_status_indicator()
# Обновляем стиль карточки
self.style().unpolish(self)
self.style().polish(self)
def is_busy(self) -> bool:
"""Проверить, выполняется ли действие."""
return self._busy
def _on_remove(self):
"""Обработчик нажатия кнопки удаления."""
if self._busy:
return
self.remove_clicked.emit(self._device.mac)
def mousePressEvent(self, event):
"""Обработка клика по карточке."""
if self._busy:
return # Игнорируем клики во время выполнения действия
if self._connected:
self.disconnect_clicked.emit(self._device.mac)
else:
@ -227,22 +250,38 @@ class BluetoothScreen(QWidget):
"""Подключиться к устройству по MAC."""
if mac not in self._cards:
return
card = self._cards[mac]
if card.is_busy():
return
# Блокируем все карточки
self._set_all_cards_busy(True)
card.set_busy(True, "Подключение...")
success = self._bt_service.connect_device(mac)
if not success:
self.status.setText(f"Статус: ошибка ({self._bt_service.last_error})")
self._settings.setValue("bluetooth/last_mac", mac)
QTimer.singleShot(300, lambda: self._update_card_status(mac))
QTimer.singleShot(300, lambda: self._finish_action(mac))
def _disconnect_device(self, mac: str):
"""Отключить устройство по MAC."""
if mac not in self._cards:
return
card = self._cards[mac]
if card.is_busy():
return
# Блокируем все карточки
self._set_all_cards_busy(True)
card.set_busy(True, "Отключение...")
success = self._bt_service.disconnect_device(mac)
if not success:
self.status.setText(f"Статус: ошибка ({self._bt_service.last_error})")
else:
self.status.setText(f"Статус: отключено от {mac}")
QTimer.singleShot(300, lambda: self._update_card_status(mac))
QTimer.singleShot(300, lambda: self._finish_action(mac))
def _remove_device(self, mac: str):
"""Удалить устройство из списка сопряженных."""
@ -258,12 +297,32 @@ class BluetoothScreen(QWidget):
ok_object_name="ConfirmOkDanger",
)
if dialog.exec() == ConfirmDialog.Accepted:
# Блокируем все карточки
self._set_all_cards_busy(True)
device.set_busy(True, "Удаление...")
success = self._bt_service.remove_device(mac)
if success:
self.status.setText(f"Статус: устройство {mac} удалено")
QTimer.singleShot(300, self.refresh_list)
else:
self.status.setText(f"Статус: ошибка удаления ({self._bt_service.last_error})")
self._set_all_cards_busy(False)
def _finish_action(self, mac: str):
"""Завершить действие и обновить статус."""
self._set_all_cards_busy(False)
self.refresh_list()
def _set_all_cards_busy(self, busy: bool):
"""Установить состояние busy для всех карточек."""
for card in self._cards.values():
if busy:
card.setProperty("selected", True)
else:
card.setProperty("selected", False)
card.style().unpolish(card)
card.style().polish(card)
def _update_card_status(self, mac: str):
"""Обновить статус на карточке устройства."""

View File

@ -150,6 +150,10 @@ QScrollArea > QWidget > QWidget { background: transparent; }
border: 1px solid #E5E7EB;
}
#BluetoothDeviceCard:hover { background: #F9FAFB; }
#BluetoothDeviceCard[selected="true"] {
background: #EFF6FF;
border: 2px solid #3B82F6;
}
#BluetoothDeviceName { color: #111827; background: transparent; }
#BluetoothDeviceMac { color: rgba(107,114,128,0.95); background: transparent; }
#BluetoothDeviceStatus { color: rgba(107,114,128,0.95); background: transparent; }

View File

@ -139,6 +139,10 @@ QScrollArea > QWidget > QWidget { background: transparent; }
border-radius: 14px;
}
#BluetoothDeviceCard:hover { background: #1B2330; }
#BluetoothDeviceCard[selected="true"] {
background: #2A3A52;
border: 2px solid #3B82F6;
}
#BluetoothDeviceName { color: #E6EAF0; background: transparent; }
#BluetoothDeviceMac { color: rgba(138,147,166,0.95); background: transparent; }
#BluetoothDeviceStatus { color: rgba(138,147,166,0.95); background: transparent; }