158 lines
5.5 KiB
Python
158 lines
5.5 KiB
Python
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel,
|
|
QLineEdit, QComboBox, QFrame, QMessageBox)
|
|
from PyQt5.QtCore import Qt, pyqtSignal
|
|
from PyQt5.QtGui import QPixmap, QFont
|
|
import os
|
|
from src.config import UXUI_ASSETS, WINDOW_SIZE, BACKGROUND_COLOR
|
|
|
|
class LoginScreen(QWidget):
|
|
# Signals for navigation
|
|
login_success = pyqtSignal()
|
|
back_to_selection = pyqtSignal()
|
|
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
# Basic window setup
|
|
self.setGeometry(100, 100, *WINDOW_SIZE)
|
|
self.setStyleSheet(f"background-color: {BACKGROUND_COLOR};")
|
|
|
|
# Main layout
|
|
layout = QVBoxLayout(self)
|
|
|
|
# Logo
|
|
logo_label = QLabel(self)
|
|
logo_path = os.path.join(UXUI_ASSETS, "Assets_png/kneron_logo.png")
|
|
if os.path.exists(logo_path):
|
|
logo_pixmap = QPixmap(logo_path)
|
|
logo_label.setPixmap(logo_pixmap)
|
|
logo_label.setAlignment(Qt.AlignCenter)
|
|
layout.addWidget(logo_label)
|
|
|
|
# Title
|
|
title_label = QLabel("Login", self)
|
|
title_label.setAlignment(Qt.AlignCenter)
|
|
title_label.setFont(QFont("Arial", 24, QFont.Bold))
|
|
layout.addWidget(title_label)
|
|
|
|
# Login form container
|
|
form_container = QFrame(self)
|
|
form_container.setFrameShape(QFrame.StyledPanel)
|
|
form_container.setStyleSheet("""
|
|
QFrame {
|
|
background-color: white;
|
|
border-radius: 10px;
|
|
padding: 20px;
|
|
}
|
|
""")
|
|
form_layout = QVBoxLayout(form_container)
|
|
|
|
# Server type
|
|
server_label = QLabel("Server Authentication Type", self)
|
|
server_label.setFont(QFont("Arial", 12))
|
|
form_layout.addWidget(server_label)
|
|
|
|
self.server_combo = QComboBox(self)
|
|
self.server_combo.addItems(["Standard Password Authentication", "Other Authentication Method"])
|
|
self.server_combo.setFont(QFont("Arial", 10))
|
|
self.server_combo.setMinimumHeight(40)
|
|
form_layout.addWidget(self.server_combo)
|
|
|
|
form_layout.addSpacing(10)
|
|
|
|
# Username
|
|
username_label = QLabel("Username", self)
|
|
username_label.setFont(QFont("Arial", 12))
|
|
form_layout.addWidget(username_label)
|
|
|
|
self.username_input = QLineEdit(self)
|
|
self.username_input.setPlaceholderText("Enter your username")
|
|
self.username_input.setMinimumHeight(40)
|
|
self.username_input.setFont(QFont("Arial", 10))
|
|
form_layout.addWidget(self.username_input)
|
|
|
|
form_layout.addSpacing(10)
|
|
|
|
# Password
|
|
password_label = QLabel("Password", self)
|
|
password_label.setFont(QFont("Arial", 12))
|
|
form_layout.addWidget(password_label)
|
|
|
|
self.password_input = QLineEdit(self)
|
|
self.password_input.setPlaceholderText("Enter your password")
|
|
self.password_input.setEchoMode(QLineEdit.Password)
|
|
self.password_input.setMinimumHeight(40)
|
|
self.password_input.setFont(QFont("Arial", 10))
|
|
form_layout.addWidget(self.password_input)
|
|
|
|
form_layout.addSpacing(20)
|
|
|
|
# Error message (hidden by default)
|
|
self.error_label = QLabel("", self)
|
|
self.error_label.setStyleSheet("color: red;")
|
|
self.error_label.setFont(QFont("Arial", 10))
|
|
self.error_label.hide()
|
|
form_layout.addWidget(self.error_label)
|
|
|
|
# Buttons
|
|
button_layout = QHBoxLayout()
|
|
|
|
back_button = QPushButton("Back", self)
|
|
back_button.setMinimumHeight(40)
|
|
back_button.setFont(QFont("Arial", 12))
|
|
back_button.setStyleSheet("""
|
|
QPushButton {
|
|
background-color: #757575;
|
|
color: white;
|
|
border-radius: 5px;
|
|
padding: 5px 15px;
|
|
}
|
|
QPushButton:hover {
|
|
background-color: #616161;
|
|
}
|
|
""")
|
|
back_button.clicked.connect(self.back_to_selection.emit)
|
|
|
|
login_button = QPushButton("Login", self)
|
|
login_button.setMinimumHeight(40)
|
|
login_button.setFont(QFont("Arial", 12))
|
|
login_button.setStyleSheet("""
|
|
QPushButton {
|
|
background-color: #1E88E5;
|
|
color: white;
|
|
border-radius: 5px;
|
|
padding: 5px 15px;
|
|
}
|
|
QPushButton:hover {
|
|
background-color: #1976D2;
|
|
}
|
|
""")
|
|
login_button.clicked.connect(self.attempt_login)
|
|
|
|
button_layout.addWidget(back_button)
|
|
button_layout.addWidget(login_button)
|
|
|
|
form_layout.addLayout(button_layout)
|
|
|
|
# Add form to main layout
|
|
layout.addWidget(form_container, 1)
|
|
|
|
def attempt_login(self):
|
|
username = self.username_input.text()
|
|
password = self.password_input.text()
|
|
|
|
# For demo purposes, use a simple validation
|
|
if not username or not password:
|
|
self.show_error("Please enter both username and password")
|
|
return
|
|
|
|
# Simulate login success (in a real app, you would validate with your server)
|
|
# For demo, accept any non-empty username/password
|
|
self.login_success.emit()
|
|
|
|
def show_error(self, message):
|
|
self.error_label.setText(message)
|
|
self.error_label.show()
|