# -*- coding: utf-8 -*-
import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMessageBox


class Ui_MainWindow(object):
    def setupUi(self, main_window):
        main_window.setObjectName("MainWindow")
        main_window.resize(564, 204)
        main_window.setMinimumSize(QtCore.QSize(564, 204))
        main_window.setMaximumSize(QtCore.QSize(564, 204))
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(8)
        font.setBold(True)
        font.setWeight(75)
        main_window.setFont(font)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("blackboard_qjj_icon.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        main_window.setWindowIcon(icon)
        main_window.setStyleSheet("background-color: rgb(61, 137, 188);\n"
                                  "")
        main_window.setIconSize(QtCore.QSize(32, 32))
        self.centralwidget = QtWidgets.QWidget(main_window)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.gridLayout_2 = QtWidgets.QGridLayout()
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.equal_to_label2 = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.equal_to_label2.setFont(font)
        self.equal_to_label2.setObjectName("equal_to_label2")
        self.gridLayout_2.addWidget(self.equal_to_label2, 1, 5, 1, 1)
        self.solution_label = QtWidgets.QLabel(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.solution_label.sizePolicy().hasHeightForWidth())
        self.solution_label.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(16)
        font.setBold(True)
        font.setWeight(75)
        self.solution_label.setFont(font)
        self.solution_label.setStyleSheet("background-color: rgb(0, 0, 0);\n"
                                          "color: rgb(255, 255, 255);")
        self.solution_label.setAlignment(QtCore.Qt.AlignCenter)
        self.solution_label.setObjectName("solution_label")
        self.gridLayout_2.addWidget(self.solution_label, 2, 0, 1, 1)
        self.gridLayout_3 = QtWidgets.QGridLayout()
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.y_output_label = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.y_output_label.setFont(font)
        self.y_output_label.setStyleSheet("background-color: rgb(0, 0, 0);\n"
                                          "color: rgb(255, 255, 255);")
        self.y_output_label.setAlignment(QtCore.Qt.AlignCenter)
        self.y_output_label.setObjectName("y_output_label")
        self.gridLayout_3.addWidget(self.y_output_label, 1, 1, 1, 1)
        self.x_output_label = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.x_output_label.setFont(font)
        self.x_output_label.setStyleSheet("color: rgb(255, 255, 255);\n"
                                          "background-color: rgb(0, 0, 0);")
        self.x_output_label.setAlignment(QtCore.Qt.AlignCenter)
        self.x_output_label.setObjectName("x_output_label")
        self.gridLayout_3.addWidget(self.x_output_label, 0, 1, 1, 1)
        self.solution_x_label = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.solution_x_label.setFont(font)
        self.solution_x_label.setStyleSheet("color: rgb(255, 255, 255);\n"
                                            "background-color: rgb(0, 0, 0);")
        self.solution_x_label.setAlignment(QtCore.Qt.AlignCenter)
        self.solution_x_label.setObjectName("solution_x_label")
        self.gridLayout_3.addWidget(self.solution_x_label, 0, 0, 1, 1)
        self.solution_y_label = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.solution_y_label.setFont(font)
        self.solution_y_label.setStyleSheet("color: rgb(255, 255, 255);\n"
                                            "background-color: rgb(0, 0, 0);")
        self.solution_y_label.setAlignment(QtCore.Qt.AlignCenter)
        self.solution_y_label.setObjectName("solution_y_label")
        self.gridLayout_3.addWidget(self.solution_y_label, 1, 0, 1, 1)
        self.gridLayout_2.addLayout(self.gridLayout_3, 2, 1, 1, 5)
        self.a_textBox = QtWidgets.QLineEdit(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.a_textBox.sizePolicy().hasHeightForWidth())
        self.a_textBox.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        self.a_textBox.setFont(font)
        self.a_textBox.setStyleSheet("color: rgb(255, 255, 255);\n"
                                     "background-color: rgb(0, 0, 0);")
        self.a_textBox.setObjectName("a_textBox")
        self.gridLayout_2.addWidget(self.a_textBox, 0, 0, 1, 1)
        self.plus_label2 = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.plus_label2.setFont(font)
        self.plus_label2.setObjectName("plus_label2")
        self.gridLayout_2.addWidget(self.plus_label2, 1, 2, 1, 1)
        self.plus_label1 = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.plus_label1.setFont(font)
        self.plus_label1.setObjectName("plus_label1")
        self.gridLayout_2.addWidget(self.plus_label1, 0, 2, 1, 1)
        self.y_label1 = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.y_label1.setFont(font)
        self.y_label1.setObjectName("y_label1")
        self.gridLayout_2.addWidget(self.y_label1, 0, 4, 1, 1)
        self.x_label2 = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.x_label2.setFont(font)
        self.x_label2.setObjectName("x_label2")
        self.gridLayout_2.addWidget(self.x_label2, 1, 1, 1, 1)
        self.x_label1 = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.x_label1.setFont(font)
        self.x_label1.setObjectName("x_label1")
        self.gridLayout_2.addWidget(self.x_label1, 0, 1, 1, 1)
        self.y_label2 = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.y_label2.setFont(font)
        self.y_label2.setObjectName("y_label2")
        self.gridLayout_2.addWidget(self.y_label2, 1, 4, 1, 1)
        self.equal_to_label1 = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.equal_to_label1.setFont(font)
        self.equal_to_label1.setObjectName("equal_to_label1")
        self.gridLayout_2.addWidget(self.equal_to_label1, 0, 5, 1, 1)
        self.b_textBox = QtWidgets.QLineEdit(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.b_textBox.sizePolicy().hasHeightForWidth())
        self.b_textBox.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        self.b_textBox.setFont(font)
        self.b_textBox.setStyleSheet("color: rgb(255, 255, 255);\n"
                                     "background-color: rgb(0, 0, 0);")
        self.b_textBox.setObjectName("b_textBox")
        self.gridLayout_2.addWidget(self.b_textBox, 0, 3, 1, 1)
        self.c_textBox = QtWidgets.QLineEdit(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.c_textBox.sizePolicy().hasHeightForWidth())
        self.c_textBox.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        self.c_textBox.setFont(font)
        self.c_textBox.setStyleSheet("color: rgb(255, 255, 255);\n"
                                     "background-color: rgb(0, 0, 0);")
        self.c_textBox.setObjectName("c_textBox")
        self.gridLayout_2.addWidget(self.c_textBox, 0, 6, 1, 1)
        self.d_textBox = QtWidgets.QLineEdit(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.d_textBox.sizePolicy().hasHeightForWidth())
        self.d_textBox.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        self.d_textBox.setFont(font)
        self.d_textBox.setStyleSheet("color: rgb(255, 255, 255);\n"
                                     "background-color: rgb(0, 0, 0);")
        self.d_textBox.setObjectName("d_textBox")
        self.gridLayout_2.addWidget(self.d_textBox, 1, 0, 1, 1)
        self.e_textBox = QtWidgets.QLineEdit(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.e_textBox.sizePolicy().hasHeightForWidth())
        self.e_textBox.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        self.e_textBox.setFont(font)
        self.e_textBox.setStyleSheet("color: rgb(255, 255, 255);\n"
                                     "background-color: rgb(0, 0, 0);")
        self.e_textBox.setObjectName("e_textBox")
        self.gridLayout_2.addWidget(self.e_textBox, 1, 3, 1, 1)
        self.f_textBox = QtWidgets.QLineEdit(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.f_textBox.sizePolicy().hasHeightForWidth())
        self.f_textBox.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(20)
        self.f_textBox.setFont(font)
        self.f_textBox.setStyleSheet("color: rgb(255, 255, 255);\n"
                                     "background-color: rgb(0, 0, 0);")
        self.f_textBox.setObjectName("f_textBox")
        self.gridLayout_2.addWidget(self.f_textBox, 1, 6, 1, 1)
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.solve_btn = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.solve_btn.sizePolicy().hasHeightForWidth())
        self.solve_btn.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.solve_btn.setFont(font)
        self.solve_btn.setStyleSheet("border-color: rgb(162, 177, 24);\n"
                                     "color: rgb(255, 255, 255);\n"
                                     "background-color: rgb(65, 163, 97);")
        self.solve_btn.setObjectName("solve_btn")
        self.gridLayout.addWidget(self.solve_btn, 0, 0, 1, 1)
        self.clear_btn = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.clear_btn.sizePolicy().hasHeightForWidth())
        self.clear_btn.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Comic Sans MS")
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.clear_btn.setFont(font)
        self.clear_btn.setStyleSheet("border-color: rgb(162, 177, 24);\n"
                                     "color: rgb(176, 0, 0);\n"
                                     "background-color: rgb(255, 152, 174);")
        self.clear_btn.setObjectName("clear_btn")
        self.gridLayout.addWidget(self.clear_btn, 1, 0, 1, 1)
        self.gridLayout_2.addLayout(self.gridLayout, 2, 6, 1, 1)
        self.verticalLayout.addLayout(self.gridLayout_2)
        main_window.setCentralWidget(self.centralwidget)

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

        self.solve_btn.clicked.connect(self.solve_equation)

        self.clear_btn.clicked.connect(self.clear_text_boxes)

    def solve_equation(self):
        a, b, c = self.a_textBox.text(), self.b_textBox.text(), self.c_textBox.text()
        d, e, f = self.d_textBox.text(), self.e_textBox.text(), self.f_textBox.text()

        conditions1 = [a == '',
                       b == '',
                       c == '',
                       d == '',
                       e == '',
                       f == '',
                       ]

        # conditions2 = [not a[1:].isdigit(),
        #                not b[1:].isdigit(),
        #                not c[1:].isdigit(),
        #                not d[1:].isdigit(),
        #                not e[1:].isdigit(),
        #                not f[1:].isdigit()
        #                ]

        if any(conditions1):
            self.show_msgBox('Fill all text boxes please or check if input is a digit!')
        # elif any(conditions2):
        #     self.show_msgBox('Inputs should be digits only(e.g -1, 14)!')
        else:
            A = [[int(a), int(b)], [int(d), int(e)]]
            B = [int(c), int(f)]

            solutions = np.linalg.solve(A, B)

            self.x_output_label.setText(str(solutions[0]))
            self.y_output_label.setText(str(solutions[1]))

    @staticmethod
    def show_msgBox(message):
        msg = QMessageBox()
        msg.setWindowTitle('Wrong Inputs')
        msg.setText("WARNING: " + message)
        msg.setIcon(QMessageBox.Question)

        msg.exec_()

    def clear_text_boxes(self):
        self.a_textBox.setText('')
        self.b_textBox.setText('')
        self.c_textBox.setText('')
        self.d_textBox.setText('')
        self.e_textBox.setText('')
        self.f_textBox.setText('')
        self.x_output_label.setText('0')
        self.y_output_label.setText('0')

    def retranslateUi(self, main_window):
        _translate = QtCore.QCoreApplication.translate
        main_window.setWindowTitle(_translate("MainWindow", "Simultaneous Equation Solver"))
        self.equal_to_label2.setText(_translate("MainWindow", "="))
        self.solution_label.setText(_translate("MainWindow", "SOLUTIONS"))
        self.y_output_label.setText(_translate("MainWindow", "0"))
        self.x_output_label.setText(_translate("MainWindow", "0"))
        self.solution_x_label.setText(_translate("MainWindow", "X:"))
        self.solution_y_label.setText(_translate("MainWindow", "Y:"))
        self.plus_label2.setText(_translate("MainWindow", "+"))
        self.plus_label1.setText(_translate("MainWindow", "+"))
        self.y_label1.setText(_translate("MainWindow", "Y"))
        self.x_label2.setText(_translate("MainWindow", "X"))
        self.x_label1.setText(_translate("MainWindow", "X"))
        self.y_label2.setText(_translate("MainWindow", "Y"))
        self.equal_to_label1.setText(_translate("MainWindow", "="))
        self.solve_btn.setText(_translate("MainWindow", "SOLVE!"))
        self.clear_btn.setText(_translate("MainWindow", "CLEAR ALL!"))


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