diff --git a/src/plan2.py b/src/plan2.py index a670665d96d35a97f1fa166bdc6dbee3af1e455c..e371dab9b9a1170fd9e2a6cb92febb84e9bebe7e 100644 --- a/src/plan2.py +++ b/src/plan2.py @@ -2,17 +2,18 @@ import sqlite3 from PyQt6.QtWidgets import QApplication, QLabel, QWidget, QPushButton, QMessageBox from PyQt6.QtGui import QFont, QPixmap, QCursor, QMovie, QIcon from PyQt6.QtCore import Qt, QSize, QUrl, QTimer, QTime +from PyQt6.QtMultimedia import QMediaPlayer # from PyQt6.QtMultimedia import QSoundEffect import time import sys -conn = sqlite3.connect("fitu.db") -c = conn.cursor() -latihan = c.execute("SELECT gif FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall() -print(latihan) class plan(QWidget): def __init__(self): super().__init__() self.index = 0 + self.conn = sqlite3.connect("fitu.db") + self.c = self.conn.cursor() + self.latihan = self.c.execute("SELECT gif FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall() + print(self.latihan) # self.remaining_time = 0 self.timer = QTimer(self) self.timer.timeout.connect(self.updateTimer) @@ -24,13 +25,24 @@ class plan(QWidget): def setUpWindowPlan(self): self.setWindowTitle("FitU - Plan") self.setFixedSize(1280, 720) + # background = QMovie("img/background.gif") + # background.setScaledSize(QSize(1280, 720)) + # background_label = QLabel(self) + # background_label.setGeometry(0, 0, 1280, 720) + # background_label.setMovie(background) + # background.start() + + # set the background style sheet + # self.setStyleSheet("background-image: url(img/background.gif);") + self.setUpPlan() def updateTimer(self): - if self.remaining_time > 0: - self.remaining_time -= 1 - minutes = self.remaining_time // 60 - seconds = self.remaining_time % 60 + # print(type(self.remaining_time)) + if int(self.remaining_time) > 0: + self.remaining_time = int(self.remaining_time) - 1 + minutes = int(self.remaining_time) // 60 + seconds = int(self.remaining_time) % 60 self.timer_label.setText(f"{minutes:02d}:{seconds:02d}") else: self.timer.stop() @@ -40,8 +52,7 @@ class plan(QWidget): def resetTimer(self): self.remaining_time = self.duration[self.index][0] self.timer.start(1000) - if(self.duration[self.index][0]<59): - + if(int(self.duration[self.index][0])<59): self.timer_label.setText("00:"+str(self.remaining_time)) else: self.timer_label.setText("00:"+str(self.remaining_time)) @@ -51,6 +62,7 @@ class plan(QWidget): def setUpPlan(self): self.setStyleSheet('background-color: #5A8D6C') + backButton = QPushButton(self) backButton.setGeometry(200, 150, 100, 100) @@ -65,7 +77,7 @@ class plan(QWidget): self.currEx.setFixedSize(360, 335) self.currEx.move(460, 105) self.currEx.setStyleSheet("background-color: #EEEEE2; border-radius: 25px; border: 2px") - self.movie = QMovie(latihan[0][0]) + self.movie = QMovie(self.latihan[0][0]) self.currEx.setMovie(self.movie) self.movie.start() # self.movie.setScaledSize(QSize(330, 305)) @@ -121,27 +133,27 @@ class plan(QWidget): # effect.setLoopCount(-2) # effect.play() - # if self.index == len(latihan): + # if self.index == len(self.latihan): # nextButton.setEnabled(False) # titleProgram = c.execute(f"SELECT name FROM program WHERE program_id = {programId}").fetchone() - # nameExe = c.execute(f"SELECT name FROM daftar_latihan WHERE exercise_id in (SELECT exercise_id FROM latihan_program)").fetchall() + # nameExe = c.execute(f"SELECT name FROM daftar_self.latihan WHERE exercise_id in (SELECT exercise_id FROM self.latihan_program)").fetchall() # date = time.strftime("%Y-%m-%d", time.localtime()) - # totDuration = c.execute(f"SELECT SUM(duration) FROM daftar_latihan WHERE exercise_id in (SELECT exercise_id FROM latihan_program)").fetchone() - # c.execute("INSERT INTO riwayat_latihan program_id, name, title_program, date, tot_duration VALUES ({programId}, {nameExe}, {titleProgram}, {date}, {totDuration})") + # totDuration = c.execute(f"SELECT SUM(duration) FROM daftar_self.latihan WHERE exercise_id in (SELECT exercise_id FROM self.latihan_program)").fetchone() + # c.execute("INSERT INTO riwayat_self.latihan program_id, name, title_program, date, tot_duration VALUES ({programId}, {nameExe}, {titleProgram}, {date}, {totDuration})") - self.name = c.execute(f"SELECT title FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall() + self.name = self.c.execute(f"SELECT title FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall() print(self.name) self.nameLabel = QLabel(self) self.nameLabel.setText(self.name[self.index][0]) print(self.name[self.index][0]) - self.nameLabel.setFont(QFont("Arial", 20, QFont.Weight.Bold)) + self.nameLabel.setFont(QFont("Segoe UI", 20, QFont.Weight.Bold)) self.nameLabel.setStyleSheet("color: #EEEEE2") self.nameLabel.move(600, 461) self.nameLabel.setFixedWidth(200) # duration = QLabel(self) self.repLabel = QLabel(self) - self.repLabel.setFont(QFont("Arial", 20, QFont.Weight.Bold)) + self.repLabel.setFont(QFont("Segoe UI", 20, QFont.Weight.Bold)) self.repLabel.setStyleSheet("color: #EEEEE2") self.repLabel.move(547, 510) @@ -151,9 +163,10 @@ class plan(QWidget): self.timer_label.move(547, 510) self.timer_label.setFont(QFont("Arial", 20, QFont.Weight.Bold)) self.timer_label.setStyleSheet("background-color: #EEEEE2; border-radius: 10px; border: 2px") - # durationCount = c.execute(f"SELECT duration FROM daftar_latihan WHERE exercise_id in (SELECT exercise_id FROM latihan_program WHERE program_id = 1)").fetchall() - self.repCount = c.execute(f"SELECT repetition FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall() - self.duration = c.execute(f"SELECT duration FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall() + # durationCount = c.execute(f"SELECT duration FROM daftar_self.latihan WHERE exercise_id in (SELECT exercise_id FROM self.latihan_program WHERE program_id = 1)").fetchall() + self.repCount = self.c.execute(f"SELECT repetition FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall() + self.duration = self.c.execute(f"SELECT duration FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = 1").fetchall() + print(type(self.duration[self.index+1][0])) for i in self.repCount: print("rep",i) for i in self.duration: @@ -166,12 +179,22 @@ class plan(QWidget): self.repetitionLabel() print((self.repCount[self.index][0])==None) + # player = QMediaPlayer() + # # playlist = QMediaPlaylist() + # media = QMediaContent(QUrl.fromLocalFile("BGM ITS OKAY NOT TO BE OKAY.mp3")) # Add your background music file here + # player.setMedia(media) + # player.setPlaybackMode(QMediaPlaylist.Loop) + # player.setMedia(player) + + # button = QPushButton("Toggle BGM") + # button.clicked.connect(lambda: player.play() if player.state() == QMediaPlayer.StoppedState else player.stop()) + # player.play() def prevEx(self): if self.index > 0: self.index -= 1 - self.movie = QMovie(latihan[self.index][0]) + self.movie = QMovie(self.latihan[self.index][0]) self.currEx.setMovie(self.movie) self.movie.start() self.movie.setScaledSize(QSize(330, 305)) @@ -188,9 +211,9 @@ class plan(QWidget): def nextEx(self): - if self.index < (len(latihan)) - 1: + if self.index < (len(self.latihan)) - 1: self.index += 1 - self.movie = QMovie(latihan[self.index][0]) + self.movie = QMovie(self.latihan[self.index][0]) self.currEx.setMovie(self.movie) self.movie.start() self.movie.setScaledSize(QSize(330, 305)) @@ -203,6 +226,8 @@ class plan(QWidget): self.repetitionLabel() self.nameLabel.setText(self.name[self.index][0]) print(self.index) + + if __name__ == "__main__":