KNEO-Academy/src/views/components/device_popup.py

76 lines
2.7 KiB
Python

from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QListWidget, QListWidgetItem
from PyQt5.QtSvg import QSvgWidget
from PyQt5.QtCore import Qt
import os
from src.config import SECONDARY_COLOR, BUTTON_STYLE, UXUI_ASSETS
def create_device_popup(parent, device_controller):
"""Create a popup window for device connection management"""
try:
# Device connection popup window
popup = QWidget(parent)
popup_width = int(parent.width() * 0.67)
popup_height = int(parent.height() * 0.67)
popup.setFixedSize(popup_width, popup_height)
popup.setStyleSheet(f"""
QWidget {{
background-color: {SECONDARY_COLOR};
border-radius: 20px;
padding: 20px;
}}
""")
popup_layout = QVBoxLayout(popup)
popup_layout.setContentsMargins(0, 0, 0, 0)
# Title row
title_layout = QHBoxLayout()
title_layout.setAlignment(Qt.AlignCenter)
title_container = QWidget()
container_layout = QHBoxLayout(title_container)
container_layout.setSpacing(10)
device_icon = QSvgWidget(os.path.join(UXUI_ASSETS, "Assets_svg/ic_window_device.svg"))
device_icon.setFixedSize(35, 35)
container_layout.addWidget(device_icon)
popup_label = QLabel("Device Connection")
popup_label.setStyleSheet("color: white; font-size: 32px;")
container_layout.addWidget(popup_label)
container_layout.setAlignment(Qt.AlignCenter)
title_layout.addWidget(title_container)
popup_layout.addLayout(title_layout)
# Device list
device_list_widget_popup = QListWidget(popup)
popup_layout.addWidget(device_list_widget_popup)
# Store reference to this list widget for later use
parent.device_list_widget_popup = device_list_widget_popup
# Button area
button_layout = QHBoxLayout()
refresh_button = QPushButton("Refresh")
refresh_button.clicked.connect(device_controller.refresh_devices)
refresh_button.setFixedSize(110, 45)
refresh_button.setStyleSheet(BUTTON_STYLE)
button_layout.addWidget(refresh_button)
done_button = QPushButton("Done")
done_button.setStyleSheet(BUTTON_STYLE)
done_button.setFixedSize(110, 45)
done_button.clicked.connect(parent.hide_device_popup)
button_layout.addWidget(done_button)
button_layout.setSpacing(10)
popup_layout.addSpacing(20)
popup_layout.addLayout(button_layout)
return popup
except Exception as e:
print(f"Error in create_device_popup: {e}")
return QWidget(parent)