summaryrefslogtreecommitdiff
path: root/assignment-list.py
blob: bcb6bd16770b432c179bb51b9ad8f5ebb120cadb (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/python3
import sys
import time
from PyQt5.QtWidgets import QAction, QApplication, QHBoxLayout, QLabel, QMainWindow, QMessageBox, QToolBar, QVBoxLayout, QWidget
from PyQt5.QtGui import QFont
from add_group_form import addGroupForm
from group import Group

class AssignmentList(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initializeUI()

    def initializeUI(self):
        self.resize(640, 480)
        self.setWindowTitle("Assignment List")
        self.createMenu()
        self.createToolbar()
        self.displayWidgets()
        self.show()

    def createMenu(self):
        menu_bar = self.menuBar()
        file_menu = menu_bar.addMenu("File")
        edit_menu = menu_bar.addMenu("Edit")
        help_menu = menu_bar.addMenu("Help")

        exit_act = QAction("Exit", self)
        exit_act.setShortcut("Ctrl+Q")
        exit_act.triggered.connect(self.close)
        file_menu.addAction(exit_act)

        self.add_group_act = QAction("Add Group", self)
        self.add_group_act.triggered.connect(self.addGroup)
        edit_menu.addAction(self.add_group_act)

        about_act = QAction("About", self)
        about_act.triggered.connect(self.aboutDialog)
        help_menu.addAction(about_act)

    def createToolbar(self):
        tool_bar = QToolBar("Toolbar")
        self.addToolBar(tool_bar)

        tool_bar.addAction(self.add_group_act)

    def displayWidgets(self):
        main_widget = QWidget(self)
        self.setCentralWidget(main_widget)

        title = QLabel(time.strftime("%A, %b %d %Y"))
        title.setFont(QFont("Arial", 17))

        title_h_box = QHBoxLayout()
        title_h_box.addStretch()
        title_h_box.addWidget(title)
        title_h_box.addStretch()

        self.load_groups()
        self.drawGroups()

        v_box = QVBoxLayout()
        v_box.addLayout(title_h_box)
        v_box.addLayout(self.groups_hbox)
        v_box.addStretch()

        main_widget.setLayout(v_box)

    def addGroup(self):
        """
        Open the 'addGroup' form
        """
        self.create_new_group_dialog = addGroupForm()
        self.create_new_group_dialog.show()

    def drawGroups(self):
        """
        Redraw the groups_hbox
        """
        # Reset layout
        self.groups_hbox = QHBoxLayout()
        self.groups_hbox.setContentsMargins(20, 5, 20, 5)

        # 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())
            else:
                column_right.addLayout(g.buildLayout())

        column_left.addStretch()
        column_right.addStretch()

        self.groups_hbox.addLayout(column_left)
        self.groups_hbox.addStretch()
        self.groups_hbox.addLayout(column_right)
        self.groups_hbox.addStretch()

    def aboutDialog(self):
        QMessageBox.about(self, "About Assignment List",
                          "Created by Louie S. - 2023")

    def load_groups(self):
        """
        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"))

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