from PyQt5 import QtCore, QtGui, QtWidgets
import dbCommands as DB

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(219, 330)
        MainWindow.setStyleSheet("background-color: #5cdb95;")
        MainWindow.setDocumentMode(False)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.Counterlabel = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Tahoma")
        font.setPointSize(45)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.Counterlabel.setFont(font)
        self.Counterlabel.setStyleSheet("color: #05386B;")
        self.Counterlabel.setAlignment(QtCore.Qt.AlignCenter)
        self.Counterlabel.setObjectName("Counterlabel")
        self.verticalLayout.addWidget(self.Counterlabel)
        self.label = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setFamily("Tahoma")
        font.setPointSize(60)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.label.setFont(font)
        self.label.setStyleSheet("color: #05386B;")
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget, clicked=lambda: self.plusB())
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(51)
        font.setBold(True)
        font.setWeight(75)
        self.pushButton_2.setFont(font)
        self.pushButton_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton_2.setAutoFillBackground(False)
        self.pushButton_2.setStyleSheet("background-color: #05386B;\n"
"color: #edf5e1;")
        self.pushButton_2.setCheckable(False)
        self.pushButton_2.setAutoDefault(False)
        self.pushButton_2.setObjectName("pushButton_2")
        self.verticalLayout.addWidget(self.pushButton_2)
        self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget, clicked=lambda: self.minusB())
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(51)
        font.setBold(True)
        font.setWeight(75)
        font.setKerning(True)
        self.pushButton_3.setFont(font)
        self.pushButton_3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton_3.setAutoFillBackground(False)
        self.pushButton_3.setStyleSheet("background-color: #05386B;\n"
"color: #edf5e1;")
        self.pushButton_3.setCheckable(False)
        self.pushButton_3.setAutoDefault(False)
        self.pushButton_3.setObjectName("pushButton_3")
        self.verticalLayout.addWidget(self.pushButton_3)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menuBar = QtWidgets.QMenuBar(MainWindow)
        self.menuBar.setGeometry(QtCore.QRect(0, 0, 219, 24))
        self.menuBar.setObjectName("menuBar")
        self.menuReset = QtWidgets.QMenu(self.menuBar)
        self.menuReset.setObjectName("menuReset")
        MainWindow.setMenuBar(self.menuBar)
        self.actionReset = QtWidgets.QAction(MainWindow)
        self.actionReset.setObjectName("actionReset")
        self.actionCancel = QtWidgets.QAction(MainWindow)
        self.actionCancel.setObjectName("actionCancel")
        self.menuReset.addAction(self.actionReset)
        self.menuReset.addAction(self.actionCancel)
        self.menuBar.addAction(self.menuReset.menuAction())
        self.actionReset.triggered.connect(lambda: self.reset())
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        MainWindow.setTabOrder(self.pushButton_2, self.pushButton_3)
        self.VIEW()

    def VIEW(self):
        number = DB.VIEW()[0][0]
        self.label.setText(str(number))

    def plusB(self):
        DB.UPDATEplus()
        self.VIEW()

    def minusB(self):
        DB.UPDATEminus()
        self.VIEW()

    def reset(self):
        DB.DELETE_ALL()
        DB.connect()
        self.VIEW()

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Counter"))
        self.Counterlabel.setText(_translate("MainWindow", "Counter"))
        self.label.setText(_translate("MainWindow", "0"))
        self.pushButton_2.setText(_translate("MainWindow", "+"))
        self.pushButton_3.setText(_translate("MainWindow", "-"))
        self.menuReset.setTitle(_translate("MainWindow", "Reset"))
        self.actionReset.setText(_translate("MainWindow", "Reset"))
        self.actionReset.setToolTip(_translate("MainWindow", "Set to 0"))
        self.actionReset.setShortcut(_translate("MainWindow", "Meta+Backspace"))
        self.actionCancel.setText(_translate("MainWindow", "Cancel"))


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