From aaaf03cfb40604fb5d13f35dddbf09b532b4daab Mon Sep 17 00:00:00 2001 From: Kr-Adarsh Date: Mon, 7 Oct 2024 05:03:50 +0530 Subject: [PATCH 1/2] Created a GUI for the Student data Added a Delect data function and Button Made few well needed changes in file_functions file --- GUI/GUI_student.py | 76 +++++++++++++++++++ GUI/file_operations.py | 31 ++++++-- GUI/first_gui.ui | 163 +++++++++++++++++++++++++++++++++++++++++ GUI/readme.md | 15 ++++ 4 files changed, 278 insertions(+), 7 deletions(-) create mode 100644 GUI/GUI_student.py create mode 100644 GUI/first_gui.ui create mode 100644 GUI/readme.md diff --git a/GUI/GUI_student.py b/GUI/GUI_student.py new file mode 100644 index 0000000..0c7491e --- /dev/null +++ b/GUI/GUI_student.py @@ -0,0 +1,76 @@ +from PyQt5.QtWidgets import * +from PyQt5 import uic +import student +import file_operations +import os # Import os for file operations + + +class Mygui(QMainWindow): + + def __init__(self): + super(Mygui, self).__init__() + uic.loadUi("Student-Management-System/GUI/first_gui.ui", self) + self.show() + + # Connect buttons to their respective methods + self.pushButton.clicked.connect(self.add_record) # Add Record Button + self.pushButton_2.clicked.connect(self.display_records) # Display Records Button + self.pushButton_3.clicked.connect(self.delete_file) # Delete All Records Button + + def add_record(self): + # Retrieve input values from the GUI + roll = self.lineEdit.text() + name = self.lineEdit_2.text() + percentage = self.lineEdit_3.text() + + # Ensure the inputs are valid (check if fields are not empty and percentage is numeric) + if roll.isdigit() and percentage.replace('.', '', 1).isdigit(): + # Create a Student object + student_obj = student.Student() + student_obj.add_record(int(roll), name, float(percentage)) + + # Write the student record to the file using file_operations + result = file_operations.write_record(student_obj) + self.statusBar().showMessage(result) # Display result message in the status bar + + # Clear the input fields after adding the record + self.lineEdit.clear() + self.lineEdit_2.clear() + self.lineEdit_3.clear() + else: + self.statusBar().showMessage("Invalid input. Please check the fields.") + + def display_records(self): + # Fetch all records from the file using file_operations + records = file_operations.display_all_records() + + # Clear the textEdit area before displaying new records + self.textEdit.clear() + + # Display all records in the textEdit widget + if records: + for record in records: + self.textEdit.append(record + "\n") # Display each record and add a new line + else: + self.textEdit.append("No records found.") + + def delete_file(self): + try: + if os.path.exists("stud.dat"): + os.remove("stud.dat") # Delete the file + self.statusBar().showMessage("All records deleted successfully!") + self.textEdit.clear() # Clear the text area if needed + else: + self.statusBar().showMessage("File not found!") + except Exception as e: + self.statusBar().showMessage(f"Error: {str(e)}") + + +def main(): + app = QApplication([]) + window = Mygui() + app.exec_() + + +if __name__ == '__main__': + main() diff --git a/GUI/file_operations.py b/GUI/file_operations.py index 9f7c752..fb2435d 100644 --- a/GUI/file_operations.py +++ b/GUI/file_operations.py @@ -1,11 +1,12 @@ # file_operations.py import pickle - +import os +import student def write_record(student): try: with open("stud.dat", "ab") as file: - pickle.dump(student, file) + pickle.dump(student, file) # Ensure student is a Student instance return "Record added in file!" except Exception as e: return f"Error: {str(e)}" @@ -16,10 +17,26 @@ def display_all_records(): try: with open("stud.dat", "rb") as file: while True: - student = pickle.load(file) - records.append(student.display_record()) - return records - except EOFError: - return records + try: + student = pickle.load(file) # Load the Student object + records.append(student.display_record()) # Append the student's record + except EOFError: + break + return records if records else ["No records found."] + except FileNotFoundError: + return ["File not found! Please add a record first."] + except pickle.UnpicklingError: + return ["Error in unpickling data! The file might be corrupted."] except IOError: return ["File could not be opened!"] + +def delete_file(self): + try: + if os.path.exists("stud.dat"): + os.remove("stud.dat") # Delete the file + self.statusBar().showMessage("All records deleted successfully!") + self.textEdit.clear() # Clear the text area if needed + else: + self.statusBar().showMessage("File not found!") + except Exception as e: + self.statusBar().showMessage(f"Error: {str(e)}") \ No newline at end of file diff --git a/GUI/first_gui.ui b/GUI/first_gui.ui new file mode 100644 index 0000000..6b8425d --- /dev/null +++ b/GUI/first_gui.ui @@ -0,0 +1,163 @@ + + + MainWindow + + + + 0 + 0 + 462 + 593 + + + + MainWindow + + + + + + 10 + 20 + 121 + 21 + + + + Roll Number: + + + + + + 10 + 50 + 121 + 16 + + + + Name + + + + + + 10 + 80 + 121 + 16 + + + + Percentage: + + + + + + 210 + 20 + 201 + 22 + + + + + + + 210 + 50 + 201 + 22 + + + + + + + 210 + 80 + 201 + 22 + + + + + + + 70 + 120 + 281 + 31 + + + + Add Record + + + + + + 20 + 180 + 421 + 261 + + + + + + + 20 + 450 + 421 + 41 + + + + Display all Records + + + + + + 10 + 150 + 55 + 16 + + + + Records: + + + + + + 20 + 500 + 421 + 31 + + + + Delete the Data + + + + + + + 0 + 0 + 462 + 26 + + + + + + + + diff --git a/GUI/readme.md b/GUI/readme.md new file mode 100644 index 0000000..bfa26e0 --- /dev/null +++ b/GUI/readme.md @@ -0,0 +1,15 @@ +# Student Management System GUI + +A simple Student Management System built using PyQt5 and Python for managing student records. The application allows users to add, display, and delete student records. + +## Features + +- **Add Student Record**: Enter roll number, name, and percentage to add a new student record. +- **Display Records**: View all student records stored in a file. +- **Delete Records**: Delete all records and reset the database by removing the `stud.dat` file. + +## Technologies Used + +- **Python**: Programming language used for development. +- **PyQt5**: GUI toolkit for creating the application interface. +- **Pickle**: Used for serializing and deserializing Python objects. From ed365bf59c2aaa56718843904fc6fbff138aea35 Mon Sep 17 00:00:00 2001 From: Kr-Adarsh Date: Mon, 7 Oct 2024 05:15:33 +0530 Subject: [PATCH 2/2] Created a GUI for a CLI model Added a readme.md for better understanding Changed the file_function and added a delete button --- GUI/GUI_student.py | 5 +++-- GUI/readme.md | 4 ++++ GUI/stud.dat | Bin 154 -> 0 bytes 3 files changed, 7 insertions(+), 2 deletions(-) delete mode 100644 GUI/stud.dat diff --git a/GUI/GUI_student.py b/GUI/GUI_student.py index 0c7491e..7bc47cc 100644 --- a/GUI/GUI_student.py +++ b/GUI/GUI_student.py @@ -9,11 +9,12 @@ class Mygui(QMainWindow): def __init__(self): super(Mygui, self).__init__() - uic.loadUi("Student-Management-System/GUI/first_gui.ui", self) + uic.loadUi("first_gui.ui", self) + self.show() # Connect buttons to their respective methods - self.pushButton.clicked.connect(self.add_record) # Add Record Button + self.pushButton.clicked.connect(self.add_record) # Record Button self.pushButton_2.clicked.connect(self.display_records) # Display Records Button self.pushButton_3.clicked.connect(self.delete_file) # Delete All Records Button diff --git a/GUI/readme.md b/GUI/readme.md index bfa26e0..c65613f 100644 --- a/GUI/readme.md +++ b/GUI/readme.md @@ -13,3 +13,7 @@ A simple Student Management System built using PyQt5 and Python for managing stu - **Python**: Programming language used for development. - **PyQt5**: GUI toolkit for creating the application interface. - **Pickle**: Used for serializing and deserializing Python objects. + +## To run the GUI: + +> python GUI_student.py diff --git a/GUI/stud.dat b/GUI/stud.dat deleted file mode 100644 index 1d97c7663c917ca1a2ba72198ef65ed08da7144d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 154 zcmZo*nd-y<0X^)+C8a5;c_mYN*n^?0$x}2Nr_@f-=wT_!&&iqM&Dg_|mzbM6rH3(S jN)K~EYS9#T2PKI1(j>hG(hOsQ8x{^XEaCvzG@xMs72h&h