# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'scheduler.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
#
# WARNING! All changes made in this file will be lost!
import os
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QDialog, QMessageBox
import sys

import schoolschedulerapp
from schoolschedulerapp.db_alchemy import *
from schoolschedulerapp.generatedata import generate_test_data
from schoolschedulerapp.schedule import generate_schedule


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setEnabled(True)
        MainWindow.resize(1024, 768)
        MainWindow.setMinimumSize(QtCore.QSize(1024, 768))
        MainWindow.setMaximumSize(QtCore.QSize(1024, 768))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(str(schoolschedulerapp.__file__)[0:-12] + "/square.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.dropdown = QtWidgets.QComboBox(self.centralwidget)
        self.dropdown.setGeometry(QtCore.QRect(0, 0, 90, 20))
        self.dropdown.setStyleSheet("")
        self.dropdown.setObjectName("dropdown")
        self.dropdown.addItem("")
        self.dropdown.addItem("")
        self.search_edit = QtWidgets.QLineEdit(self.centralwidget)
        self.search_edit.setGeometry(QtCore.QRect(110, 0, 120, 20))
        self.search_edit.setStyleSheet("")
        self.search_edit.setObjectName("search_edit")
        self.search_edit.textEdited.connect(
            lambda: self.search_mode(self.search_edit.text(), self.dropdown.currentIndex()))
        self.search_button = QtWidgets.QToolButton(self.centralwidget)
        self.search_button.setGeometry(QtCore.QRect(230, 0, 20, 20))
        self.search_button.setStyleSheet("background-color: rgb(0, 0, 127);")
        self.search_button.setText("")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(str(schoolschedulerapp.__file__)[0:-12] + "/search.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.search_button.setIcon(icon1)
        self.search_button.setObjectName("search_button")
        self.plusbutton = QtWidgets.QPushButton(self.centralwidget)
        self.plusbutton.setGeometry(QtCore.QRect(90, 0, 20, 20))
        self.plusbutton.setStyleSheet("")
        self.plusbutton.setObjectName("plusbutton")
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setGeometry(QtCore.QRect(260, 10, 761, 60))

        #         self.borderframe = QFrame(self)
        #         self.borderframe.setGeometry(QtCore.QRect(260, 35, 760, 60))
        #         self.borderframe.setStyleSheet("border: 1px solid black;")
        #         self.borderframe.show()

        self.frame.setStyleSheet("")
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.name = QtWidgets.QLabel(self.frame)
        self.name.setGeometry(QtCore.QRect(20, 20, 221, 20))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.name.setFont(font)
        self.name.setStyleSheet("")
        self.name.setObjectName("name")
        self.id = QtWidgets.QLabel(self.frame)
        self.id.setGeometry(QtCore.QRect(245, 20, 160, 16))
        self.id.setObjectName("id")
        self.grade = QtWidgets.QLabel(self.frame)
        self.grade.setGeometry(QtCore.QRect(470, 20, 71, 16))
        self.grade.setObjectName("grade")
        self.num_credits = QtWidgets.QLabel(self.frame)
        self.num_credits.setGeometry(QtCore.QRect(560, 20, 111, 16))
        self.num_credits.setObjectName("num_credits")
        self.gpa = QtWidgets.QLabel(self.frame)
        self.gpa.setGeometry(QtCore.QRect(685, 20, 61, 16))
        self.gpa.setObjectName("gpa")
        self.name_edit = QtWidgets.QLineEdit(self.frame)
        self.name_edit.setGeometry(QtCore.QRect(80, 20, 161, 16))
        self.name_edit.setObjectName("name_edit")
        self.id_edit = QtWidgets.QLineEdit(self.frame)
        self.id_edit.setGeometry(QtCore.QRect(265, 20, 85, 16))
        self.id_edit.setObjectName("id_edit")
        self.grade_edit = QtWidgets.QLineEdit(self.frame)
        self.grade_edit.setGeometry(QtCore.QRect(515, 20, 32, 16))
        self.grade_edit.setObjectName("grade_edit")
        # self.credits_edit = QtWidgets.QLineEdit(self.frame)
        # self.credits_edit.setGeometry(QtCore.QRect(645, 20, 32, 16))
        # self.credits_edit.setObjectName("credits_edit")
        #self.gpa_edit = QtWidgets.QLineEdit(self.frame)
        #self.gpa_edit.setGeometry(QtCore.QRect(720, 20, 32, 16))
        #self.gpa_edit.setObjectName("gpa_edit")
        self.edit_button = QtWidgets.QToolButton(self.frame)
        self.edit_button.setGeometry(QtCore.QRect(740, 40, 20, 20))
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap(str(schoolschedulerapp.__file__)[0:-12] + "/edit.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.edit_button.setIcon(icon2)
        self.edit_button.setObjectName("edit_button")
        font = QtGui.QFont()
        font.setKerning(True)

        self.tree_scroll_area = QtWidgets.QScrollArea(self.centralwidget)
        self.tree_scroll_area.setGeometry(QtCore.QRect(0, 20, 250, 680))
        self.tree_scroll_area.setWidgetResizable(True)
        self.tree_scroll_area.setObjectName("tree_scroll_area")

        self.list_tree = QtWidgets.QTreeWidget(self.centralwidget)
        self.list_tree.setColumnCount(2)
        self.list_tree.setGeometry(QtCore.QRect(0, 20, 250, 680))
        self.tree_scroll_area_WidgetContents = QtWidgets.QWidget()
        self.tree_scroll_area_WidgetContents.setGeometry(QtCore.QRect(0, 20, 250, 679))
        self.tree_scroll_area_WidgetContents.setObjectName("tree_scroll_area_WidgetContents")
        self.tree_scroll_area.setWidget(self.tree_scroll_area_WidgetContents)

        self.tree_scroll_bar = QtWidgets.QScrollBar(self.tree_scroll_area_WidgetContents)
        self.list_tree.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
        self.tree_scroll_area.setVerticalScrollBar(self.tree_scroll_bar)
        # self.students_tree = QtWidgets.QTreeWidget(self.tree_scroll_area_WidgetContents)
        self.tree_scroll_area.setWidget(self.tree_scroll_area_WidgetContents)

        self.list_tree.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.list_tree.setObjectName("list_tree")
        self.list_tree.setSortingEnabled(True)

        self.frame_2 = QtWidgets.QFrame(self.centralwidget)
        self.frame_2.setGeometry(QtCore.QRect(260, 80, 372, 275))
        self.frame_2.setStyleSheet("border-color: rgb(0, 0, 0);")
        self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_2.setObjectName("frame_2")

        #         self.borderframe2 = QFrame(self)
        #         self.borderframe2.setGeometry(QtCore.QRect(260, 106, 372, 275))
        #         self.borderframe2.setStyleSheet("border: 1px solid black;")
        #         self.borderframe2.show()

        self.preferences = QtWidgets.QLabel(self.frame_2)
        self.preferences.setGeometry(QtCore.QRect(20, 20, 241, 16))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.preferences.setFont(font)
        self.preferences.setStyleSheet("")
        self.preferences.setObjectName("preferences")
        self.preference1 = QtWidgets.QLabel(self.frame_2)
        self.preference1.setGeometry(QtCore.QRect(20, 56, 225, 15))
        self.preference1.setObjectName("preference1")
        self.preference2 = QtWidgets.QLabel(self.frame_2)
        self.preference2.setGeometry(QtCore.QRect(20, 86, 225, 15))
        self.preference2.setObjectName("preference2")
        self.preference3 = QtWidgets.QLabel(self.frame_2)
        self.preference3.setGeometry(QtCore.QRect(20, 116, 225, 15))
        self.preference3.setObjectName("preference3")
        self.preference4 = QtWidgets.QLabel(self.frame_2)
        self.preference4.setGeometry(QtCore.QRect(20, 146, 225, 15))
        self.preference4.setObjectName("preference4")
        self.preference5 = QtWidgets.QLabel(self.frame_2)
        self.preference5.setGeometry(QtCore.QRect(20, 176, 225, 15))
        self.preference5.setObjectName("preference5")
        self.preference6 = QtWidgets.QLabel(self.frame_2)
        self.preference6.setGeometry(QtCore.QRect(20, 206, 225, 15))
        self.preference6.setObjectName("preference6")
        self.pref1edit = QtWidgets.QLineEdit(self.frame_2)
        self.pref1edit.setGeometry(QtCore.QRect(40, 56, 211, 16))
        self.pref1edit.setObjectName("pref1edit")
        self.pref2edit = QtWidgets.QLineEdit(self.frame_2)
        self.pref2edit.setGeometry(QtCore.QRect(40, 86, 211, 16))
        self.pref2edit.setObjectName("pref2edit")
        self.pref3edit = QtWidgets.QLineEdit(self.frame_2)
        self.pref3edit.setGeometry(QtCore.QRect(40, 116, 211, 16))
        self.pref3edit.setObjectName("pref3edit")
        self.pref4edit = QtWidgets.QLineEdit(self.frame_2)
        self.pref4edit.setGeometry(QtCore.QRect(40, 146, 211, 16))
        self.pref4edit.setObjectName("pref4edit")
        self.pref5edit = QtWidgets.QLineEdit(self.frame_2)
        self.pref5edit.setGeometry(QtCore.QRect(40, 176, 211, 16))
        self.pref5edit.setObjectName("pref5edit")
        self.pref6edit = QtWidgets.QLineEdit(self.frame_2)
        self.pref6edit.setGeometry(QtCore.QRect(40, 206, 211, 16))
        self.pref6edit.setObjectName("pref6edit")
        self.preference7 = QtWidgets.QLabel(self.frame_2)
        self.preference7.setGeometry(QtCore.QRect(20, 236, 225, 15))
        self.preference7.setObjectName("preference7")
        self.pref7edit = QtWidgets.QLineEdit(self.frame_2)
        self.pref7edit.setGeometry(QtCore.QRect(40, 236, 211, 16))
        self.pref7edit.setObjectName("pref7edit")
        self.frame_3 = QtWidgets.QFrame(self.centralwidget)
        self.frame_3.setGeometry(QtCore.QRect(642, 80, 372, 275))
        self.frame_3.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_3.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_3.setObjectName("frame_3")

        # self.borderframe3 = QFrame(self)
        # self.borderframe3.setGeometry(QtCore.QRect(642, 106, 372, 275))
        # self.borderframe3.setStyleSheet("border: 1px solid black")
        # self.borderframe3.show()

        self.requirements_scroll = QtWidgets.QScrollArea(self.frame_3)
        self.requirements_scroll.setGeometry(QtCore.QRect(0, 0, 372, 275))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.requirements_scroll.sizePolicy().hasHeightForWidth())
        self.requirements_scroll.setSizePolicy(sizePolicy)
        self.requirements_scroll.setMinimumSize(QtCore.QSize(0, 100))
        self.requirements_scroll.setStyleSheet("")
        self.requirements_scroll.setWidgetResizable(True)
        self.requirements_scroll.setObjectName("requirements_scroll")
        self.scrollAreaWidgetContents_2 = QtWidgets.QWidget()
        self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 356, 942))
        self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents_2)
        self.verticalLayout.setObjectName("verticalLayout")
        self.requirements = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.requirements.setFont(font)
        self.requirements.setObjectName("requirements")
        self.verticalLayout.addWidget(self.requirements)
        self.label_fsa = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
        self.label_fsa.setObjectName("label_fsa")
        self.verticalLayout.addWidget(self.label_fsa)
        self.verticalLayout_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.checkBox_fsa_ela = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_fsa_ela.setObjectName("checkBox_fsa_ela")
        self.verticalLayout_2.addWidget(self.checkBox_fsa_ela)
        self.checkBox_fsa_algebra = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_fsa_algebra.setObjectName("checkBox_fsa_algebra")
        self.verticalLayout_2.addWidget(self.checkBox_fsa_algebra)
        self.verticalLayout.addLayout(self.verticalLayout_2)
        self.label_ela = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
        self.label_ela.setObjectName("label_ela")
        self.verticalLayout.addWidget(self.label_ela)
        self.checkBox_ela_1 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_ela_1.setObjectName("checkBox_ela_1")
        self.verticalLayout.addWidget(self.checkBox_ela_1)
        self.checkBox_ela_2 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_ela_2.setObjectName("checkBox_ela_2")
        self.verticalLayout.addWidget(self.checkBox_ela_2)
        self.checkBox_ela_3 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_ela_3.setObjectName("checkBox_ela_3")
        self.verticalLayout.addWidget(self.checkBox_ela_3)
        self.checkBox_ela_4 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_ela_4.setObjectName("checkBox_ela_4")
        self.verticalLayout.addWidget(self.checkBox_ela_4)
        self.label_math = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
        self.label_math.setObjectName("label_math")
        self.verticalLayout.addWidget(self.label_math)
        self.checkBox_algebra = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_algebra.setObjectName("checkBox_algebra")
        self.verticalLayout.addWidget(self.checkBox_algebra)
        self.checkBox_algebra_2 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_algebra_2.setObjectName("checkBox_algebra_2")
        self.verticalLayout.addWidget(self.checkBox_algebra_2)
        self.checkBox_geometry = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_geometry.setObjectName("checkBox_geometry")
        self.verticalLayout.addWidget(self.checkBox_geometry)
        self.checkBox_math_3 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_math_3.setObjectName("checkBox_math_3")
        self.verticalLayout.addWidget(self.checkBox_math_3)
        self.checkBox_math_4 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_math_4.setObjectName("checkBox_math_4")
        self.verticalLayout.addWidget(self.checkBox_math_4)
        self.label_science = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
        self.label_science.setObjectName("label_science")
        self.verticalLayout.addWidget(self.label_science)
        self.checkBox_bio = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_bio.setObjectName("checkBox_bio")
        self.verticalLayout.addWidget(self.checkBox_bio)
        self.checkBox_sci_2 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_sci_2.setObjectName("checkBox_sci_2")
        self.verticalLayout.addWidget(self.checkBox_sci_2)
        self.checkBox_sci_3 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_sci_3.setObjectName("checkBox_sci_3")
        self.verticalLayout.addWidget(self.checkBox_sci_3)
        self.label_social_studies = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
        self.label_social_studies.setObjectName("label_social_studies")
        self.verticalLayout.addWidget(self.label_social_studies)
        self.checkBox_history_us = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_history_us.setObjectName("checkBox_history_us")
        self.verticalLayout.addWidget(self.checkBox_history_us)
        self.checkBox_history_world = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_history_world.setObjectName("checkBox_history_world")
        self.verticalLayout.addWidget(self.checkBox_history_world)
        self.checkBox_gov = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_gov.setObjectName("checkBox_gov")
        self.verticalLayout.addWidget(self.checkBox_gov)
        self.checkBox_econ = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_econ.setObjectName("checkBox_econ")
        self.verticalLayout.addWidget(self.checkBox_econ)
        self.label_electives = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
        self.label_electives.setObjectName("label_electives")
        self.verticalLayout.addWidget(self.label_electives)
        self.checkBox_e1 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_e1.setObjectName("checkBox_e1")
        self.verticalLayout.addWidget(self.checkBox_e1)
        self.checkBox_e2 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_e2.setObjectName("checkBox_e2")
        self.verticalLayout.addWidget(self.checkBox_e2)
        self.checkBox_e3 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_e3.setObjectName("checkBox_e3")
        self.verticalLayout.addWidget(self.checkBox_e3)
        self.checkBox_e4 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_e4.setObjectName("checkBox_e4")
        self.verticalLayout.addWidget(self.checkBox_e4)
        self.checkBox_e5 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_e5.setObjectName("checkBox_e5")
        self.verticalLayout.addWidget(self.checkBox_e5)
        self.checkBox_e6 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_e6.setObjectName("checkBox_e6")
        self.verticalLayout.addWidget(self.checkBox_e6)
        self.checkBox_e7 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_e7.setObjectName("checkBox_e7")
        self.verticalLayout.addWidget(self.checkBox_e7)
        self.checkBox_e8 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_e8.setObjectName("checkBox_e8")
        self.verticalLayout.addWidget(self.checkBox_e8)
        self.label_other = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
        self.label_other.setObjectName("label_other")
        self.verticalLayout.addWidget(self.label_other)
        self.checkBox_art = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_art.setObjectName("checkBox_art")
        self.verticalLayout.addWidget(self.checkBox_art)
        self.checkBox_pe = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_pe.setObjectName("checkBox_pe")
        self.verticalLayout.addWidget(self.checkBox_pe)
        self.checkBox_online = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_2)
        self.checkBox_online.setObjectName("checkBox_online")
        self.verticalLayout.addWidget(self.checkBox_online)
        self.requirements_scroll.setWidget(self.scrollAreaWidgetContents_2)
        self.frame_4 = QtWidgets.QFrame(self.centralwidget)
        self.frame_4.setGeometry(QtCore.QRect(260, 365, 751, 355))
        self.frame_4.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_4.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_4.setObjectName("frame_4")

        #         self.borderframe4 = QFrame(self)
        #         self.borderframe4.setGeometry(QtCore.QRect(260, 391, 751, 355))
        #         self.borderframe4.setStyleSheet("border: 1px solid black;")
        #         self.borderframe4.show()

        self.label = QtWidgets.QLabel(self.frame_4)
        self.label.setGeometry(QtCore.QRect(20, 20, 151, 16))
        self.label.setObjectName("label")
        self.label.setFont(font)
        self.tableWidget = QtWidgets.QTableWidget(self.frame_4)
        self.tableWidget.setGeometry(QtCore.QRect(20, 56, 377, 131))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.tableWidget.sizePolicy().hasHeightForWidth())
        self.tableWidget.setSizePolicy(sizePolicy)
        self.tableWidget.setStyleSheet("")
        self.tableWidget.setCornerButtonEnabled(True)
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(3)
        self.tableWidget.setRowCount(3)
        self.tableWidget.verticalHeader().hide()
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(0, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(1, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(2, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setItem(0, 0, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setItem(0, 1, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setItem(0, 2, item)
        self.ok_button = QtWidgets.QPushButton(self.frame_4)
        self.ok_button.setGeometry(QtCore.QRect(661, 322, 80, 23))
        self.ok_button.setStyleSheet("")
        self.ok_button.setObjectName("ok_button")
        self.frame_3.raise_()
        self.dropdown.raise_()
        self.search_edit.raise_()
        self.search_button.raise_()
        self.plusbutton.raise_()
        self.frame.raise_()
        # self.scroll_area_name.raise_()
        self.frame_2.raise_()
        self.frame_4.raise_()
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1024, 20))
        self.menubar.setObjectName("menubar")
        self.menutoolbar = QtWidgets.QMenu(self.menubar)
        self.menutoolbar.setObjectName("menutoolbar")
        self.menuImport_Students = QtWidgets.QMenu(self.menutoolbar)
        self.menuImport_Students.setObjectName("menuImport_Students")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        MainWindow.setStatusBar(self.statusbar)
        self.actionImport_Teachers = QtWidgets.QAction(MainWindow)
        self.actionImport_Teachers.setObjectName("actionImport_Teachers")
        self.actionStudents = QtWidgets.QAction(MainWindow)
        self.actionStudents.setObjectName("actionStudents")
        self.actionSettings = QtWidgets.QAction(MainWindow)
        self.actionSettings.setObjectName("actionSettings")
        self.menuImport_Students.addAction(self.actionStudents)
        self.menuImport_Students.addSeparator()
        self.menuImport_Students.addSeparator()
        self.menuImport_Students.addSeparator()
        self.menutoolbar.addAction(self.menuImport_Students.menuAction())
        self.menutoolbar.addAction(self.actionImport_Teachers)
        self.menutoolbar.addAction(self.actionSettings)
        self.menubar.addAction(self.menutoolbar.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        # Set inital list on load
        self.populate_student_list()

        self.hide_edit_elements()
        self.plusbutton.clicked.connect(self.enter_add_mode)
        self.edit_button.clicked.connect(self.enter_edit_mode)
        self.ok_button.clicked.connect(self.exit_edit_mode)
        self.actionSettings.triggered.connect(self.open_colors_dialog)
        self.actionStudents.triggered.connect(self.open_input_dialog)
        # called in close input dialog, self.actionStudents.triggered.connect(lambda: self.createFakeDataBase())
        # Change name refactor later TODO
        self.actionImport_Teachers.triggered.connect(self.open_export_dialog)
        self.list_tree.itemClicked.connect(
            lambda: self.search_by_id_tree_select(self.list_tree.currentItem().text(1)))
        self.list_tree.itemClicked.connect(lambda: print(self.list_tree.currentItem().text(1)))
        self.dropdown.activated.connect(lambda: self.update_dropdown())

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Scheduler"))
        self.dropdown.setItemText(0, _translate("MainWindow", "Students"))
        self.dropdown.setItemText(1, _translate("MainWindow", "Courses"))
        self.plusbutton.setText(_translate("MainWindow", "+"))
        self.name.setText(_translate("MainWindow", "Name:"))
        self.id.setText(_translate("MainWindow", "ID:"))
        self.grade.setText(_translate("MainWindow", "Grade: "))
        self.num_credits.setText(_translate("MainWindow", "Total Credits: "))
        self.gpa.setText(_translate("MainWindow", "GPA: "))
        self.edit_button.setText(_translate("MainWindow", "..."))

        self.list_tree.headerItem().setText(0, _translate("MainWindow", "Name"))
        self.list_tree.headerItem().setText(1, _translate("MainWindow", "ID"))
        __sortingEnabled = self.list_tree.isSortingEnabled()
        self.list_tree.setSortingEnabled(False)
        self.list_tree.setSortingEnabled(__sortingEnabled)

        self.preferences.setText(_translate("MainWindow", "Course Preferences"))
        self.preference1.setText(_translate("MainWindow", "1. "))
        self.preference2.setText(_translate("MainWindow", "2. "))
        self.preference3.setText(_translate("MainWindow", "3. "))
        self.preference4.setText(_translate("MainWindow", "4. "))
        self.preference5.setText(_translate("MainWindow", "5. "))
        self.preference6.setText(_translate("MainWindow", "6. "))
        self.preference7.setText(_translate("MainWindow", "7. "))
        self.requirements.setText(_translate("MainWindow", "Graduation Requirements"))
        self.label_fsa.setText(_translate("MainWindow", "State Assessments"))
        self.checkBox_fsa_ela.setText(_translate("MainWindow", "FSA ELA"))
        self.checkBox_fsa_algebra.setText(_translate("MainWindow", "FSA Algebra 1 EOC"))
        self.label_ela.setText(_translate("MainWindow", "ELA"))
        self.checkBox_ela_1.setText(_translate("MainWindow", "English 1"))
        self.checkBox_ela_2.setText(_translate("MainWindow", "English 2"))
        self.checkBox_ela_3.setText(_translate("MainWindow", "English 3"))
        self.checkBox_ela_4.setText(_translate("MainWindow", "English 4"))
        self.label_math.setText(_translate("MainWindow", "Mathematics"))
        self.checkBox_algebra.setText(_translate("MainWindow", "Algebra 1"))
        self.checkBox_algebra_2.setText(_translate("MainWindow", "Algebra 2"))
        self.checkBox_geometry.setText(_translate("MainWindow", "Geometry"))
        self.checkBox_math_3.setText(_translate("MainWindow", "Mathematrics 3rd Credit"))
        self.checkBox_math_4.setText(_translate("MainWindow", "Mathematics 4th Credit"))
        self.label_science.setText(_translate("MainWindow", "Science"))
        self.checkBox_bio.setText(_translate("MainWindow", "Biology"))
        self.checkBox_sci_2.setText(_translate("MainWindow", "Science 2nd Credit"))
        self.checkBox_sci_3.setText(_translate("MainWindow", "Science 3rd Credit"))
        self.label_social_studies.setText(_translate("MainWindow", "Social Studies"))
        self.checkBox_history_us.setText(_translate("MainWindow", "U.S. History"))
        self.checkBox_history_world.setText(_translate("MainWindow", "World History"))
        self.checkBox_gov.setText(_translate("MainWindow", "U.S. Government"))
        self.checkBox_econ.setText(_translate("MainWindow", "Economics"))
        self.label_electives.setText(_translate("MainWindow", "Electives"))
        self.checkBox_e1.setText(_translate("MainWindow", "Elective 1"))
        self.checkBox_e2.setText(_translate("MainWindow", "Elective 2"))
        self.checkBox_e3.setText(_translate("MainWindow", "Elective 3"))
        self.checkBox_e4.setText(_translate("MainWindow", "Elective 4"))
        self.checkBox_e5.setText(_translate("MainWindow", "Elective 5"))
        self.checkBox_e6.setText(_translate("MainWindow", "Elective 6"))
        self.checkBox_e7.setText(_translate("MainWindow", "Elective 7"))
        self.checkBox_e8.setText(_translate("MainWindow", "Elective 8"))
        self.label_other.setText(_translate("MainWindow", "Other"))
        self.checkBox_art.setText(_translate("MainWindow", "Fine and Performing Arts"))
        self.checkBox_pe.setText(_translate("MainWindow", "Physical Education"))
        self.checkBox_online.setText(_translate("MainWindow", "Online "))
        self.label.setText(_translate("MainWindow", "Past Coursework"))
        item = self.tableWidget.horizontalHeaderItem(0)
        item.setText(_translate("MainWindow", "Name"))
        item = self.tableWidget.horizontalHeaderItem(1)
        item.setText(_translate("MainWindow", "Credits"))
        item = self.tableWidget.horizontalHeaderItem(2)
        item.setText(_translate("MainWindow", "Grade"))
        stylesheet = "::section{border-radius:14px;}"
        self.tableWidget.horizontalHeader().setStyleSheet(stylesheet)
        self.tableWidget.setRowCount(3)
        self.tableWidget.setFixedWidth(302)
        self.tableWidget.setFixedHeight(128)
        __sortingEnabled = self.tableWidget.isSortingEnabled()
        self.tableWidget.setSortingEnabled(False)
        #         item = self.tableWidget.item(0, 0)
        #         item.setText(_translate("MainWindow", "Algebra 1"))
        #         item = self.tableWidget.item(0, 1)
        #         item.setText(_translate("MainWindow", "1"))
        #         item = self.tableWidget.item(0, 2)
        #         item.setText(_translate("MainWindow", "A"))
        self.tableWidget.setSortingEnabled(__sortingEnabled)
        self.ok_button.setText(_translate("MainWindow", "Ok"))
        self.menutoolbar.setTitle(_translate("MainWindow", "File"))
        self.menuImport_Students.setTitle(_translate("MainWindow", "Import Students"))
        self.actionImport_Teachers.setText(_translate("MainWindow", "Export Schedules"))
        self.actionStudents.setText(_translate("MainWindow", "Students"))
        self.actionSettings.setText(_translate("MainWindow", "Settings"))

    def check_box_enabled(self, tf):
        self.checkBox_fsa_ela.setEnabled(tf)
        self.checkBox_fsa_algebra.setEnabled(tf)
        self.checkBox_ela_1.setEnabled(tf)
        self.checkBox_ela_2.setEnabled(tf)
        self.checkBox_ela_3.setEnabled(tf)
        self.checkBox_ela_4.setEnabled(tf)
        self.checkBox_algebra.setEnabled(tf)
        self.checkBox_algebra_2.setEnabled(tf)
        self.checkBox_geometry.setEnabled(tf)
        self.checkBox_math_3.setEnabled(tf)
        self.checkBox_math_4.setEnabled(tf)
        self.checkBox_pe.setEnabled(tf)
        self.checkBox_bio.setEnabled(tf)
        self.checkBox_sci_2.setEnabled(tf)
        self.checkBox_sci_3.setEnabled(tf)
        self.checkBox_history_us.setEnabled(tf)
        self.checkBox_history_world.setEnabled(tf)
        self.checkBox_econ.setEnabled(tf)
        self.checkBox_gov.setEnabled(tf)
        self.checkBox_e1.setEnabled(tf)
        self.checkBox_e2.setEnabled(tf)
        self.checkBox_e3.setEnabled(tf)
        self.checkBox_e4.setEnabled(tf)
        self.checkBox_e5.setEnabled(tf)
        self.checkBox_e6.setEnabled(tf)
        self.checkBox_e7.setEnabled(tf)
        self.checkBox_e8.setEnabled(tf)
        self.checkBox_art.setEnabled(tf)
        self.checkBox_pe.setEnabled(tf)
        self.checkBox_online.setEnabled(tf)

    def hide_edit_elements(self):
        self.name_edit.hide()
        self.id_edit.hide()
        self.grade_edit.hide()
        # self.credits_edit.hide()
        # self.gpa_edit.hide()
        self.pref1edit.hide()
        self.pref2edit.hide()
        self.pref3edit.hide()
        self.pref4edit.hide()
        self.pref5edit.hide()
        self.pref6edit.hide()
        self.pref7edit.hide()
        self.check_box_enabled(False)
        self.ok_button.hide()
        self.ok_button.setEnabled(False)

    def show_edit_elements(self):
        self.name_edit.show()
        self.id_edit.show()
        self.grade_edit.show()
        #self.credits_edit.show()
        #self.gpa_edit.show()
        self.pref1edit.show()
        self.pref2edit.show()
        self.pref3edit.show()
        self.pref4edit.show()
        self.pref5edit.show()
        self.pref6edit.show()
        self.pref7edit.show()
        self.ok_button.show()
        self.ok_button.setEnabled(True)

    def enter_add_mode(self):
        self.clear_shown_student()
        self.clear_edit_fields()
        self.show_edit_elements()
        self.tableWidget.clear()
        self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.AllEditTriggers)
        self.tableWidget.setHorizontalHeaderItem(0, QtWidgets.QTableWidgetItem("Name"))
        self.tableWidget.setHorizontalHeaderItem(1, QtWidgets.QTableWidgetItem("Credits"))
        self.tableWidget.setHorizontalHeaderItem(2, QtWidgets.QTableWidgetItem("Grade"""))
        #self.check_box_enabled(True)

    def enter_edit_mode(self):

        if self.name_edit.isHidden():
            if self.name.text() != "Name: ":
                self.set_edit_elements()
                session.delete(Student.by_id(int(self.id.text().split(' ')[2])))
                self.clear_shown_student()
            self.show_edit_elements()
            #self.check_box_enabled(True)

    def set_edit_elements(self):
        self.name_edit.setText(self.name.text().split(" ")[1] + " " + self.name.text().split(" ")[2])
        self.id_edit.setText(self.id.text().split(" ")[2])
        self.grade_edit.setText(self.grade.text().split(" ")[1])
        # self.credits_edit.setText(self.num_credits.text().split(" ")[2]) # should be 2 but credits are not being set
        # self.gpa_edit.setText(self.gpa.text().split(" ")[1])
        self.pref1edit.setText(" ".join(self.preference1.text().split(" ")[1:]))
        self.pref2edit.setText(" ".join(self.preference2.text().split(" ")[1:]))
        self.pref3edit.setText(" ".join(self.preference3.text().split(" ")[1:]))
        self.pref4edit.setText(" ".join(self.preference4.text().split(" ")[1:]))
        self.pref5edit.setText(" ".join(self.preference5.text().split(" ")[1:]))
        self.pref6edit.setText(" ".join(self.preference6.text().split(" ")[1:]))
        self.pref7edit.setText(" ".join(self.preference7.text().split(" ")[1:]))
        self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.AllEditTriggers)

    def clear_shown_student(self):
        self.name.setText("Name: ")
        self.id.setText("ID: ")
        self.grade.setText("Grade: ")
        self.num_credits.setText("Credits: ")
        self.gpa.setText("GPA: ")
        self.preference1.setText("1. ")
        self.preference2.setText("2. ")
        self.preference3.setText("3. ")
        self.preference4.setText("4. ")
        self.preference5.setText("5. ")
        self.preference6.setText("6. ")
        self.preference7.setText("7. ")

    def clear_edit_fields(self):
        self.name_edit.setText("")
        self.id_edit.setText("")
        self.grade_edit.setText("")
        # self.gpa_edit.setText("")
        # self.credits_edit.setText("")
        self.pref1edit.setText("")
        self.pref2edit.setText("")
        self.pref3edit.setText("")
        self.pref4edit.setText("")
        self.pref5edit.setText("")
        self.pref6edit.setText("")
        self.pref7edit.setText("")

    def exit_edit_mode(self):
        if self.name_edit.text() != "":
            try:
                self.create_new_student()
            except ValueError:
                self.open_error_dialog()
        self.clear_edit_fields()
        self.hide_edit_elements()
        self.check_box_enabled(False)
        self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.tableWidget.setHorizontalHeaderItem(0, QtWidgets.QTableWidgetItem("Name"))
        self.tableWidget.setHorizontalHeaderItem(1, QtWidgets.QTableWidgetItem("Credits"))
        self.tableWidget.setHorizontalHeaderItem(2, QtWidgets.QTableWidgetItem("Grade"))

    def search_mode(self, name, index):
        if index == 0:
            students_list = Student.get_all()
            self.list_tree.clear()

            for student in students_list:
                if name in (student.last + ", " + student.first):
                    item_name = QtWidgets.QTreeWidgetItem(self.list_tree)
                    item_name.setText(0, student.last + ", " + student.first)
                    item_name.setData(1, QtCore.Qt.DisplayRole, student.id)

    def create_new_student(self):
        name = self.name_edit.text()
        first_last = name.split(" ", 2)
        s = Student.by_id(int(self.id_edit.text()))
        if s != None:
            s.first = first_last[0]
            s.last = first_last[1]
            s.grade = float(self.grade_edit.text())
        else:
            Student.insert(int(self.id_edit.text()), first_last[0], first_last[1], float(self.grade_edit.text()))
        self.save_course_history(int(self.id_edit.text()))
        self.save_preferences(int(self.id_edit.text()))
        self.clear_edit_fields()
        self.tableWidget.clear()
        self.refresh_list()

    def refresh_list(self):
        self.list_tree.clear()
        students_list = Student.get_all()
        self.populate_student_list()

    def set_color_1(self, id):
        color = get_color_string(id)
        self.name.setStyleSheet(color)
        # self.borderframe2.setStyleSheet("border: 1px solid; border-" + color)
        # self.borderframe3.setStyleSheet("border: 1px solid; border-" + color)
        self.label.setStyleSheet(color)

    def set_color_2(self, id):
        color = get_color_string(id)
        self.preferences.setStyleSheet(color)
        self.requirements.setStyleSheet(color)
        self.ok_button.setStyleSheet("background-" + color)
        # self.borderframe.setStyleSheet("border: 1px solid; border-" + color)
        # self.borderframe4.setStyleSheet("border: 1px solid; border-" + color)

    def open_colors_dialog(self):
        colors_dialog = QDialog(self)
        colors_dialog.setObjectName("colors_dialog")
        colors_dialog.resize(600, 300)

        self.buttonBox = QtWidgets.QDialogButtonBox(colors_dialog)
        self.buttonBox.setGeometry(QtCore.QRect(30, 238, 341, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.label_1 = QtWidgets.QLabel(colors_dialog)
        self.label_1.setGeometry(QtCore.QRect(30, 30, 211, 16))
        self.label_1.setObjectName("label_1")
        self.label_2 = QtWidgets.QLabel(colors_dialog)
        self.label_2.setGeometry(QtCore.QRect(30, 130, 101, 16))
        self.label_2.setObjectName("label_2")
        self.red_button_1 = QtWidgets.QRadioButton(colors_dialog)
        self.red_button_1.setGeometry(QtCore.QRect(40, 50, 100, 21))
        self.red_button_1.setObjectName("red_button_1")
        self.buttonGroup = QtWidgets.QButtonGroup(colors_dialog)
        self.buttonGroup.setObjectName("buttonGroup")
        self.buttonGroup.addButton(self.red_button_1, 1)
        self.blue_button_1 = QtWidgets.QRadioButton(colors_dialog)
        self.blue_button_1.setGeometry(QtCore.QRect(40, 90, 100, 21))
        self.blue_button_1.setObjectName("blue_button_1")
        self.buttonGroup.addButton(self.blue_button_1, 2)
        self.orange_button_1 = QtWidgets.QRadioButton(colors_dialog)
        self.orange_button_1.setGeometry(QtCore.QRect(150, 50, 100, 21))
        self.orange_button_1.setObjectName("orange_button_1")
        self.buttonGroup.addButton(self.orange_button_1, 3)
        self.purple_button_1 = QtWidgets.QRadioButton(colors_dialog)
        self.purple_button_1.setGeometry(QtCore.QRect(150, 90, 100, 21))
        self.purple_button_1.setObjectName("purple_button_1")
        self.buttonGroup.addButton(self.purple_button_1, 4)
        self.yellow_button_1 = QtWidgets.QRadioButton(colors_dialog)
        self.yellow_button_1.setGeometry(QtCore.QRect(260, 50, 100, 21))
        self.yellow_button_1.setObjectName("yellow_button_1")
        self.buttonGroup.addButton(self.yellow_button_1, 5)
        self.black_button_1 = QtWidgets.QRadioButton(colors_dialog)
        self.black_button_1.setGeometry(QtCore.QRect(260, 90, 100, 21))
        self.black_button_1.setObjectName("black_button_1")
        self.buttonGroup.addButton(self.black_button_1, 6)
        self.green_button_1 = QtWidgets.QRadioButton(colors_dialog)
        self.green_button_1.setGeometry(QtCore.QRect(380, 50, 100, 21))
        self.green_button_1.setObjectName("green_button_1")
        self.buttonGroup.addButton(self.green_button_1, 7)
        self.white_button_1 = QtWidgets.QRadioButton(colors_dialog)
        self.white_button_1.setGeometry(QtCore.QRect(380, 90, 100, 21))
        self.white_button_1.setObjectName("white_button_1")
        self.buttonGroup.addButton(self.white_button_1, 8)
        self.red_button_2 = QtWidgets.QRadioButton(colors_dialog)
        self.red_button_2.setGeometry(QtCore.QRect(40, 150, 100, 21))
        self.red_button_2.setObjectName("red_button_2")
        self.buttonGroup_2 = QtWidgets.QButtonGroup(colors_dialog)
        self.buttonGroup_2.setObjectName("buttonGroup_2")
        self.buttonGroup_2.addButton(self.red_button_2, 1)
        self.blue_button_2 = QtWidgets.QRadioButton(colors_dialog)
        self.blue_button_2.setGeometry(QtCore.QRect(40, 190, 100, 21))
        self.blue_button_2.setObjectName("blue_button_2", )
        self.buttonGroup_2.addButton(self.blue_button_2, 2)
        self.purple_button_2 = QtWidgets.QRadioButton(colors_dialog)
        self.purple_button_2.setGeometry(QtCore.QRect(150, 190, 100, 21))
        self.purple_button_2.setObjectName("purple_button_2")
        self.buttonGroup_2.addButton(self.purple_button_2, 4)
        self.yellow_button_2 = QtWidgets.QRadioButton(colors_dialog)
        self.yellow_button_2.setGeometry(QtCore.QRect(260, 150, 100, 21))
        self.yellow_button_2.setObjectName("yellow_button_2")
        self.buttonGroup_2.addButton(self.yellow_button_2, 5)
        self.green_button_2 = QtWidgets.QRadioButton(colors_dialog)
        self.green_button_2.setGeometry(QtCore.QRect(380, 150, 100, 21))
        self.green_button_2.setObjectName("green_button_2")
        self.buttonGroup_2.addButton(self.green_button_2, 7)
        self.black_button_2 = QtWidgets.QRadioButton(colors_dialog)
        self.black_button_2.setGeometry(QtCore.QRect(260, 190, 100, 21))
        self.black_button_2.setObjectName("black_button_2")
        self.buttonGroup_2.addButton(self.black_button_2, 6)
        self.orange_button_2 = QtWidgets.QRadioButton(colors_dialog)
        self.orange_button_2.setGeometry(QtCore.QRect(150, 150, 100, 21))
        self.orange_button_2.setObjectName("orange_button_2")
        self.buttonGroup_2.addButton(self.orange_button_2, 3)
        self.white_button_2 = QtWidgets.QRadioButton(colors_dialog)
        self.white_button_2.setGeometry(QtCore.QRect(380, 190, 100, 21))
        self.white_button_2.setObjectName("white_button_2")
        self.buttonGroup_2.addButton(self.white_button_2, 8)

        _translate = QtCore.QCoreApplication.translate
        colors_dialog.setWindowTitle(_translate("colors_dialog", "Dialog"))
        self.label_1.setText(_translate("colors_dialog", "Select Color 1:"))
        self.label_2.setText(_translate("colors_dialog", "Select Color 2:"))
        self.red_button_1.setText(_translate("colors_dialog", "Red"))
        self.blue_button_1.setText(_translate("colors_dialog", "Blue"))
        self.orange_button_1.setText(_translate("colors_dialog", "Orange"))
        self.purple_button_1.setText(_translate("colors_dialog", "Purple"))
        self.yellow_button_1.setText(_translate("colors_dialog", "Yellow"))
        self.black_button_1.setText(_translate("colors_dialog", "Black"))
        self.green_button_1.setText(_translate("colors_dialog", "Green"))
        self.white_button_1.setText(_translate("colors_dialog", "White"))
        self.red_button_2.setText(_translate("colors_dialog", "Red"))
        self.blue_button_2.setText(_translate("colors_dialog", "Blue"))
        self.purple_button_2.setText(_translate("colors_dialog", "Purple"))
        self.yellow_button_2.setText(_translate("colors_dialog", "Yellow"))
        self.green_button_2.setText(_translate("colors_dialog", "Green"))
        self.black_button_2.setText(_translate("colors_dialog", "Black"))
        self.orange_button_2.setText(_translate("colors_dialog", "Orange"))
        self.white_button_2.setText(_translate("colors_dialog", "White"))

        self.buttonBox.accepted.connect(lambda: self.set_color_1(self.buttonGroup.checkedId()))
        self.buttonBox.accepted.connect(lambda: self.set_color_2(self.buttonGroup_2.checkedId()))
        self.buttonBox.accepted.connect(colors_dialog.accept)
        self.buttonBox.rejected.connect(colors_dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(colors_dialog)
        colors_dialog.show()
        
    def open_input_dialog(self):

        if not os.path.isfile("./import/Data.xlsx"):
            msg = QMessageBox()
            msg.setWindowTitle("Database Not Found")
            msg.setText("A valid Database was not found generating test data Standby")
            msg.exec_()
            generate_test_data()

        import_dialog = QDialog(self)
        import_dialog.setObjectName("Dialog")
        import_dialog.resize(400, 193)
        self.buttonBox = QtWidgets.QDialogButtonBox(import_dialog)
        self.buttonBox.setGeometry(QtCore.QRect(31, 140, 341, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.label = QtWidgets.QLabel(import_dialog)
        self.label.setGeometry(QtCore.QRect(28, 28, 331, 16))
        self.label.setObjectName("label")
        self.lineEdit = QtWidgets.QLineEdit(import_dialog)
        self.lineEdit.setGeometry(QtCore.QRect(28, 72, 291, 23))
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit.setText(str(schoolschedulerapp.__file__)[0:-12] + "/import/Data.xlsx")
        import_dialog.setWindowTitle("Dialog")
        self.label.setText("Enter the location of the file you wish to import:")
        self.buttonBox.accepted.connect(lambda: self.createFakeDataBase(self.lineEdit.text()))
        self.buttonBox.accepted.connect(import_dialog.accept)
        self.buttonBox.rejected.connect(import_dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(import_dialog)
        import_dialog.show()

    def open_export_dialog(self):
        if not os.path.isfile(str(schoolschedulerapp.__file__)[0:-12] + "/import/Data.xlsx"):
            msg = QMessageBox()
            msg.setWindowTitle("Database Not Found")
            msg.setText("A valid Database was not found generating test data Standby")
            msg.exec_()
            generate_test_data()
            self.createFakeDataBase()


        export_dialog = QDialog(self)
        export_dialog.setObjectName("Dialog")
        export_dialog.resize(540, 193)
        self.buttonBox = QtWidgets.QDialogButtonBox(export_dialog)
        self.buttonBox.setGeometry(QtCore.QRect(31, 140, 441, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.label2 = QtWidgets.QLabel(export_dialog)
        self.label2.setGeometry(QtCore.QRect(28, 28, 460, 32))
        self.label2.setObjectName("label2")
        export_dialog.setWindowTitle("Dialog")
        self.label2.setText('Exported files will be found in the folder named "Export" \n' + str(schoolschedulerapp.__file__)[0:-12] + '\\export')
        self.buttonBox.accepted.connect(export_dialog.accept)
        self.buttonBox.rejected.connect(export_dialog.reject)
        export_dialog.accepted.connect(lambda: generate_schedule())

        export_dialog.show()

        # export_dialog.accepted.connect(generate_schedule())

    def open_error_dialog(self):
        error_dialog = QDialog(self)
        error_dialog.setObjectName("Dialog")
        error_dialog.resize(400, 193)
        self.buttonBox = QtWidgets.QDialogButtonBox(error_dialog)
        self.buttonBox.setGeometry(QtCore.QRect(31, 140, 341, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.plainTextEdit = QtWidgets.QPlainTextEdit(error_dialog)
        self.plainTextEdit.setGeometry(QtCore.QRect(30, 30, 331, 51))
        self.plainTextEdit.setObjectName("plainTextEdit")
        error_dialog.setWindowTitle("Dialog")
        self.plainTextEdit.setPlainText("Error: please ensure first and last name and a unique integer ID have been entered")
        self.buttonBox.accepted.connect(error_dialog.accept)
        self.buttonBox.rejected.connect(error_dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(error_dialog)
        error_dialog.show()

    # Do not Use Deprecated
    def show_student(self, student):
        self.name.setText("Name: " + student.first + " " + student.last)
        self.id.setText("ID: " + str(student.id))
        self.gpa.setText("GPA: " + str(student.gpa))
        raise Exception('Deprecated see search_by_id_tree_select')

    # Expensive call
    def populate_student_list(self):
        students_list = Student.get_all()
        self.list_tree.clear()

        for student in students_list:
            item_name = QtWidgets.QTreeWidgetItem(self.list_tree)
            item_name.setText(0, student.last + ", " + student.first)
            item_name.setData(1, QtCore.Qt.DisplayRole, student.id)

    # Expensive call
    def populate_course_list(self):
        course_list = Course.get_all()
        self.list_tree.clear()
        for course in course_list:
            item_name = QtWidgets.QTreeWidgetItem(self.list_tree)
            item_name.setText(0, str(course.name))
            item_name.setData(1, QtCore.Qt.DisplayRole, course.id)

    def update_dropdown(self):
        if self.dropdown.currentText() == "Courses":
            self.populate_course_list()
            return
        if self.dropdown.currentText() == "Students":
            self.populate_student_list()
            return

    def createFakeDataBase(self, path="./import/Data.xlsx"):
        import_data(path)
        self.populate_student_list()

    # Search should also apply to teachers in future
    def search_by_id_tree_select(self, id_request):
        self.clear_shown_student()
        students_list = Student.get_all()
        course_list = Course.get_all()
        self.tableWidget.clear()

        if self.dropdown.currentText() == "Courses":
            for course in course_list:
                if course.id == int(id_request):
                    self.name.setText("Name: " + str(course.name))
                    return

        for student in students_list:
            if student.id == int(id_request):
                self.name.setText("Name: " + student.first + " " + student.last)
                self.id.setText("Student ID: " + str(student.id))
                self.grade.setText("Grade: " + str(student.grade))
                self.num_credits.setText("Total Credits: " + str(student.credits))
                self.gpa.setText("GPA: " + str(student.gpa))

                qline = [self.preference1, self.preference2, self.preference3, self.preference4, self.preference5,
                         self.preference6, self.preference7]

                pref = Preference.by_student_id(student.id)

                x = 0

                for p in pref:
                    if x < 7:
                        course_id = pref[x].course_id
                        qline[x].setText(str(x + 1) + '. ' + str(Course.by_id(course_id).name))
                        x += 1

                self.load_grad_requirements(student.id)

                classes = Class_History.by_student_id(student.id)
                index = 0

                self.tableWidget.setHorizontalHeaderItem(0, QtWidgets.QTableWidgetItem("Name"))
                self.tableWidget.setHorizontalHeaderItem(1, QtWidgets.QTableWidgetItem("Credits"))
                self.tableWidget.setHorizontalHeaderItem(2, QtWidgets.QTableWidgetItem("Grade"""))

                if len(classes) == 0:
                    self.tableWidget.setRowCount(3)
                    self.tableWidget.setFixedWidth(302)
                    self.tableWidget.setFixedHeight(128)
                else:
                    self.tableWidget.setRowCount(len(classes))
                    self.tableWidget.setFixedWidth(319)


                for c in classes:
                    self.tableWidget.setItem(index, 0, QtWidgets.QTableWidgetItem(c.class_name))
                    self.tableWidget.setItem(index, 1, QtWidgets.QTableWidgetItem(str(c.credit)))
                    self.tableWidget.setItem(index, 2, QtWidgets.QTableWidgetItem(str(c.grade)))
                    index += 1
                self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)

    def load_grad_requirements(self, id):
        self.clear_grad_requirements()
        for c in Class_History.by_student_id(id):
            if c.class_name == 'ELA 1': self.checkBox_ela_1.setChecked(True)
            elif c.class_name == 'ELA 2': self.checkBox_ela_2.setChecked(True)
            elif c.class_name == 'ELA 3': self.checkBox_ela_3.setChecked(True)
            elif c.class_name == 'ELA 4': self.checkBox_ela_4.setChecked(True)
            elif c.class_name == 'Algebra 1': self.checkBox_algebra.setChecked(True)
            elif c.class_name == 'Algebra 2': self.checkBox_algebra_2.setChecked(True)
            elif c.class_name == 'Geometry': self.checkBox_geometry.setChecked(True)
            elif c.class_name == 'ADV MATH 1': self.checkBox_math_3.setChecked(True)
            elif c.class_name == 'ADV MATH 2': self.checkBox_math_4.setChecked(True)
            elif c.class_name == 'Biology 1': self.checkBox_bio.setChecked(True)
            elif c.class_name == 'Science Class 1': self.checkBox_sci_2.setChecked(True)
            elif c.class_name == 'Science Class 2': self.checkBox_sci_3.setChecked(True)
            elif c.class_name == 'U.S. History': self.checkBox_history_us.setChecked(True)
            elif c.class_name == 'World History': self.checkBox_history_world.setChecked(True)
            elif c.class_name == 'U.S. Government': self.checkBox_gov.setChecked(True)
            elif c.class_name == 'Economics': self.checkBox_econ.setChecked(True)
            elif c.class_name == 'Elective 1': self.checkBox_e1.setChecked(True)
            elif c.class_name == 'Elective 2': self.checkBox_e2.setChecked(True)
            elif c.class_name == 'Elective 3': self.checkBox_e3.setChecked(True)
            elif c.class_name == 'Elective 4': self.checkBox_e4.setChecked(True)
            elif c.class_name == 'Elective 5': self.checkBox_e5.setChecked(True)
            elif c.class_name == 'Elective 6': self.checkBox_e6.setChecked(True)
            elif c.class_name == 'Elective 7': self.checkBox_e7.setChecked(True)
            elif c.class_name == 'Elective 8': self.checkBox_e8.setChecked(True)
            elif c.class_name == 'ART 1': self.checkBox_art.setChecked(True)
            elif c.class_name == 'ART 2': self.checkBox_pe.setChecked(True)
            elif c.class_name == 'ART 3': self.checkBox_online.setChecked(True)

    def clear_grad_requirements(self):
        self.checkBox_ela_1.setChecked(False)
        self.checkBox_ela_2.setChecked(False)
        self.checkBox_ela_3.setChecked(False)
        self.checkBox_ela_4.setChecked(False)
        self.checkBox_algebra.setChecked(False)
        self.checkBox_algebra_2.setChecked(False)
        self.checkBox_geometry.setChecked(False)
        self.checkBox_math_3.setChecked(False)
        self.checkBox_math_4.setChecked(False)
        self.checkBox_bio.setChecked(False)
        self.checkBox_sci_2.setChecked(False)
        self.checkBox_sci_3.setChecked(False)
        self.checkBox_history_us.setChecked(False)
        self.checkBox_history_world.setChecked(False)
        self.checkBox_gov.setChecked(False)
        self.checkBox_econ.setChecked(False)
        self.checkBox_e1.setChecked(False)
        self.checkBox_e2.setChecked(False)
        self.checkBox_e3.setChecked(False)
        self.checkBox_e4.setChecked(False)
        self.checkBox_e5.setChecked(False)
        self.checkBox_e6.setChecked(False)
        self.checkBox_e7.setChecked(False)
        self.checkBox_e8.setChecked(False)
        self.checkBox_art.setChecked(False)
        self.checkBox_pe.setChecked(False)
        self.checkBox_online.setChecked(False)

    def save_course_history(self, student_id):
        rows = self.tableWidget.rowCount()

        classes = Class_History.by_student_id(student_id)
        for c in classes:
            c.class_name = self.tableWidget.item(len(classes)-rows, 0).text()
            c.credit = int(self.tableWidget.item(len(classes)-rows, 1).text())
            c.grade = self.tableWidget.item(len(classes)-rows, 2).text()
            rows -= 1

        for i in range(rows):
            if self.tableWidget.item(i, 0) != None and self.tableWidget.item(i, 1) != None and self.tableWidget.item(i,2) != None and \
                    self.tableWidget.item(i, 0).text() != '' and self.tableWidget.item(i, 1).text() != '' and self.tableWidget.item(i, 2).text() != '':
                Class_History.insert(student_id, self.tableWidget.item(i, 0).text(), int(self.tableWidget.item(i, 1).text()), self.tableWidget.item(i, 2).text())
        Student.update_computed(student_id)

    def save_preferences(self, student_id):
        preferences = Preference.by_student_id(student_id)
        qline = [self.pref1edit, self.pref2edit, self.pref3edit, self.pref4edit, self.pref5edit, self.pref6edit,
                 self.pref7edit]

        # try to update existing preferences
        index = 0
        for p in preferences:
            if qline[7 - len(qline) - index].text() != None and Course.by_name(qline[0].text()) != None:
                p.course_id = Course.by_name(qline[7 - len(qline) - index].text()).id
                qline.pop(7 - len(qline) - index)
                index += 1

        # update remaining
        idx = 0
        for q in qline:
            if q.text() != '' and Course.by_name(q.text()) != None:
                Preference.insert(Course.by_name(q.text()).id, student_id, len(preferences) + idx)
                idx += 1
        session.commit()

# self.checkBox_fsa_ela.setEnabled = True
# self.checkBox_fsa_algebra.setEnabled = True

def get_color_string(id):
    color_string = "color: "
    if id == 1:
        color_string += "rgb(255, 0, 0)"  # red
    elif id == 2:
        color_string += "rgb(0, 0, 127)"  # blue
    elif id == 3:
        color_string += "rgb(255, 85, 0)"  # orange
    elif id == 4:
        color_string += "rgb(85, 0, 127)"  # purple
    elif id == 5:
        color_string += "rgb(255, 210, 5)"  # yellow
    elif id == 6:
        color_string += "rgb(255, 255, 255)"  # black
    elif id == 7:
        color_string += "rgb(0, 170, 0)"  # green
    else:
        color_string += "rgb(0, 0, 0)"  # white
    return color_string
