From 6a1c76798dea2b5ea6a30aab7f8ef2b4834c6f69 Mon Sep 17 00:00:00 2001 From: Thastertyn Date: Tue, 7 Jan 2025 21:23:55 +0100 Subject: [PATCH] [main] Updated design for tab view, prepared for other tabs and general tweaks to design --- src/ui/book_editor/book_editor.py | 19 +++++ src/ui/dashboard/book_list_entry.py | 27 +++++++ src/ui/{ => dashboard}/dashboard.py | 99 +++++++++---------------- src/ui/member_editor/member_editor.py | 19 +++++ src/ui/window.py | 103 ++++++++++++++++++++++++++ 5 files changed, 201 insertions(+), 66 deletions(-) create mode 100644 src/ui/book_editor/book_editor.py create mode 100644 src/ui/dashboard/book_list_entry.py rename src/ui/{ => dashboard}/dashboard.py (52%) create mode 100644 src/ui/member_editor/member_editor.py create mode 100644 src/ui/window.py diff --git a/src/ui/book_editor/book_editor.py b/src/ui/book_editor/book_editor.py new file mode 100644 index 0000000..fb321af --- /dev/null +++ b/src/ui/book_editor/book_editor.py @@ -0,0 +1,19 @@ +from PySide6.QtGui import QGuiApplication, QAction +from PySide6.QtQml import QQmlApplicationEngine +from PySide6 import QtWidgets, QtCore + +class BookEditor(QtWidgets.QWidget): + def __init__(self): + super().__init__() + + # Central widget and layout + main_layout = QtWidgets.QVBoxLayout(self) + + # Title label + title_label = QtWidgets.QLabel("Books", self) + title_label.setAlignment(QtCore.Qt.AlignCenter) + title_label.setStyleSheet("font-size: 20px; font-weight: bold; color: #0078D4;") + main_layout.addWidget(title_label) + + self.setLayout(main_layout) + diff --git a/src/ui/dashboard/book_list_entry.py b/src/ui/dashboard/book_list_entry.py new file mode 100644 index 0000000..fd7d097 --- /dev/null +++ b/src/ui/dashboard/book_list_entry.py @@ -0,0 +1,27 @@ +from PySide6.QtGui import QGuiApplication, QAction +from PySide6.QtQml import QQmlApplicationEngine +from PySide6 import QtWidgets, QtCore + +from models.book import BookStatusEnum + +STATUS_TO_COLOR_MAP = { + BookStatusEnum.available: "highlight", + BookStatusEnum.borrowed: "highlighted-text", + BookStatusEnum.reserved: "base" +} + +class BookListEntry(QtWidgets.QWidget): + def __init__(self, title, status): + super().__init__() + + layout = QtWidgets.QHBoxLayout(self) + + book_label = QtWidgets.QLabel(title) + layout.addWidget(book_label) + + status_label = QtWidgets.QLabel(status) + status_label.setStyleSheet(f"color: palette({STATUS_TO_COLOR_MAP[status]});") + layout.addWidget(status_label) + + + self.setLayout(layout) diff --git a/src/ui/dashboard.py b/src/ui/dashboard/dashboard.py similarity index 52% rename from src/ui/dashboard.py rename to src/ui/dashboard/dashboard.py index ff82ffa..304e2bf 100644 --- a/src/ui/dashboard.py +++ b/src/ui/dashboard/dashboard.py @@ -3,37 +3,50 @@ from PySide6.QtQml import QQmlApplicationEngine from PySide6 import QtWidgets, QtCore from ui.settings import SettingsDialog - -class LibraryDashboard(QtWidgets.QMainWindow): +class LibraryDashboard(QtWidgets.QWidget): 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) + main_layout = QtWidgets.QVBoxLayout(self) # Title label - title_label = QtWidgets.QLabel("Library Dashboard", self) + title_label = QtWidgets.QLabel("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) + # Search bar + self.search_input = QtWidgets.QLineEdit() + self.search_input.setPlaceholderText("Type to search...") + self.search_input.textChanged.connect(self.filter_books) + main_layout.addWidget(self.search_input) + + 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.books = ["Book One", "Book Two", "Book Three", "Book Four", + "Book Five", "Book Six", "Book Seven", "Book Eight"] + + self.available_books_list.addItems(self.books) self.available_books_list.itemClicked.connect(self.edit_book) + self.available_books_list.setStyleSheet(""" + QListWidget { + font-size: 14px; + } + QListWidget::item { + padding: 5px; + } + QListWidget::item:hover { + background-color: palette(highlight); + color: palette(highlighted-text); + } + """) main_layout.addWidget(self.available_books_list) # Borrowed books list @@ -58,6 +71,12 @@ class LibraryDashboard(QtWidgets.QMainWindow): main_layout.addLayout(button_layout) + def filter_books(self, text): + """Filter the available books list based on the search input.""" + self.available_books_list.clear() + filtered_books = [book for book in self.books if text.lower() in book.lower()] + self.available_books_list.addItems(filtered_books) + # Slots for button actions def edit_book(self, item): QtWidgets.QMessageBox.information(self, "Edit Book", f"Edit details for '{item.text()}'.") @@ -71,55 +90,3 @@ class LibraryDashboard(QtWidgets.QMainWindow): 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.") \ No newline at end of file diff --git a/src/ui/member_editor/member_editor.py b/src/ui/member_editor/member_editor.py new file mode 100644 index 0000000..75b68d1 --- /dev/null +++ b/src/ui/member_editor/member_editor.py @@ -0,0 +1,19 @@ +from PySide6.QtGui import QGuiApplication, QAction +from PySide6.QtQml import QQmlApplicationEngine +from PySide6 import QtWidgets, QtCore + +class MemberEditor(QtWidgets.QWidget): + def __init__(self): + super().__init__() + + # Central widget and layout + main_layout = QtWidgets.QVBoxLayout(self) + + # Title label + title_label = QtWidgets.QLabel("Members", self) + title_label.setAlignment(QtCore.Qt.AlignCenter) + title_label.setStyleSheet("font-size: 20px; font-weight: bold; color: #0078D4;") + main_layout.addWidget(title_label) + + self.setLayout(main_layout) + diff --git a/src/ui/window.py b/src/ui/window.py new file mode 100644 index 0000000..6a3d30d --- /dev/null +++ b/src/ui/window.py @@ -0,0 +1,103 @@ +from PySide6.QtGui import QGuiApplication, QAction, QIcon +from PySide6.QtQml import QQmlApplicationEngine +from PySide6 import QtWidgets, QtCore + +from ui.dashboard.dashboard import LibraryDashboard +from ui.book_editor.book_editor import BookEditor +from ui.member_editor.member_editor import MemberEditor + +from ui.settings import SettingsDialog + +class LibraryWindow(QtWidgets.QMainWindow): + def __init__(self): + super().__init__() + + # Set up main window properties + self.setWindowTitle("Library App") + self.setGeometry(0, 0, 800, 600) + + self.center_window() + + # Set up menu bar + self.create_menu_bar() + + # Central widget and layout + central_widget = QtWidgets.QTabWidget() + self.setCentralWidget(central_widget) + + central_widget.addTab(LibraryDashboard(), "Dashboard") + central_widget.addTab(BookEditor(), "Books") + central_widget.addTab(MemberEditor(), "Members") + + + def center_window(self): + # Get the screen geometry + screen = QtWidgets.QApplication.primaryScreen() + screen_geometry = screen.geometry() + + # Get the dimensions of the window + window_geometry = self.frameGeometry() + + # Calculate the center point of the screen + center_point = screen_geometry.center() + + # Move the window geometry to the center of the screen + window_geometry.moveCenter(center_point) + + # Move the window to the calculated geometry + self.move(window_geometry.topLeft()) + + + + 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.setShortcut("Ctrl+Q") + 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.") \ No newline at end of file