From 65d8cbafe34b946d450ce46703e6449eb9962741 Mon Sep 17 00:00:00 2001 From: Louie Shprung Date: Thu, 21 Dec 2023 13:17:39 -0800 Subject: Rename src directory to unique name to avoid install issues --- assignment_list_pyqt/add_entry_form.py | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 assignment_list_pyqt/add_entry_form.py (limited to 'assignment_list_pyqt/add_entry_form.py') diff --git a/assignment_list_pyqt/add_entry_form.py b/assignment_list_pyqt/add_entry_form.py new file mode 100644 index 0000000..59ed08a --- /dev/null +++ b/assignment_list_pyqt/add_entry_form.py @@ -0,0 +1,51 @@ +import os +import sys +from PyQt5 import uic +from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox +from PyQt5.QtCore import QDate +from assignment_list_pyqt.entry import Entry +import assignment_list_pyqt.globals as Globals +import assignment_list_pyqt.db_sqlite as DB + +class addEntryForm(QDialog): + def __init__(self, parent): + super().__init__() + uic.loadUi(os.path.join(os.path.dirname(os.path.abspath(__file__)), + "add_entry_form.ui"), self) + self.initializeUI(parent) + + def initializeUI(self, parent): + self.displayWidgets(parent) + self.exec() + + def displayWidgets(self, parent): + self.new_entry_due.setDate(QDate.currentDate()) + self.buttonBox.rejected.connect(self.close) + self.buttonBox.accepted.connect(lambda: self.handleSubmit(parent)) + + def handleSubmit(self, parent): + # Check that the new entry is not blank + desc_text = self.new_entry_desc.text() + due_text = "" + if self.new_entry_due_checkbox.isChecked(): + due_text = self.new_entry_due.date() # due_text is a QDate + due_alt_text = self.new_entry_due_alt.text() + link_text = self.new_entry_link.text() + color_text = self.new_entry_color.text() + highlight_text = self.new_entry_highlight.text() + + if not desc_text: + QMessageBox.warning(self, "Error Message", + "Description cannot be blank", + QMessageBox.Close, + QMessageBox.Close) + return + + new_id = DB.insertEntry(Entry(0, parent, desc_text, due_text, due_alt_text, link_text, color_text, highlight_text)) + Globals.entries.append(Entry(new_id, parent, desc_text, due_text, due_alt_text, link_text, color_text, highlight_text)) + self.close() + +if __name__ == "__main__": + app = QApplication(sys.argv) + window = addEntryForm() + sys.exit(app.exec_()) -- cgit