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

# Form implementation generated from reading ui file 'mainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
import sys, time, datetime
from getTable import *
class Ui_MainWindow(QtWidgets.QWidget):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(482, 788)
        MainWindow.setMinimumSize(QtCore.QSize(400, 788))
        MainWindow.setAnimated(True)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.dateEdit = QtWidgets.QDateEdit(self.centralwidget)
        self.dateEdit.setGeometry(QtCore.QRect(150, 730, 110, 22))
        self.dateEdit.setDateTime(QtCore.QDateTime(QtCore.QDate(time.gmtime().tm_year, time.gmtime().tm_mon, time.gmtime().tm_mday), QtCore.QTime(0, 0, 0)))
        self.dateEdit.setObjectName("dateEdit")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(280, 730, 75, 23))
        self.pushButton.setObjectName("pushButton")
        self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
        self.tableWidget.setGeometry(QtCore.QRect(0, 0, 491, 711))
        self.tableWidget.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.tableWidget.setLineWidth(1)
        self.tableWidget.setAutoScroll(False)
        self.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.tableWidget.setDragEnabled(False)
        self.tableWidget.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection)
        self.tableWidget.setRowCount(7)
        self.tableWidget.setColumnCount(4)
        self.tableWidget.setObjectName("tableWidget")
        item = QtWidgets.QTableWidgetItem()
        brush = QtGui.QBrush(QtGui.QColor(255, 85, 0))
        brush.setStyle(QtCore.Qt.Dense2Pattern)
        item.setBackground(brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.NoBrush)
        item.setForeground(brush)
        self.tableWidget.setItem(0, 0, item)
        item = QtWidgets.QTableWidgetItem()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
        brush.setStyle(QtCore.Qt.Dense2Pattern)
        item.setBackground(brush)
        self.tableWidget.setItem(0, 1, item)
        item = QtWidgets.QTableWidgetItem()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
        brush.setStyle(QtCore.Qt.Dense2Pattern)
        item.setBackground(brush)
        self.tableWidget.setItem(0, 2, item)
        item = QtWidgets.QTableWidgetItem()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
        brush.setStyle(QtCore.Qt.Dense2Pattern)
        item.setBackground(brush)
        self.tableWidget.setItem(0, 3, item)
        item = QtWidgets.QTableWidgetItem()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
        brush.setStyle(QtCore.Qt.Dense2Pattern)
        item.setBackground(brush)
        self.tableWidget.setItem(1, 0, item)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget.setItem(1, 1, item)
        item = QtWidgets.QTableWidgetItem()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
        brush.setStyle(QtCore.Qt.Dense2Pattern)
        item.setBackground(brush)
        self.tableWidget.setItem(2, 0, item)
        item = QtWidgets.QTableWidgetItem()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
        brush.setStyle(QtCore.Qt.Dense2Pattern)
        item.setBackground(brush)
        self.tableWidget.setItem(3, 0, item)
        item = QtWidgets.QTableWidgetItem()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
        brush.setStyle(QtCore.Qt.Dense2Pattern)
        item.setBackground(brush)
        self.tableWidget.setItem(4, 0, item)
        item = QtWidgets.QTableWidgetItem()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
        brush.setStyle(QtCore.Qt.Dense2Pattern)
        item.setBackground(brush)
        self.tableWidget.setItem(5, 0, item)
        item = QtWidgets.QTableWidgetItem()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
        brush.setStyle(QtCore.Qt.Dense2Pattern)
        item.setBackground(brush)
        self.tableWidget.setItem(6, 0, item)
        self.tableWidget.horizontalHeader().setVisible(False)
        self.tableWidget.horizontalHeader().setDefaultSectionSize(120)
        self.tableWidget.horizontalHeader().setMinimumSectionSize(25)
        self.tableWidget.verticalHeader().setVisible(False)
        self.tableWidget.verticalHeader().setDefaultSectionSize(100)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 482, 22))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.pushButton.clicked.connect(self.timeChange)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "翘课小王子"))
        self.pushButton.setText(_translate("MainWindow", "PushButton"))
        __sortingEnabled = self.tableWidget.isSortingEnabled()
        self.tableWidget.setSortingEnabled(False)
        self.tableWidget.setSortingEnabled(__sortingEnabled)
    def timeChange(self):
        for i in range(1,4):
            for j in range(1,7):
                self.tableWidget.setItem(j, i, QtWidgets.QTableWidgetItem())
                self.tableWidget.item(j, i).setText("")
        t = tableFun()
        print(t.login())
        if (t.login() == True):
            msg1 = QtWidgets.QMessageBox().information(self, '提示', '登录成功！')
        else:
            msg1 = QtWidgets.QMessageBox().information(self, '提示', '登录失败！')
        date = self.dateEdit.dateTime().date().toPyDate()
        t.getData(date)
        Table = t.readTable()
        print(Table)
        print(date)
        i = 0
        for line in Table:
            self.tableWidget.item(i, 0).setText(line[0])
            i += 1

        tm = time.strptime(str(date), '%Y-%m-%d')
        deviation = tm.tm_wday
        print(deviation)
        if(deviation == 0):
            date1 = str((datetime.date.fromisoformat(str(date)) + datetime.timedelta(-1)).strftime("%Y-%m-%d"))
            t.getData(date1, 'Table1.txt')
            table1 = t.readTable('Table1.txt')
        elif(deviation == 6):
            date1 = str((datetime.date.fromisoformat(str(date)) + datetime.timedelta(1)).strftime("%Y-%m-%d"))
            t.getData(date1, 'Table1.txt')
            table1 = t.readTable('Table1.txt')
        rq = list(map(lambda x: (x + deviation) % 8, range(0, 3)))


        i = 0
        n = 0

        for line in Table:
            print(line)
            j = 1
            for item in rq:
                if(item == 0):
                    if(table1[n]):
                        text = table1[n][1+abs(deviation-6)]
                    else:
                        text = ''
                else:
                    text = line[item]
                if(text != None):

                    if(type(text) == type({1:'1'})):
                        s=text['课程名称']+'\n'+text['上课时间']+'\n'+text['上课地点']
                        self.tableWidget.item(i, j).setText(s)
                    else:
                        self.tableWidget.item(i, j).setText(text)
                j += 1
            i += 1
            n += 1

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    mainwindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(mainwindow)
    mainwindow.show()
    sys.exit(app.exec_())