GRP PRJ OOP
GRP PRJ OOP
This project is about developing a user interface application that can manage a Library
system that help the user to add, remove, find and delete book from the library.
With the use PYQT design which you can drag and drop the different interface or you can
code it manual. Also make use of Sql lite to keep all data base
Step 1: You have to import the library which is the PYQT by typing import pyqt
Step 2: you have to import the SQL Lite by typing import SQL lite
Step 3: you have to install pyqt on the terminal and make sure you are connected to
strong internet use (pip install pyqt5 to install)
Step 4: You have to install the SQL lite using (pip install SQL lite)
Step 6: You have to declare the attributes using the __init__ constructor
CASE STUDY
This is a library management system that keep track of books in an online library system.
The system help you to know book that are not available at the moment in the library or
books that are added or books that are just be updated in the library for easy running of
the library system. With the use of PYQT which is in different version but for this project
we are using the PYQT5. This help you to design an application system through the
Manuel code or drag and drop to design a perfect interface. The PYQT can be manually
install using line of code or you can download it from the browser. With the use of python
language you then code the functionality you want your application to perform after that
you have to run the code on you terminal and it straight away take you to the PYQT to
display you project. The PYQT has some functionality which help you to design your
application the way want it to be using color, text, image and videos. The use of the SQL
lite is to keep all the data that are and will be add to the application system.
USER MANUAL
Step 1: Clicking on the application to open after that you go the screech to look for the
book you want to read or find. When screeching for the book you have to write the title,
author, ISBN and publish year and click screech.
Step 2: When you want to add a book you have to click on the add book. Enter the title
of the book you want to author, ISBN and the published year.
Step 3: If you want to delete a book you have to click on the title of the book you want
to delete and press delete. You can delete multiple book at a time by select the amount
you want to delete
Step 4: You can by clicking update and entering the book title, author, ISBN and year
and click update.
Step 5: If you have open a particular and want to exit from there you can press back to
go back.
import sys
import sqlite3
class LibraryManagementSystem(QMainWindow):
def go_back(self):
def __init__(self):
super().__init__()
# Main Widget
self.main_widget = QWidget()
self.setCentralWidget(self.main_widget)
# Main Layout
self.layout = QVBoxLayout()
self.main_widget.setLayout(self.layout)
# Search Bar
self.search_layout = QHBoxLayout()
self.search_input = QLineEdit()
self.search_button = QPushButton("Search")
self.search_button.clicked.connect(self.search_books)
self.search_layout.addWidget(self.search_input)
self.search_layout.addWidget(self.search_button)
self.layout.addLayout(self.search_layout)
self.table = QTableWidget()
self.table.setColumnCount(5)
self.layout.addWidget(self.table)
# CRUD Buttons
self.button_layout = QHBoxLayout()
# Back Button
self.back_button = QPushButton("Back")
self.back_button.clicked.connect(self.go_back)
self.add_button.clicked.connect(self.add_book)
self.update_button.clicked.connect(self.update_book)
self.delete_button.clicked.connect(self.delete_book)
self.button_layout.addWidget(self.add_button)
self.button_layout.addWidget(self.update_button)
self.button_layout.addWidget(self.delete_button)
self.button_layout.addWidget(self.back_button)
self.layout.addLayout(self.button_layout)
# Database Connection
self.conn = sqlite3.connect("library.db")
self.cursor = self.conn.cursor()
self.create_table()
self.add_initial_books()
self.load_books()
def create_table(self):
query = """
genre TEXT,
publication_year INTEGER
)
"""
self.cursor.execute(query)
self.conn.commit()
def add_initial_books(self):
books = [
query = """
VALUES (?, ?, ?, ?, ?)
"""
self.cursor.execute(query, book)
except sqlite3.IntegrityError:
self.conn.commit()
def load_books(self):
self.cursor.execute(query)
books = self.cursor.fetchall()
self.table.setRowCount(len(books))
def search_books(self):
search_text = self.search_input.text()
query = """
"""
self.cursor.execute(query, (f"%{search_text}%",) * 4)
books = self.cursor.fetchall()
self.table.setRowCount(len(books))
def add_book(self):
return
return
isbn, ok = QInputDialog.getText(self, "Add Book", "Enter ISBN:")
return
return
if not ok:
return
try:
query = """
VALUES (?, ?, ?, ?, ?)
"""
self.conn.commit()
self.load_books()
except sqlite3.IntegrityError:
selected_row = self.table.currentRow()
if selected_row < 0:
return
return
return
return
year, ok = QInputDialog.getInt(self, "Update Book", "Enter new Publication Year:",
int(self.table.item(selected_row, 4).text()))
if not ok:
return
query = """
UPDATE books
WHERE isbn = ?
"""
self.conn.commit()
self.load_books()
def delete_book(self):
selected_row = self.table.currentRow()
if selected_row < 0:
return
self.conn.commit()
self.load_books()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = LibraryManagementSystem()
window.show()
sys.exit(app.exec_())
CONCLUSION
In a nut shell this assignment was a good means of learning as it make us understand
the Meaning and purpose of Object Oriented Programming Language. We get to know
the how to use PYQT and create our very own application system.