summaryrefslogtreecommitdiff
path: root/add_entry_form.py
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2023-09-16 09:36:14 -0400
committerLouie S <louie@example.com>2023-09-16 09:36:14 -0400
commit038df361d2aa8d03adb111b2faefa6ce4e5cd641 (patch)
tree30d1083356ab6be4f0f4edae70d9bf3e4cd47d1d /add_entry_form.py
parente89fd9cb4e88aa8f27f40c5c5073feb1a3aa1ce3 (diff)
Adding groups and entries starting to work
Diffstat (limited to 'add_entry_form.py')
-rw-r--r--add_entry_form.py56
1 files changed, 38 insertions, 18 deletions
diff --git a/add_entry_form.py b/add_entry_form.py
index 6449076..0140891 100644
--- a/add_entry_form.py
+++ b/add_entry_form.py
@@ -1,21 +1,23 @@
#!/usr/bin/python3
import sys
-from PyQt5.QtWidgets import QApplication, QDateTimeEdit, QFormLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QWidget
+from PyQt5.QtWidgets import QApplication, QDateTimeEdit, QDialog, QFormLayout, QHBoxLayout, QLabel, QLineEdit, QMessageBox, QPushButton
from PyQt5.QtGui import QFont
from PyQt5.QtCore import QDate, Qt
+from entry import Entry
+Globals = __import__("globals")
-class addEntryForm(QWidget):
- def __init__(self):
+class addEntryForm(QDialog):
+ def __init__(self, parent):
super().__init__()
- self.initializeUI()
+ self.initializeUI(parent)
- def initializeUI(self):
+ def initializeUI(self, parent):
self.resize(400, 1)
self.setWindowTitle("Add Entry")
- self.displayWidgets()
- self.show()
+ self.displayWidgets(parent)
+ self.exec()
- def displayWidgets(self):
+ def displayWidgets(self, parent):
entry_form_layout = QFormLayout()
title = QLabel("Add Entry")
@@ -23,18 +25,18 @@ class addEntryForm(QWidget):
title.setAlignment(Qt.AlignCenter)
entry_form_layout.addRow(title)
- new_entry_desc = QLineEdit()
- entry_form_layout.addRow("Description:", new_entry_desc)
+ self.new_entry_desc = QLineEdit()
+ entry_form_layout.addRow("Description:", self.new_entry_desc)
- new_entry_due = QDateTimeEdit(QDate.currentDate())
- new_entry_due.setDisplayFormat("MM/dd/yyyy")
- entry_form_layout.addRow("Due Date:", new_entry_due)
+ self.new_entry_due = QDateTimeEdit(QDate.currentDate())
+ self.new_entry_due.setDisplayFormat("MM/dd/yyyy")
+ entry_form_layout.addRow("Due Date:", self.new_entry_due)
- new_entry_due_alt = QLineEdit()
- entry_form_layout.addRow("Due Date (Alt):", new_entry_due_alt)
+ self.new_entry_due_alt = QLineEdit()
+ entry_form_layout.addRow("Due Date (Alt):", self.new_entry_due_alt)
- new_entry_link = QLineEdit() # TODO see if there is a widget specifically for URLs
- entry_form_layout.addRow("Link:", new_entry_link)
+ self.new_entry_link = QLineEdit() # TODO see if there is a widget specifically for URLs
+ entry_form_layout.addRow("Link:", self.new_entry_link)
# TODO:
# color
@@ -48,7 +50,7 @@ class addEntryForm(QWidget):
close_button.clicked.connect(self.close)
buttons_h_box.addWidget(close_button)
submit_button = QPushButton("Submit")
- submit_button.clicked.connect(self.close) # TODO connect this to a real method
+ submit_button.clicked.connect(lambda: self.handleSubmit(parent)) # TODO connect this to a real method
buttons_h_box.addWidget(submit_button)
buttons_h_box.addStretch()
@@ -56,6 +58,24 @@ class addEntryForm(QWidget):
self.setLayout(entry_form_layout)
+ def handleSubmit(self, parent):
+ # Check that the new entry is not blank
+ desc_text = self.new_entry_desc.text()
+ due_text = self.new_entry_due.text()
+ due_alt_text = self.new_entry_due_alt.text()
+ link_text = self.new_entry_link.text()
+
+ if not desc_text:
+ QMessageBox.warning(self, "Error Message",
+ "Description cannot be blank",
+ QMessageBox.Close,
+ QMessageBox.Close)
+ return
+
+ # TODO do the database stuff (this will allow us to get the id)
+ Globals.entries.append(Entry(parent, desc_text, due_text, due_alt_text, link_text))
+ self.close()
+
if __name__ == "__main__":
app = QApplication(sys.argv)
window = addEntryForm()