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

# Form implementation generated from reading ui file 'MWindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# 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 HtmlFunction import htmlf
from WebcamWidget import WebcamWidget
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QPixmap, QColor


class Ui_Main(object):
    setsCount = None
    jumpingJacksCount = None
    squatsCount = None
    weightCurlsCount = None

    setsValue = 1
    jumpingJacksValue = 0
    squatsValue = 0
    weightCurlsValue = 0

    def setParams(self, setsCount, jumpingJacksCount, squatsCount, weightCurlsCount):
        self.setsCount = setsCount
        self.jumpingJacksCount = jumpingJacksCount
        self.squatsCount = squatsCount
        self.weightCurlsCount = weightCurlsCount

    def setValues(self, setsCount, jumpingJacksCount, squatsCount, weightCurlsCount):
        self.setsValue = setsCount
        self.jumpingJacksValue = jumpingJacksCount
        self.squatsValue = squatsCount
        self.weightCurlsValue = weightCurlsCount
        self.reTranslateUi()

    def setupUi(self, MainWindow):
        self.MainWindow = MainWindow
        self.MainWindow.setObjectName("MainWindow")
        self.MainWindow.setFixedSize(1779, 984)

        self.centralwidget = QtWidgets.QWidget(self.MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(80, 30, 311, 821))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")

        self.workoutLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.workoutLayout.setContentsMargins(0, 0, 0, 0)
        self.workoutLayout.setObjectName("workoutLayout")

        self.jumpingJacksLabel = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.jumpingJacksLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.jumpingJacksLabel.setObjectName("jumpingJacksLabel")

        self.workoutLayout.addWidget(self.jumpingJacksLabel)

        self.squatsLabel = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.squatsLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.squatsLabel.setObjectName("squatsLabel")
        self.workoutLayout.addWidget(self.squatsLabel)

        self.weightCurlsLabel = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.weightCurlsLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.weightCurlsLabel.setObjectName("weightCurlsLabel")
        self.workoutLayout.addWidget(self.weightCurlsLabel)

        self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(420, 30, 1281, 80))
        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")

        self.setsLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
        self.setsLayout.setContentsMargins(0, 0, 0, 0)
        self.setsLayout.setObjectName("setsLayout")

        self.setsLabel = QtWidgets.QLabel(self.horizontalLayoutWidget)
        self.setsLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.setsLabel.setObjectName("setsLabel")
        self.setsLayout.addWidget(self.setsLabel)

        self.workoutFrame = QtWidgets.QFrame(self.centralwidget)
        self.workoutFrame.setGeometry(QtCore.QRect(79, 29, 311, 821))
        self.workoutFrame.setFrameShape(QtWidgets.QFrame.Panel)
        self.workoutFrame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.workoutFrame.setObjectName("workoutFrame")

        self.setsFrame = QtWidgets.QFrame(self.centralwidget)
        self.setsFrame.setGeometry(QtCore.QRect(419, 29, 1281, 81))
        self.setsFrame.setFrameShape(QtWidgets.QFrame.Panel)
        self.setsFrame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.setsFrame.setObjectName("setsFrame")

        self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
        self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(420, 869, 1281, 61))
        self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")

        self.startStopLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2)
        self.startStopLayout.setContentsMargins(0, 0, 0, 0)
        self.startStopLayout.setObjectName("startStopLayout")

        self.startBtn = QtWidgets.QPushButton(self.horizontalLayoutWidget_2)
        self.startBtn.setObjectName("startBtn")
        self.startStopLayout.addWidget(self.startBtn)

        self.stopBtn = QtWidgets.QPushButton(self.horizontalLayoutWidget_2)
        self.stopBtn.setObjectName("stopBtn")
        self.stopBtn.setEnabled(False)
        self.startStopLayout.addWidget(self.stopBtn)

        self.horizontalLayoutWidget_3 = QtWidgets.QWidget(self.centralwidget)
        self.horizontalLayoutWidget_3.setGeometry(QtCore.QRect(420, 130, 1280, 720))
        self.horizontalLayoutWidget_3.setObjectName("horizontalLayoutWidget_3")

        self.webcamLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_3)
        self.webcamLayout.setContentsMargins(0, 0, 0, 0)
        self.webcamLayout.setObjectName("webcamLayout")

        self.webcamWidget = WebcamWidget()

        self.webcamWidgetPlaceholder = QtWidgets.QLabel()
        self.webcamWidgetPlaceholderPixmap = QPixmap(1280, 720)
        self.webcamWidgetPlaceholderPixmap.fill(QColor("black"))
        self.webcamWidgetPlaceholder.setPixmap(self.webcamWidgetPlaceholderPixmap)

        self.webcamLayout.addWidget(self.webcamWidgetPlaceholder)
        self.webcamLayout.addWidget(self.webcamWidget)

        self.webcamWidget.hide()

        self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(73, 850, 311, 100))
        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")

        self.themeLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
        self.themeLayout.setContentsMargins(0, 0, 0, 0)
        self.themeLayout.setObjectName("horizontalLayout")
        
        self.lightRBtn = QtWidgets.QRadioButton(self.horizontalLayoutWidget)
        self.lightRBtn.setLayoutDirection(QtCore.Qt.RightToLeft)
        self.lightRBtn.setObjectName("lightRBtn")
        self.themeLayout.addWidget(self.lightRBtn)

        self.themeLabel = QtWidgets.QLabel(self.horizontalLayoutWidget)
        self.themeLabel.setText("")
        self.themeLabel.setObjectName("themeLabel")
        self.themeLayout.addWidget(self.themeLabel)

        self.darkRBtn = QtWidgets.QRadioButton(self.horizontalLayoutWidget)
        self.darkRBtn.setObjectName("darkRBtn")
        self.themeLayout.addWidget(self.darkRBtn)

        self.MainWindow.setCentralWidget(self.centralwidget)

        self.theme = "styles/styleLight.qss"

        self.menubar = QtWidgets.QMenuBar(self.MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1779, 22))
        self.menubar.setObjectName("menubar")
        self.MainWindow.setMenuBar(self.menubar)

        self.statusbar = QtWidgets.QStatusBar(self.MainWindow)
        self.statusbar.setObjectName("statusbar")
        
        self.MainWindow.setStatusBar(self.statusbar)

        # This section is devoted to button connections
        self.startBtn.clicked.connect(self.startBtnAction)
        self.stopBtn.clicked.connect(self.stopBtnAction)
        self.lightRBtn.clicked.connect(self.lightBtnAction)
        self.darkRBtn.clicked.connect(self.darkBtnAction)

        self.cancelBtn = QtWidgets.QPushButton(self.horizontalLayoutWidget_2)
        self.cancelBtn.setObjectName("cancelBtn")
        self.startStopLayout.addWidget(self.cancelBtn)

        self.cancelBtn.clicked.connect(self.cancelBtnAction)

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

    def setToTimer(self):
        _translate = QtCore.QCoreApplication.translate
        self.setsLabel.setText(_translate("MainWindow", htmlf([("Take a rest!", 4)])))

    def offTheProgram(self):
        _translate = QtCore.QCoreApplication.translate
        self.setsLabel.setText(_translate("MainWindow", htmlf([("You finished your workout!", 4)])))

    def reTranslateUi(self):
        _translate = QtCore.QCoreApplication.translate
        self.MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.jumpingJacksLabel.setText(_translate("MainWindow", htmlf([("Jumping Jacks:\n\n", 2), (f"{self.jumpingJacksValue}/{self.jumpingJacksCount}", 3)])))
        self.squatsLabel.setText(_translate("MainWindow", htmlf([("Squats:\n\n", 2), (f"{self.squatsValue}/{self.squatsCount}", 3)])))
        self.weightCurlsLabel.setText(_translate("MainWindow", htmlf([("Weight Curls:\n\n", 2), (f"{self.weightCurlsValue}/{self.weightCurlsCount}", 3)])))
        self.setsLabel.setText(_translate("MainWindow", htmlf([("Sets: ", 2), (f"{self.setsValue}/{self.setsCount}", 3)])))
        self.startBtn.setText(_translate("MainWindow", "Start Video"))
        self.stopBtn.setText(_translate("MainWindow", "Stop Video"))
        self.lightRBtn.setText(_translate("MainWindow", "Light Mode"))
        self.darkRBtn.setText(_translate("MainWindow", "Dark Mode"))
        self.cancelBtn.setText(_translate("MainWindow", "Cancel"))

    def cancelBtnAction(self):
        self.MainWindow.hide()

    # Button
    def startBtnAction(self) -> None:
        self.webcamWidgetPlaceholder.hide()
        self.webcamWidget.show()
        self.startBtn.setEnabled(False)
        self.stopBtn.setEnabled(True)

    def stopBtnAction(self) -> None:
        self.webcamWidget.hide()
        self.webcamWidgetPlaceholder.show()
        self.stopBtn.setEnabled(False)
        self.startBtn.setEnabled(True)

    def lightBtnAction(self) -> None:
        self.theme = "styles/styleLight.qss"
        with open(self.theme, "r") as theme:
            styleSheet = "\n".join(theme.readlines())
        self.MainWindow.setStyleSheet(styleSheet)

    def darkBtnAction(self) -> None:
        self.theme = "styles/styleDark.qss"
        with open(self.theme, "r") as theme:
            styleSheet = "\n".join(theme.readlines())
        self.MainWindow.setStyleSheet(styleSheet)

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_Main()
    ui.setupUi(MainWindow)
    with open(ui.theme, "r") as styleFile:
        stylesheet = "\n".join(styleFile.readlines())
    app.setStyleSheet(stylesheet)
    MainWindow.show()
    sys.exit(app.exec_())
