from PySide6.QtWidgets import ( QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QCheckBox, QGroupBox, QFormLayout ) from PySide6.QtCore import Signal class WebServerWidget(QWidget): """Виджет настроек веб-сервера""" valueChanged = Signal() def __init__(self): super().__init__() self.init_ui() def init_ui(self): layout = QVBoxLayout() # Чекбокс запуска сайта self.start_server_check = QCheckBox("Запускать сайт-панель") self.start_server_check.toggled.connect(self.on_value_changed) layout.addWidget(self.start_server_check) # Пароль администратора group_box = QGroupBox("Пароль администратора") group_layout = QFormLayout() self.password_edit = QLineEdit() self.password_edit.setMaxLength(10) self.password_edit.setPlaceholderText("до 10 символов") self.password_edit.textChanged.connect(self.on_value_changed) # Индикатор длины пароля self.length_label = QLabel("0/10") self.length_label.setStyleSheet("color: #666; font-size: 10px;") password_layout = QHBoxLayout() password_layout.addWidget(self.password_edit) password_layout.addWidget(self.length_label) group_layout.addRow("Пароль:", password_layout) group_box.setLayout(group_layout) layout.addWidget(group_box) # Обновляем индикатор длины self.password_edit.textChanged.connect(self.update_length_indicator) self.setLayout(layout) def on_value_changed(self): """Обработчик изменения значения""" self.valueChanged.emit() def update_length_indicator(self): length = len(self.password_edit.text()) self.length_label.setText(f"{length}/10") if length > 10: self.length_label.setStyleSheet("color: red; font-size: 10px;") else: self.length_label.setStyleSheet("color: green; font-size: 10px;") def get_start_server(self) -> bool: return self.start_server_check.isChecked() def get_password(self) -> str: return self.password_edit.text() def set_start_server(self, value: bool): self.start_server_check.setChecked(value) def set_password(self, password: str): self.password_edit.setText(password[:10])