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

# Form implementation generated from reading ui file 'GUI.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 PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel
from PyQt5.QtWidgets import QGridLayout, QWidget, QDesktopWidget, QGraphicsView
from datetime import datetime
import pygame
import alarmpopup
import selecttime
import random

changereason = 600

### reason1-50 are the random strings that appear in the center of the alarm clock. I used these for things that make my girlfriend special.
### You can use as many or as little as you want. Just change the range here at lines 81 and 249.

reason1 = ''
reason2 = ''
reason3 = ''
reason4 = ''
reason5 = ''
reason6 = ''
reason8 = ''
reason9 = ''
reason10 = ''
reason11 = ''
reason12 = ''
reason13 = ''
reason14 = ''
reason15 = ''
reason16 = ''
reason17 = ''
reason18 = ''
reason19 = ''
reason20 = ''
reason21 = ''
reason22 = ''
reason23 = ''
reason24 = ''
reason25 = ''
reason26 = ''
reason27 = ''
reason28 = ''
reason29 = ''
reason30 = ''
reason31 = ''
reason32 = ''
reason33 = ''
reason34 = ''
reason35 = ''
reason36 = ''
reason37 = ''
reason38 = ''
reason39 = ''
reason40 = ''
reason41 = ''
reason42 = ''
reason43 = ''
reason44 = ''
reason45 = ''
reason46 = ''
reason47 = ''
reason48 = ''
reason49 = ''
reason50 = ''
reason51 = ''
listofreasons = [reason1, reason2, reason3, reason4, reason5, reason6, reason8, reason9, reason10,
                 reason11, reason12, reason13, reason14, reason15, reason16, reason17, reason18, reason19, reason20,
                 reason21, reason22, reason23, reason24, reason25, reason26, reason27, reason28, reason29, reason30,
                 reason31, reason32, reason33, reason34, reason35, reason36, reason37, reason38, reason39, reason40,
                 reason41, reason42, reason43, reason44, reason45, reason46, reason47, reason48, reason49, reason50,
                 reason51]

reason = listofreasons[random.randint(0, 49)]

