summaryrefslogtreecommitdiff
path: root/assignment_list_pyqt/add_entry_form.py
diff options
context:
space:
mode:
authorLouie Shprung <lshprung@scu.edu>2023-12-21 13:17:39 -0800
committerLouie Shprung <lshprung@scu.edu>2023-12-21 13:17:39 -0800
commit65d8cbafe34b946d450ce46703e6449eb9962741 (patch)
tree9cb2bfa4857507207e8740478e5d23d4421ad784 /assignment_list_pyqt/add_entry_form.py
parent11373742d701166f2580cfe67015eac012cda1a9 (diff)
Rename src directory to unique name to avoid install issues
Diffstat (limited to 'assignment_list_pyqt/add_entry_form.py')
-rw-r--r--assignment_list_pyqt/add_entry_form.py51
1 files changed, 51 insertions, 0 deletions
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_())