In the initial implementation of the Pybrary project, the entire functionality was contained within a single script. This included both the user interface (UI) logic and the library management logic. To improve the modularity, readability, and maintainability of the code, we refactored the project into multiple classes, each with a specific responsibility.
-
Separation of Concerns:
- The original code had all the logic for managing the library and the UI in one place. We separated these concerns by creating distinct classes for managing the library data and handling the UI.
-
New Classes:
- LibraryManager: This class is responsible for all operations related to managing the library data, such as adding, deleting, searching, loading, and saving books.
- LibraryGUI: This class is responsible for creating and managing the graphical user interface (GUI) of the application.
- Librarian: This class handles the storing, deleting and overwriting of books, so it is not done in the GUI directly.
- Pybrary: This class integrates all the components together.
- File:
library_manager.py - Responsibilities:
- Manage the library data.
- Add, delete, and search for books.
- Load and save data to/from a CSV file.
- File:
librarian.py - Responsibilities:
- Call functions of the
LibraryManagerwhen buttons are pressed.
- Call functions of the
- File:
gui.py - Responsibilities:
- Create and manage the graphical user interface.
- Handle user interactions and events.
- File:
pybrary.py - Responsibilities:
- Integrate all the components (
LibraryManager,LibraryGUI, andLibrarian) together. - Serve as the entry point for the application.
- Integrate all the components (
-
GUI Bug Fixes:
- Fixed the delete button functionality.
- Added exception handling to prevent empty fields in Author or Year.
- Implemented a pop-up error message for exceptions.
-
Rating Validation:
- Ensured that the book rating can only be between 1 and 5.
- Invalid inputs (including characters in the Year field) are now properly handled.
-
New Tab for Visualizations:
- Added a new tab with simple visualizations using Matplotlib.
-
Improved Search Function:
- Enhanced the search functionality to allow searching by pages, author, or genre.
-
Unit Testing:
- Created a test class
book_test.pywith simple unit tests.
- Created a test class
-
Resizable GUI:
- Made the GUI resizable for better user experience.