class Ui_MainWindow(object):
    def openSelectTime(self):
        self.window = QtWidgets.QMainWindow()
        self.ui = selecttime.Ui_Form()
        self.ui.setupUi(self.window)
        self.window.setCursor(QtCore.Qt.BlankCursor)
        self.window.showFullScreen()

    def openWindow(self):
        self.window = QtWidgets.QMainWindow()
        self.ui = alarmpopup.Ui_AlarmMessageBox()
        self.ui.setupUi(self.window)
        self.window.setCursor(QtCore.Qt.BlankCursor)
        self.window.show()

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1024, 600)
        MainWindow.setFocusPolicy(QtCore.Qt.StrongFocus)
        #flags = QtCore.Qt.WindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
        #MainWindow.setWindowFlags(flags)
        self.label = QtWidgets.QLabel(MainWindow)
        self.label.setGeometry(QtCore.QRect(0, 0, 1024, 600))
        self.label.setText("")
        self.label.setPixmap(QtGui.QPixmap("/home/pi/Desktop/Alarm/timeselectorbg.png"))
        self.label.setObjectName("label")
        self.Time = QtWidgets.QLabel(MainWindow)
        self.Time.setGeometry(QtCore.QRect(20, 460, 620, 131))
        font = QtGui.QFont()
        font.setFamily("Arial Black")
        font.setPointSize(80)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.Time.setFont(font)
        self.Time.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
        self.Time.setObjectName("Time")
        self.Reasons = QtWidgets.QLabel(MainWindow)
        self.Reasons.setGeometry(QtCore.QRect(150, 225, 721, 231))
        font = QtGui.QFont()
        font.setFamily("Helvetica")
        self.Reasons.setFont(font)
        self.Reasons.setAlignment(QtCore.Qt.AlignJustify | QtCore.Qt.AlignTop)
        self.Reasons.setWordWrap(True)
        self.Reasons.setObjectName("Reasons")
        self.verticalLayoutWidget = QtWidgets.QWidget(MainWindow)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(867, 50, 151, 231))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.firstAlarmLbl = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.firstAlarmLbl.setMinimumSize(QtCore.QSize(60, 0))
        self.firstAlarmLbl.setMaximumSize(QtCore.QSize(16777215, 111))
        self.firstAlarmLbl.setObjectName("firstAlarmLbl")
        self.verticalLayout.addWidget(self.firstAlarmLbl)
        self.secondAlarmLbl = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.secondAlarmLbl.setObjectName("secondAlarmLbl")
        self.verticalLayout.addWidget(self.secondAlarmLbl)
        self.thirdAlarmLbl = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.thirdAlarmLbl.setObjectName("thirdAlarmLbl")
        self.verticalLayout.addWidget(self.thirdAlarmLbl)
        self.fourthAlarmLbl = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.fourthAlarmLbl.setObjectName("fourthAlarmLbl")
        self.verticalLayout.addWidget(self.fourthAlarmLbl)
        self.fifthAlarmLbl = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.fifthAlarmLbl.setObjectName("fifthAlarmLbl")
        self.verticalLayout.addWidget(self.fifthAlarmLbl)
        self.SetAlarmBtn = QtWidgets.QPushButton(MainWindow)
        self.SetAlarmBtn.setGeometry(QtCore.QRect(865, 10, 150, 40))
        font = QtGui.QFont()
        font.setFamily("Helvetica")
        font.setPointSize(16)
        self.SetAlarmBtn.setFont(font)
        self.SetAlarmBtn.setObjectName("SetAlarmBtn")

        self.SetAlarmBtn.clicked.connect(self.openSelectTime)
        
        self.EndAlarmBtn = QtWidgets.QPushButton(MainWindow)
        self.EndAlarmBtn.setGeometry(QtCore.QRect(865, 555, 150, 40))
        font = QtGui.QFont()
        font.setFamily("Helvetica")
        font.setPointSize(16)
        self.EndAlarmBtn.setFont(font)
        self.EndAlarmBtn.setObjectName("EndAlarmBtn")

        self.EndAlarmBtn.clicked.connect(self.end_music)

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

        pygame.init()
        pygame.mixer.init()
        pygame.mixer.music.load('/home/pi/Desktop/Alarm/BrandName.mp3')

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


    def retranslateUi(self, MainWindow):
        now = datetime.now()
        #print(now)
        current_time = now.strftime('%-I:%M %p')
        #print(current_time)
        alarm_time = now.strftime('%-I:%M:%S %p')
        #print(alarm_time)

        self.setReason()
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.Time.setText(_translate("MainWindow","<html><head/><body><p><span style=\" color:#d5d5d5;\">" + current_time + "</span></p></body></html>"))
        self.Reasons.setText(_translate("MainWindow","<html><head/><body><p align=\"center\"><span style=\" font-size:45pt; font-style:italic; color:#d5d5d5;\">" + reason + "</span></p></body></html>"))
        self.firstAlarmLbl.setText(_translate("MainWindow","<html><head/><body><p align=\"center\"><span style=\" font-size:24pt; color:#d5d5d5;\">" + selecttime.time1 + "</span></p></body></html>"))
        self.secondAlarmLbl.setText(_translate("MainWindow","<html><head/><body><p align=\"center\"><span style=\" font-size:24pt; color:#d5d5d5;\">" + selecttime.time2 + "</span></p></body></html>"))
        self.thirdAlarmLbl.setText(_translate("MainWindow","<html><head/><body><p align=\"center\"><span style=\" font-size:24pt; color:#d5d5d5;\">" + selecttime.time3 + "</span></p></body></html>"))
        self.fourthAlarmLbl.setText(_translate("MainWindow","<html><head/><body><p align=\"center\"><span style=\" font-size:24pt; color:#d5d5d5;\">" + selecttime.time4 + "</span></p></body></html>"))
        self.fifthAlarmLbl.setText(_translate("MainWindow","<html><head/><body><p align=\"center\"><span style=\" font-size:24pt; color:#d5d5d5;\">" + selecttime.time5 + "</span></p></body></html>"))
        self.SetAlarmBtn.setText(_translate("MainWindow", "Set New Alarm"))
        self.EndAlarmBtn.setText(_translate("MainWindow", "End Alarm"))


        if selecttime.alarmtime1 == alarm_time:
            selecttime.alarmtime1 = ''
            selecttime.time1 = ''
            pygame.mixer.music.play()
            self.openWindow()
        elif selecttime.alarmtime2 == alarm_time:
            selecttime.alarmtime2 = ''
            selecttime.time2 = ''
            pygame.mixer.music.play()
            self.openWindow()
        elif selecttime.alarmtime3 == alarm_time:
            selecttime.alarmtime3 = ''
            selecttime.time3 = ''
            pygame.mixer.music.play()
            self.openWindow()
        elif selecttime.alarmtime4 == alarm_time:
            selecttime.alarmtime4 = ''
            selecttime.time4 = ''
            pygame.mixer.music.play()
            self.openWindow()
        elif selecttime.alarmtime5 == alarm_time:
            selecttime.alarmtime5 = ''
            selecttime.time5 = ''
            pygame.mixer.music.play()
            self.openWindow()

    def end_music(self):
        pygame.mixer.music.stop()
        
    def myshow(self):
        ui = Ui_MainWindow()
        ui.setupUi(MainWindow)
        MainWindow.showFullScreen()

    def setReason(self):
        global changereason
        changereason -= 1
        #print(changereason)
        if changereason == 0:
            global reason
            reason = listofreasons[random.randint(0, 49)] # 0 and 49 included
            changereason = 600


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    timer = QtCore.QTimer(MainWindow)
    timer.timeout.connect(lambda: ui.retranslateUi(MainWindow))
    timer.start(1000)
    #MainWindow.show()
    MainWindow.setCursor(QtCore.Qt.BlankCursor)
    MainWindow.showFullScreen()
    sys.exit(app.exec_())
