diff options
author | Louie S <louie@example.com> | 2023-09-16 09:36:14 -0400 |
---|---|---|
committer | Louie S <louie@example.com> | 2023-09-16 09:36:14 -0400 |
commit | b883e45bd29fd53cc318cf1abeda8fbcfeb69a22 (patch) | |
tree | 61e887edebd75bac3987527ce8fee86f34a3edc6 | |
parent | 1a266e4159976d2753d8dbd787fc8155ba321859 (diff) |
Editing groups is working
-rw-r--r-- | add_entry_form.py | 1 | ||||
-rw-r--r-- | add_group_form.py | 6 | ||||
-rwxr-xr-x | assignment-list.py | 38 | ||||
-rw-r--r-- | edit_group_form.py | 81 | ||||
-rw-r--r-- | globals.py | 2 | ||||
-rw-r--r-- | group.py | 4 |
6 files changed, 123 insertions, 9 deletions
diff --git a/add_entry_form.py b/add_entry_form.py index 0140891..cedaaf6 100644 --- a/add_entry_form.py +++ b/add_entry_form.py @@ -1,4 +1,3 @@ -#!/usr/bin/python3 import sys from PyQt5.QtWidgets import QApplication, QDateTimeEdit, QDialog, QFormLayout, QHBoxLayout, QLabel, QLineEdit, QMessageBox, QPushButton from PyQt5.QtGui import QFont diff --git a/add_group_form.py b/add_group_form.py index 9a88385..e62b211 100644 --- a/add_group_form.py +++ b/add_group_form.py @@ -1,4 +1,3 @@ -#!/usr/bin/python3 import sys from PyQt5.QtWidgets import QApplication, QComboBox, QDialog, QFormLayout, QHBoxLayout, QLabel, QLineEdit, QMessageBox, QPushButton from PyQt5.QtGui import QFont @@ -8,6 +7,9 @@ from add_entry_form import Globals from group import Group class addGroupForm(QDialog): + """ + Implemented so that it can be used for adding and editing groups + """ def __init__(self): super().__init__() self.initializeUI() @@ -43,7 +45,7 @@ class addGroupForm(QDialog): close_button.clicked.connect(self.close) buttons_h_box.addWidget(close_button) submit_button = QPushButton("Submit") - submit_button.clicked.connect(self.handleSubmit) # TODO connect this to a real method + submit_button.clicked.connect(self.handleSubmit) buttons_h_box.addWidget(submit_button) buttons_h_box.addStretch() diff --git a/assignment-list.py b/assignment-list.py index c72493d..b336098 100755 --- a/assignment-list.py +++ b/assignment-list.py @@ -5,9 +5,8 @@ from PyQt5.QtWidgets import QAction, QApplication, QHBoxLayout, QLabel, QMainWin from PyQt5.QtGui import QFont from PyQt5.QtCore import Qt from add_group_form import addGroupForm +from edit_group_form import editGroupForm from add_entry_form import addEntryForm -from entry import Entry -from group import Group Globals = __import__("globals") class AssignmentList(QMainWindow): @@ -83,6 +82,23 @@ class AssignmentList(QMainWindow): if old_count != len(Globals.groups): self.drawGroups() + def editGroup(self, id): + """ + Open the 'editGroup' form + """ + self.create_edit_group_dialog = editGroupForm(id) + self.drawGroups() + + def removeGroup(self, id): + """ + Delete a group with a given id + """ + # TODO might want to add a warning + # TODO might want to make part of the a destructor in the Group class + Globals.entries = list(filter(lambda e: e.parent_id != id, Globals.entries)) + Globals.groups = list(filter(lambda g: g.id != id, Globals.groups)) + self.drawGroups() + def addEntry(self, parent): """ Open the 'addEntry' form @@ -92,6 +108,12 @@ class AssignmentList(QMainWindow): if old_count != len(Globals.entries): self.drawGroups() # TODO see if we can do this with only redrawing a single group + def removeEntry(self, id): + """ + Delete an entry with a given id + """ + # TODO implement when db is implemented, and entries have ids + pass def drawGroups(self): """ @@ -116,10 +138,22 @@ class AssignmentList(QMainWindow): # 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) + + add_entry_button = QPushButton() + add_entry_button.setText("Edit Group") + add_entry_button.clicked.connect((lambda id: lambda: self.editGroup(id))(g.id)) + buttons_hbox.addWidget(add_entry_button) + + del_group_button = QPushButton() + del_group_button.setText("Remove Group") + del_group_button.clicked.connect((lambda id: lambda: self.removeGroup(id))(g.id)) + buttons_hbox.addWidget(del_group_button) + buttons_hbox.addStretch() g_layout.addLayout(buttons_hbox) if g.column.lower() == "left": diff --git a/edit_group_form.py b/edit_group_form.py new file mode 100644 index 0000000..d5df4c8 --- /dev/null +++ b/edit_group_form.py @@ -0,0 +1,81 @@ +import sys +from PyQt5.QtWidgets import QApplication, QComboBox, QDialog, QFormLayout, QHBoxLayout, QLabel, QLineEdit, QMessageBox, QPushButton +from PyQt5.QtGui import QFont +from PyQt5.QtCore import Qt + +from add_entry_form import Globals +from group import Group + +class editGroupForm(QDialog): + """ + Implemented so that it can be used for adding and editing groups + """ + def __init__(self, id): + self.id = id + super().__init__() + self.initializeUI() + + def initializeUI(self): + self.resize(400, 1) + self.setWindowTitle("Edit Group") + self.displayWidgets() + self.exec() + + def displayWidgets(self): + group_form_layout = QFormLayout() + group = list(filter(lambda g: g.id == self.id, Globals.groups))[0] + + title = QLabel("Edit Group") + title.setFont(QFont("Arial", 18)) + title.setAlignment(Qt.AlignCenter) + group_form_layout.addRow(title) + + self.group_name = QLineEdit() + self.group_name.setText(group.name) + group_form_layout.addRow("Name:", self.group_name) + + self.group_column = QComboBox() + self.group_column.addItems(["Left", "Right"]) + self.group_column.setCurrentIndex(0 if group.column.lower() == "left" else 1) + group_form_layout.addRow("Column:", self.group_column) + + self.group_link = QLineEdit() # TODO see if there is a widget specifically for URLs + self.group_link.setText(group.link) + group_form_layout.addRow("Link:", self.group_link) + + # Submit and cancel buttons + buttons_h_box = QHBoxLayout() + buttons_h_box.addStretch() + close_button = QPushButton("Cancel") + close_button.clicked.connect(self.close) + buttons_h_box.addWidget(close_button) + submit_button = QPushButton("Submit") + submit_button.clicked.connect(self.handleSubmit) + buttons_h_box.addWidget(submit_button) + buttons_h_box.addStretch() + + group_form_layout.addRow(buttons_h_box) + + self.setLayout(group_form_layout) + + def handleSubmit(self): + name_text = self.group_name.text() + column_text = self.group_column.currentText() + link_text = self.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 = list(filter(lambda g: g.id != self.id, Globals.groups)) + Globals.groups.append(Group(self.id, name_text, column_text, link_text)) + self.close() + +if __name__ == "__main__": + app = QApplication(sys.argv) + window = editGroupForm() + sys.exit(app.exec_()) @@ -1,3 +1,3 @@ groups = [] entries = [] -max_group_id = 5 # TODO remove this, only a placeholder until database is implemented +max_group_id = 1 # TODO remove this, only a placeholder until database is implemented @@ -1,7 +1,6 @@ -import datetime from PyQt5.QtCore import Qt from PyQt5.QtGui import QFont -from PyQt5.QtWidgets import QHBoxLayout, QLabel, QPushButton, QVBoxLayout +from PyQt5.QtWidgets import QLabel, QVBoxLayout Globals = __import__("globals") class Group: @@ -36,7 +35,6 @@ class Group: """ Retrieve this group's entries """ - # TODO this should be pulling from a database output = [] for e in Globals.entries: if e.parent_id == self.id: |