[main] Changed from qml UI to QWidgets

This commit is contained in:
Thastertyn 2025-01-07 15:25:29 +01:00
parent 1c860b70e8
commit 427cd25853
5 changed files with 196 additions and 34 deletions

View File

@ -1,32 +0,0 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Window {
width: 300
height: 200
visible: true
title: "Hello World"
readonly property list<string> texts: ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир"]
function setText() {
var i = Math.round(Math.random() * 3);
text.text = texts[i];
}
ColumnLayout {
anchors.fill: parent
Text {
id: text
text: "Hello World"
Layout.alignment: Qt.AlignHCenter
}
Button {
text: "Click me"
Layout.alignment: Qt.AlignHCenter
onClicked: setText()
}
}
}

0
src/ui/__init__.py Normal file
View File

125
src/ui/dashboard.py Normal file
View File

@ -0,0 +1,125 @@
from PySide6.QtGui import QGuiApplication, QAction
from PySide6.QtQml import QQmlApplicationEngine
from PySide6 import QtWidgets, QtCore
from ui.settings import SettingsDialog
class LibraryDashboard(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
# Set up main window properties
self.setWindowTitle("Library Dashboard")
self.setGeometry(100, 100, 400, 400)
# Set up menu bar
self.create_menu_bar()
# Central widget and layout
central_widget = QtWidgets.QWidget()
self.setCentralWidget(central_widget)
main_layout = QtWidgets.QVBoxLayout(central_widget)
# Title label
title_label = QtWidgets.QLabel("Library Dashboard", self)
title_label.setAlignment(QtCore.Qt.AlignCenter)
title_label.setStyleSheet("font-size: 20px; font-weight: bold; color: #0078D4;")
main_layout.addWidget(title_label)
# Available books list
available_label = QtWidgets.QLabel("Available Books")
available_label.setStyleSheet("font-size: 16px;")
main_layout.addWidget(available_label)
self.available_books_list = QtWidgets.QListWidget()
self.available_books_list.addItems(["Book One", "Book Two", "Book Three", "Book Four","Book One", "Book Two", "Book Three", "Book Four","Book One", "Book Two", "Book Three", "Book Four"])
self.available_books_list.itemClicked.connect(self.edit_book)
main_layout.addWidget(self.available_books_list)
# Borrowed books list
borrowed_label = QtWidgets.QLabel("Currently Borrowed Books")
borrowed_label.setStyleSheet("font-size: 16px;")
main_layout.addWidget(borrowed_label)
self.borrowed_books_list = QtWidgets.QListWidget()
self.borrowed_books_list.addItems(["Book Two", "Book Four"])
self.borrowed_books_list.itemClicked.connect(self.return_book)
main_layout.addWidget(self.borrowed_books_list)
# Buttons for actions
button_layout = QtWidgets.QHBoxLayout()
register_member_button = QtWidgets.QPushButton("Add New Member")
register_member_button.clicked.connect(self.register_member)
button_layout.addWidget(register_member_button)
add_borrow_record_button = QtWidgets.QPushButton("Add Borrow Record")
add_borrow_record_button.clicked.connect(self.add_borrow_record)
button_layout.addWidget(add_borrow_record_button)
main_layout.addLayout(button_layout)
# Slots for button actions
def edit_book(self, item):
QtWidgets.QMessageBox.information(self, "Edit Book", f"Edit details for '{item.text()}'.")
def return_book(self, item):
QtWidgets.QMessageBox.information(self, "Return Book", f"Mark '{item.text()}' as returned.")
def register_member(self):
QtWidgets.QMessageBox.information(self, "Add Member", "Open dialog to register a new member.")
def add_borrow_record(self):
QtWidgets.QMessageBox.information(self, "Add Borrow Record", "Open dialog to add a borrow record.")
def create_menu_bar(self):
# Create the menu bar
menu_bar = self.menuBar()
# File menu
file_menu = menu_bar.addMenu("File")
import_action = QAction("Import", self)
import_action.triggered.connect(self.import_data)
file_menu.addAction(import_action)
export_action = QAction("Export", self)
export_action.triggered.connect(self.export_data)
file_menu.addAction(export_action)
file_menu.addSeparator()
exit_action = QAction("Exit", self)
exit_action.triggered.connect(self.close)
file_menu.addAction(exit_action)
# Edit menu
edit_menu = menu_bar.addMenu("Edit")
preferences = QAction("Preferences", self)
preferences.triggered.connect(self.edit_preferences)
edit_menu.addAction(preferences)
# Help menu
help_menu = menu_bar.addMenu("Help")
about_action = QAction("About", self)
about_action.triggered.connect(self.about)
help_menu.addAction(about_action)
# Menu action slots
def edit_preferences(self):
dialog = SettingsDialog(parent=self)
if dialog.exec() == QtWidgets.QDialog.Accepted:
print("Settings were saved.")
def open_file(self):
QtWidgets.QMessageBox.information(self, "Open File", "Open an existing file.")
def import_data(self):
pass
def export_data(self):
pass
def about(self):
QtWidgets.QMessageBox.information(self, "About", "Library Dashboard v1.0\nDeveloped by You.")

View File

@ -1,2 +0,0 @@
module Example
Main 254.0 Main.qml

71
src/ui/settings.py Normal file
View File

@ -0,0 +1,71 @@
import sys
from PySide6 import QtWidgets
class SettingsDialog(QtWidgets.QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Settings")
self.setMinimumSize(400, 300)
# Position the dialog relative to the parent (main window)
if parent:
x = parent.geometry().x() + parent.geometry().width() // 2 - self.width() // 2
y = parent.geometry().y() + parent.geometry().height() // 2 - self.height() // 2
self.move(x, y)
# Create layout
layout = QtWidgets.QVBoxLayout(self)
# Checkbox: Enable Notifications
self.notifications_checkbox = QtWidgets.QCheckBox("Enable Notifications")
layout.addWidget(self.notifications_checkbox)
# Checkbox: Dark Mode
self.dark_mode_checkbox = QtWidgets.QCheckBox("Enable Dark Mode")
layout.addWidget(self.dark_mode_checkbox)
# Dropdown: Language Selection
self.language_label = QtWidgets.QLabel("Language:")
layout.addWidget(self.language_label)
self.language_dropdown = QtWidgets.QComboBox()
self.language_dropdown.addItems(["English", "Spanish", "French", "German"])
layout.addWidget(self.language_dropdown)
# Dropdown: Theme Selection
self.theme_label = QtWidgets.QLabel("Theme:")
layout.addWidget(self.theme_label)
self.theme_dropdown = QtWidgets.QComboBox()
self.theme_dropdown.addItems(["Light", "Dark", "System Default"])
layout.addWidget(self.theme_dropdown)
# Buttons
button_layout = QtWidgets.QHBoxLayout()
self.save_button = QtWidgets.QPushButton("Save")
self.save_button.clicked.connect(self.save_settings)
button_layout.addWidget(self.save_button)
self.cancel_button = QtWidgets.QPushButton("Cancel")
self.cancel_button.clicked.connect(self.reject)
button_layout.addWidget(self.cancel_button)
layout.addLayout(button_layout)
def save_settings(self):
# Example of how to fetch settings
notifications = self.notifications_checkbox.isChecked()
dark_mode = self.dark_mode_checkbox.isChecked()
language = self.language_dropdown.currentText()
theme = self.theme_dropdown.currentText()
print("Settings Saved:")
print(f"Notifications: {notifications}")
print(f"Dark Mode: {dark_mode}")
print(f"Language: {language}")
print(f"Theme: {theme}")
self.accept()