diff options
-rw-r--r-- | add_entry_form.py | 56 | ||||
-rw-r--r-- | add_group_form.py | 42 | ||||
-rwxr-xr-x | assignment-list.py | 76 | ||||
-rw-r--r-- | entry.py | 3 | ||||
-rw-r--r-- | globals.py | 3 | ||||
-rw-r--r-- | group.py | 29 |
6 files changed, 141 insertions, 68 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() diff --git a/add_group_form.py b/add_group_form.py index f4c4d6a..9a88385 100644 --- a/add_group_form.py +++ b/add_group_form.py @@ -1,10 +1,13 @@ #!/usr/bin/python3 import sys -from PyQt5.QtWidgets import QApplication, QComboBox, QFormLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QWidget +from PyQt5.QtWidgets import QApplication, QComboBox, QDialog, QFormLayout, QHBoxLayout, QLabel, QLineEdit, QMessageBox, QPushButton from PyQt5.QtGui import QFont from PyQt5.QtCore import Qt -class addGroupForm(QWidget): +from add_entry_form import Globals +from group import Group + +class addGroupForm(QDialog): def __init__(self): super().__init__() self.initializeUI() @@ -13,7 +16,7 @@ class addGroupForm(QWidget): self.resize(400, 1) self.setWindowTitle("Add Group") self.displayWidgets() - self.show() + self.exec() def displayWidgets(self): group_form_layout = QFormLayout() @@ -23,15 +26,15 @@ class addGroupForm(QWidget): title.setAlignment(Qt.AlignCenter) group_form_layout.addRow(title) - new_group_name = QLineEdit() - group_form_layout.addRow("Name:", new_group_name) + self.new_group_name = QLineEdit() + group_form_layout.addRow("Name:", self.new_group_name) - new_group_column = QComboBox() - new_group_column.addItems(["Left", "Right"]) - group_form_layout.addRow("Column:", new_group_column) + self.new_group_column = QComboBox() + self.new_group_column.addItems(["Left", "Right"]) + group_form_layout.addRow("Column:", self.new_group_column) - new_group_link = QLineEdit() # TODO see if there is a widget specifically for URLs - group_form_layout.addRow("Link:", new_group_link) + self.new_group_link = QLineEdit() # TODO see if there is a widget specifically for URLs + group_form_layout.addRow("Link:", self.new_group_link) # Submit and cancel buttons buttons_h_box = QHBoxLayout() @@ -40,7 +43,7 @@ class addGroupForm(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(self.handleSubmit) # TODO connect this to a real method buttons_h_box.addWidget(submit_button) buttons_h_box.addStretch() @@ -48,6 +51,23 @@ class addGroupForm(QWidget): self.setLayout(group_form_layout) + def handleSubmit(self): + name_text = self.new_group_name.text() + column_text = self.new_group_column.currentText() + link_text = self.new_group_link.text() + + if not name_text: + QMessageBox.warning(self, "Error Message", + "Name cannot be blank", + QMessageBox.Close, + QMessageBox.Close) + return + + # TODO do the database stuff (this will allow us to get the id) + Globals.groups.append(Group(Globals.max_group_id, name_text, column_text, link_text)) + Globals.max_group_id = Globals.max_group_id + 1 + self.close() + if __name__ == "__main__": app = QApplication(sys.argv) window = addGroupForm() diff --git a/assignment-list.py b/assignment-list.py index 535370d..63eb519 100755 --- a/assignment-list.py +++ b/assignment-list.py @@ -1,11 +1,14 @@ #!/usr/bin/python3 import sys import time -from PyQt5.QtWidgets import QAction, QApplication, QHBoxLayout, QLabel, QMainWindow, QMessageBox, QToolBar, QVBoxLayout, QWidget +from PyQt5.QtWidgets import QAction, QApplication, QHBoxLayout, QLabel, QMainWindow, QMessageBox, QPushButton, QToolBar, QVBoxLayout, QWidget from PyQt5.QtGui import QFont from PyQt5.QtCore import Qt from add_group_form import addGroupForm +from add_entry_form import addEntryForm +from entry import Entry from group import Group +Globals = __import__("globals") class AssignmentList(QMainWindow): def __init__(self): @@ -59,6 +62,9 @@ class AssignmentList(QMainWindow): title_h_box.addStretch() self.load_groups() + self.load_entries() # TODO placeholder, this will eventually be moved to group.py + self.groups_hbox = QHBoxLayout() + self.groups_hbox.setContentsMargins(20, 5, 20, 5) self.drawGroups() v_box = QVBoxLayout() @@ -72,26 +78,54 @@ class AssignmentList(QMainWindow): """ Open the 'addGroup' form """ + old_count = len(Globals.groups) self.create_new_group_dialog = addGroupForm() - self.create_new_group_dialog.show() + if old_count != len(Globals.groups): + self.drawGroups() + + def addEntry(self, parent): + """ + Open the 'addEntry' form + """ + old_count = len(Globals.entries) + self.create_new_entry_dialog = addEntryForm(parent) + if old_count != len(Globals.entries): + self.drawGroups() # TODO see if we can do this with only redrawing a single group + def drawGroups(self): """ Redraw the groups_hbox """ - # Reset layout - self.groups_hbox = QHBoxLayout() - self.groups_hbox.setContentsMargins(20, 5, 20, 5) + # Remove all children from layout + def recursiveClear(layout): + while layout.count(): + child = layout.takeAt(0) + if child.widget(): + child.widget().deleteLater() + elif child.layout(): + recursiveClear(child) + + recursiveClear(self.groups_hbox) # Create columns as vertical boxes column_left = QVBoxLayout() column_right = QVBoxLayout() - for g in self.groups: - if g.column == "left": - column_left.addLayout(g.buildLayout()) + for g in Globals.groups: + # Include buttons at the bottom to edit the group + g_layout = g.buildLayout() + buttons_hbox = QHBoxLayout() + add_entry_button = QPushButton() + add_entry_button.setText("Add Entry") + add_entry_button.clicked.connect((lambda id: lambda: self.addEntry(id))(g.id)) + buttons_hbox.addWidget(add_entry_button) + buttons_hbox.addStretch() + g_layout.addLayout(buttons_hbox) + if g.column.lower() == "left": + column_left.addLayout(g_layout) else: - column_right.addLayout(g.buildLayout()) + column_right.addLayout(g_layout) column_left.addStretch() column_right.addStretch() @@ -101,6 +135,13 @@ class AssignmentList(QMainWindow): self.groups_hbox.addLayout(column_right) self.groups_hbox.addStretch() + # Implementation should be moved here from group.py if possible + def drawEntries(self): + """ + Redraw the entries of a specific group + """ + pass + def aboutDialog(self): QMessageBox.about(self, "About Assignment List", "Created by Louie S. - 2023") @@ -109,12 +150,17 @@ class AssignmentList(QMainWindow): """ Load groups data """ - # TODO this is debug for now, with fixed values - self.groups = [] - self.groups.append(Group("test1", "left")) - self.groups.append(Group("test2", "left")) - self.groups.append(Group("test3", "right")) - self.groups.append(Group("test4", "right")) + Globals.groups.append(Group(1, "test1", "left")) + Globals.groups.append(Group(2, "test2", "left")) + Globals.groups.append(Group(3, "test3", "right")) + Globals.groups.append(Group(4, "test4", "right")) + + def load_entries(self): + """ + Load entries data + """ + Globals.entries.append(Entry(1, "test1-task1")) + Globals.entries.append(Entry(2, "test2-task1")) if __name__ == "__main__": app = QApplication(sys.argv) @@ -4,7 +4,8 @@ from PyQt5.QtGui import QFont from PyQt5.QtWidgets import QLabel class Entry: - def __init__(self, desc, due = "", due_alt = "", link = ""): + def __init__(self, parent_id, desc, due = "", due_alt = "", link = ""): + self.parent_id = parent_id self.desc = desc self.due = due self.due_alt = due_alt diff --git a/globals.py b/globals.py new file mode 100644 index 0000000..040fe59 --- /dev/null +++ b/globals.py @@ -0,0 +1,3 @@ +groups = [] +entries = [] +max_group_id = 5 # TODO remove this, only a placeholder until database is implemented @@ -2,11 +2,11 @@ import datetime from PyQt5.QtCore import Qt from PyQt5.QtGui import QFont from PyQt5.QtWidgets import QHBoxLayout, QLabel, QPushButton, QVBoxLayout -from add_entry_form import addEntryForm -from entry import Entry +Globals = __import__("globals") class Group: - def __init__(self, name, column = "left", link = ""): + def __init__(self, id, name, column = "left", link = ""): + self.id = id self.name = name self.column = column self.link = link @@ -30,33 +30,16 @@ class Group: entries_vbox.addWidget(e.buildLayout()) output.addLayout(entries_vbox) - # Include buttons at the bottom to edit the group - buttons_hbox = QHBoxLayout() - - add_entry_button = QPushButton() - add_entry_button.setText("Add Entry") - add_entry_button.clicked.connect(self.addEntry) - buttons_hbox.addWidget(add_entry_button) - buttons_hbox.addStretch() - - output.addLayout(buttons_hbox) - return output - def addEntry(self): - """ - Open the 'addEntry' form - """ - self.create_new_entry_dialog = addEntryForm() - self.create_new_entry_dialog.show() - def getEntriesFromGroup(self): """ Retrieve this group's entries """ # TODO this should be pulling from a database output = [] - output.append(Entry("yeet")) - output.append(Entry("bruh", datetime.date(2023, 12, 25))) + for e in Globals.entries: + if e.parent_id == self.id: + output.append(e) return output |