summaryrefslogtreecommitdiff
path: root/assignment_list_pyqt/add_group_form.py
blob: b6cb804f7a87255f015be63c39b515ce89c7f8b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox

import assignment_list_pyqt.globals as Globals
from assignment_list_pyqt.group import Group
import assignment_list_pyqt.db_sqlite as DB

class addGroupForm(QDialog):
    """
    Implemented so that it can be used for adding and editing groups
    """
    def __init__(self):
        super().__init__()
        uic.loadUi(os.path.join(os.path.dirname(os.path.abspath(__file__)), 
                                   "add_group_form.ui"), self)
        self.initializeUI()

    def initializeUI(self):
        self.displayWidgets()
        self.exec()

    def displayWidgets(self):
        self.buttonBox.rejected.connect(self.close)
        self.buttonBox.accepted.connect(self.handleSubmit)

    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

        new_id = DB.insertGroup(Group(0, name_text, column_text, link_text))
        Globals.groups.append(Group(new_id, name_text, column_text, link_text))
        self.close()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = addGroupForm()
    sys.exit(app.exec_())