diff --git a/img/exe-bearcrawl.gif b/img/exe-bearcrawl.gif new file mode 100644 index 0000000000000000000000000000000000000000..3f8773df67d8c370cbe934283e9b2a6c1fd7415d Binary files /dev/null and b/img/exe-bearcrawl.gif differ diff --git a/img/exe-hipdip.gif b/img/exe-hipdip.gif new file mode 100644 index 0000000000000000000000000000000000000000..678931334f0f5dd3f732904e7c492b610b2a478e Binary files /dev/null and b/img/exe-hipdip.gif differ diff --git a/img/exe-shouldertap.gif b/img/exe-shouldertap.gif new file mode 100644 index 0000000000000000000000000000000000000000..6623a22fbaa43936d41faf5f382efff878780064 Binary files /dev/null and b/img/exe-shouldertap.gif differ diff --git a/img/exe-toetap.gif b/img/exe-toetap.gif new file mode 100644 index 0000000000000000000000000000000000000000..bc161f240737152609ef3fee27bd0fc76a1ffdf1 Binary files /dev/null and b/img/exe-toetap.gif differ diff --git a/src/controller.py b/src/controller.py index d90966b06c911accc18feabd154a0fdbcb00bd2a..7bafc807d6aac898ac1484bd28611b7e29340e63 100644 --- a/src/controller.py +++ b/src/controller.py @@ -4,21 +4,31 @@ import sqlite3 from register import register from dashboard import dashboard from listlatihan2 import listLatihan2 -from tesBacaDB import tesBaca from customize import customizeWorkout from plan import plan +from plan2 import plan2 +from endOfExercise import endOfExe +import os +import os.path class controller: def __init__(self): + self.initDatabase() self.conn = sqlite3.connect('fitu.db') - self.tesBacaDB = tesBaca() self.registerWin = register() self.registerWin.switch.connect(self.fromRegister) self.dashboard = dashboard() self.dashboard.switch.connect(self.fromDashboard) self.listLatihan = listLatihan2() self.listLatihan.switch.connect(self.fromListLatihan) - self.customize = customizeWorkout() + self.customize = customizeWorkout(0) + self.customize.switch.connect(self.fromCustomize) self.plan = plan() + self.plan.switch.connect(self.fromPlan) + self.plan2 = plan2(1) + self.plan.switch.connect(self.toPlan2) + self.endOfExe = endOfExe() + self.endOfExe.switch.connect(self.toEndOfExe) + self.endOfExe.switch.connect(self.fromEndOfExe) pass @@ -34,9 +44,11 @@ class controller: def fromRegister(self): self.registerWin.close() + self.dashboard = dashboard() + self.dashboard.switch.connect(self.fromDashboard) self.dashboard.show() - def fromDashboard(self, page): + def fromDashboard(self, page, program_id): self.registerWin.close() self.dashboard.close() if (page == "listLatihan"): @@ -47,13 +59,199 @@ class controller: self.plan.show() - def fromListLatihan(self, page): + def fromListLatihan(self, page, program_id): self.listLatihan.close() if (page == "dashboard"): self.dashboard.show() elif (page == "customize"): self.customize.show() + elif (page == "plan"): + self.plan.show() + def fromPlan(self, page, program_id): + self.plan.close() + if (page == "dashboard"): + self.dashboard.show() + elif (page == "customize"): + self.customize = customizeWorkout(program_id) + self.customize.switch.connect(self.fromCustomize) + self.customize.show() + elif (page == "listLatihan"): + self.listLatihan.show() + elif (page == "plan2"): + self.plan2 = plan2(program_id) + self.plan2.switch.connect(self.toEndOfExe) + self.plan2.show() + + def fromCustomize(self, page, program_id): + self.customize.close() + if (page == "dashboard"): + self.dashboard.show() + elif (page == "listLatihan"): + self.listLatihan.show() + elif (page == "plan"): + self.plan = plan() + self.plan.switch.connect(self.fromPlan) + self.plan.show() + + def toPlan2(self, page, program_id): + self.plan.close() + if (page == "plan2"): + print("ctrl" + str(program_id)) + self.plan2 = plan2(program_id) + self.plan2.switch.connect(self.toEndOfExe) + self.plan2.show() + + def toEndOfExe(self,page): + self.plan2.close() + if (page == "endOfExe"): + self.endOfExe.show() + + def fromEndOfExe(self,page): + self.endOfExe.close() + if (page == "dashboard"): + self.dashboard = dashboard() + self.dashboard.switch.connect(self.fromDashboard) + self.dashboard.show() + + def initDatabase(self): + if not os.path.exists("fitu.db"): + self.con = sqlite3.connect("fitu.db") + cur = self.con.cursor() + + cur.execute(""" + CREATE TABLE IF NOT EXISTS user ( + name text PRIMARY KEY, + height integer, + weight integer, + goal text, + gender text, + age integer + ) + """) + cur.execute(""" + CREATE TABLE IF NOT EXISTS daftar_latihan ( + exercise_id integer PRIMARY KEY, + title text, + description text, + goals text, + duration integer, + repetition integer, + gif text + ) + """) + + cur.execute(""" + CREATE TABLE IF NOT EXISTS riwayat_latihan ( + history_id integer, + program_id integer, + name text, + title_program text, + calories integer, + date text, + tot_duration integer, + FOREIGN KEY (program_id) REFERENCES program (program_id) + ) + """) + cur.execute(""" + CREATE TABLE IF NOT EXISTS program ( + program_id integer PRIMARY KEY AUTOINCREMENT, + title_program text + ) + """) + + cur.execute(""" + CREATE TABLE IF NOT EXISTS latihan_program ( + program_id integer, + exercise_id integer, + FOREIGN KEY (program_id) REFERENCES program (program_id) + ) + """) + + cur.execute(""" + INSERT or IGNORE INTO daftar_latihan + (exercise_id, title, description, goals, duration, repetition, gif) + VALUES + (101, "Hip Dip", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-hipdip.gif"), + (102, "Bear Crawl", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-bearcrawl.gif"), + (103, "Jumping Jacks", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-jumpingjack.gif"), + (104, "Plank", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-plank.gif"), + (105, "Bridge", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-bridges.gif"), + (106, "High Knees", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-highknee.gif"), + (107, "Mountain Climber", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL, "img/exe-mountain.gif"), + (108, "Russian Twist", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', 30, NULL,"img/exe-russian.gif"), + (201, 'Push Up', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor','Goals', NULL, 10, 'img/exe-pushup.gif'), + (202, "Sit Up", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-situp.gif"), + (203, "Toe Tap", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-toetap.gif"), + (204, "Shoulder Tap", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-shouldertap.gif"), + (205, "Lunges", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-lunges.gif"), + (206, "Crunches", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-crunches.gif"), + (207, "Burpees", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-burpees.gif"), + (208, "Bicycle Crunch", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac venenatis purus. Nulla a fringilla ante. Aenean id ipsum pellentesque, convallis ex eget, cursus dolor", 'Goals', NULL, 10, "img/exe-bicycle.gif") + """) + + cur.execute(""" + INSERT or IGNORE INTO program + (program_id, title_program) + VALUES + (1, 'Full Body Workout'), + (2, 'Upper Body Workout'), + (3, 'Lower Body Workout'), + (4, 'Core Workout') + """) + + cur.execute(""" + INSERT or IGNORE INTO latihan_program + (program_id, exercise_id) + VALUES + (1, 201), + (1, 105), + (1, 106), + (1, 202), + (2, 104), + (2, 107), + (2, 108), + (2, 201), + (3, 202), + (3, 205), + (3, 106) + """) + + # cur.execute(""" + # INSERT INTO riwayat_latihan + # (program_id, name, title_program, calories, date, tot_duration) + # VALUES + # (1, 'Push Up', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Sit Up', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Pull Up', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Squat Jump', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Lunges', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Crunches', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Burpees', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Bicycle Crunch', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Jumping Rope', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Running', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Jumping Jacks', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Plank', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Bridge', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'High Knees', 'Chest Day', 100, '2020-12-12', 30), + # (1, 'Squat', 'Chest Day', 100, '2020-12-12', 30), + # (2, 'Push Up', 'Leg Day', 100, '2020-12-15', 30), + # (2, 'Sit Up', 'Leg Day', 100, '2020-12-15', 30), + # (2, 'Pull Up', 'Leg Day', 100, '2020-12-15', 30), + # (2, 'Squat Jump', 'Leg Day', 100, '2020-12-15', 30), + # (2, 'Lunges', 'Leg Day', 100, '2020-12-15', 30), + # (2, 'Crunches', 'Leg Day', 100, '2020-12-15', 30), + # (2, 'Burpees', 'Leg Day', 100, '2020-12-15', 30), + # (2, 'Bicycle Crunch', 'Leg Day', 100, '2020-12-15', 30), + # (2, 'Jumping Rope', 'Leg Day', 100, '2020-12-15', 30), + # (2, 'Running', 'Leg Day', 100, '2020-12-15', 30) + # """) + + self.con.commit() + self.con.close() + else: + print("Database already exists") if __name__ == "__main__": app = QApplication(sys.argv) controller = controller() diff --git a/src/customize.py b/src/customize.py index 5fce0a1d4efe51b488d4c562ea95511eaaab3883..9443c641947263b1a1af916512aca7ef11a690b1 100644 --- a/src/customize.py +++ b/src/customize.py @@ -13,13 +13,14 @@ text_color = '#EEEEE2' cardColor = '#D2DCC4' class customizeWorkout(QWidget): - switch = pyqtSignal(str, dict) + switch = pyqtSignal(str, int, dict) - def __init__(self): + def __init__(self, program_id): super().__init__() self.con = sqlite3.connect('fitu.db') - self.listEx = self.fetchListEx() + self.listEx = self.fetchListEx() + self.program_id = program_id self.setupGUI() def fetchListEx(self): @@ -141,6 +142,7 @@ class customizeWorkout(QWidget): homeButton.move(507, 53) homeButton.setCursor( QCursor(Qt.CursorShape.PointingHandCursor)) + homeButton.clicked.connect(self.dashboardWindow) # tombol customize customizeButton = QPushButton(self) @@ -158,6 +160,7 @@ class customizeWorkout(QWidget): customizeButton.move(649, 53) customizeButton.setCursor( QCursor(Qt.CursorShape.PointingHandCursor)) + # customizeButton.clicked.connect(self.customizeWindow) # tombol plan planButton = QPushButton(self) @@ -174,6 +177,7 @@ class customizeWorkout(QWidget): planButton.move(807, 58) planButton.setCursor( QCursor(Qt.CursorShape.PointingHandCursor)) + planButton.clicked.connect(self.planWindow) # tombol list listButton = QPushButton(self) @@ -190,6 +194,7 @@ class customizeWorkout(QWidget): listButton.move(898, 58) listButton.setCursor( QCursor(Qt.CursorShape.PointingHandCursor)) + listButton.clicked.connect(self.listWindow) # tombol history historyButton = QPushButton(self) @@ -302,9 +307,50 @@ class customizeWorkout(QWidget): scroll2.setWidget(scrollWidget2) area2 = [] - + + if self.program_id != 0: + cur = self.con.cursor() + self.latihan = cur.execute(f"SELECT exercise_id FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = {self.program_id}").fetchall() + print(self.latihan) + for i in range(len(self.latihan)): + area2.append(self.latihan[i][0]) + exLabel = QLabel(self) + exLabel.setFixedSize(367, 99) + exLabel.setStyleSheet("background-color: #5A8D6C; border-radius: 20px;") + exLabel1 = QLabel(exLabel) + exLabel1.move(10, 10) + exLabel1.setFixedSize(79, 79) + exLabel1.setStyleSheet(styleSheet5) + + #add gif + gif = QMovie('img/exe-pushup.gif') + exLabel1.setMovie(gif) + gif.start() + gif.setScaledSize(QSize(79, 79)) + gif.setSpeed(100) + title = QLabel(exLabel) + title.setText(f'<font style="font-size:24px;" color="#D2DCC4"; font-family="Sogoe UI";><b>{self.listEx[i][1]}<b>') + title.move(100, 15) + repDur = QLabel(exLabel) + if(i<8): + repDur.setText(f'<font style="font-size:14px;" color="#D2DCC4"; font-family="Sogoe UI";><b>{self.listEx[i][4]} Seconds<b>') + repDur.move(100, 60) + else: + repDur.setText(f'<font style="font-size:14px;" color="#D2DCC4"; font-family="Sogoe UI";><b>{self.listEx[i][5]} Repetition<b>') + repDur.move(100,60) + deleteButton = QPushButton(exLabel) + deleteButton.setIcon(QIcon('img/delete button.png')) + deleteButton.setIconSize(QPixmap('img/delete button.png').size()) + deleteButton.setGeometry(320, 55, 36, 36) + deleteButton.move(320, 55) + deleteButton.setCursor( + QCursor(Qt.CursorShape.PointingHandCursor)) + deleteButton.clicked.connect(lambda checked, index=i: handleDeleteButtonClicked(index, exLabel, scrollLayout2)) + scrollLayout2.addWidget(exLabel) + def handleButtonClicked(i, buttonList): - area2.append(i) + + area2.append(self.listEx[i][0]) button = buttonList[i] button.setEnabled(False) button.setIcon(QIcon('img/check button.png')) @@ -328,10 +374,10 @@ class customizeWorkout(QWidget): title.move(100, 15) repDur = QLabel(exLabel) if(i<8): - repDur.setText(f'<font style="font-size:14px;" color="#D2DCC4"; font-family="Sogoe UI";><b>{self.listEx[i][4]} Detik<b>') + repDur.setText(f'<font style="font-size:14px;" color="#D2DCC4"; font-family="Sogoe UI";><b>{self.listEx[i][4]} Seconds<b>') repDur.move(100, 60) else: - repDur.setText(f'<font style="font-size:14px;" color="#D2DCC4"; font-family="Sogoe UI";><b>{self.listEx[i][5]} Repetisi<b>') + repDur.setText(f'<font style="font-size:14px;" color="#D2DCC4"; font-family="Sogoe UI";><b>{self.listEx[i][5]} Repetition<b>') repDur.move(100,60) deleteButton = QPushButton(exLabel) deleteButton.setIcon(QIcon('img/delete button.png')) @@ -356,7 +402,7 @@ class customizeWorkout(QWidget): if(progNameInput.text() == '' or scrollLayout2 == []): QMessageBox.about(self, "Error", "Please input program name") else: - # QMessageBox.about(self, "Success", "Program saved") + QMessageBox.about(self, "Success", "Program saved") # self.close() cur = self.con.cursor() data = cur.execute("SELECT program_id FROM program") @@ -366,11 +412,11 @@ class customizeWorkout(QWidget): ) for i in area2: cur.execute( - f"INSERT INTO latihan_program (program_id, exercise_id) VALUES ({lenProg+1} ,{self.listEx[i][0]})" + f"INSERT INTO latihan_program (program_id, exercise_id) VALUES ({lenProg+1} ,{i})" ) print(lenProg) self.con.commit() - self.close() + @@ -435,7 +481,15 @@ class customizeWorkout(QWidget): saveButton.setCursor( QCursor(Qt.CursorShape.PointingHandCursor)) saveButton.clicked.connect(saveButtonClicked) + + def planWindow(self): + self.switch.emit("plan", 0, {}) + + def listWindow(self): + self.switch.emit("listLatihan", 0, {}) + def dashboardWindow(self): + self.switch.emit("dashboard", 0, {}) if __name__ == '__main__': app = QApplication(sys.argv) diff --git a/src/dashboard.py b/src/dashboard.py index bf038ff8ca5d870b36a43be798f49ca077f0d7c2..c5a9398bc669b6050c284a313e4748c24833b1b9 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -1,12 +1,11 @@ import sys -from PyQt6.QtCore import Qt, pyqtSignal, QSize, pyqtSignal +from PyQt6.QtCore import Qt, pyqtSignal, QSize from PyQt6.QtGui import QCursor, QFont, QPixmap, QMovie from PyQt6.QtWidgets import QApplication, QLabel, QPushButton, QWidget, QScrollArea, QVBoxLayout, QHBoxLayout import sqlite3 -con = sqlite3.connect("fitu.db") -cur = con.cursor() +# cur = sqlite3.connect("fitu.db").cursor() background = '#5A8D6C' button_color = '#174728' @@ -53,20 +52,26 @@ styleSheetCard = ( class dashboard(QWidget): - switch = pyqtSignal(str, dict) + switch = pyqtSignal(str, int,dict) def __init__(self, user=None): super().__init__() - if (user == None): - self.user = { - 'name': 'krisi', - 'height': 170, - 'weight': 65, - 'gender': 'Perempuan', - 'age': 20, - 'goal': 'I want to have a sixpack stomach' - } - else: - self.user = user + self.con = sqlite3.connect("fitu.db") + self.cur = self.con.cursor() + self.biodata = self.cur.execute("SELECT * FROM user").fetchall() + print(self.biodata) + # if (self.biodata == None): + # self.switch.emit('register', {}) + # self.user = { + # 'name': f'{self.biodata[0][0]}', + # 'height': self.biodata[0][1], + # 'weight': self.biodata[0][2], + # 'goal': f'{self.biodata[0][3]}', + # 'gender': f'{self.biodata[0][4]}', + # 'age': self.biodata[0][5] + # } + # else: + # self.user = user + self.index_history = int(-1) self.banyaknyaKartu = int(-1) self.dashboardWindow() @@ -79,24 +84,27 @@ class dashboard(QWidget): self.label.setParent(self) self.element() - def historyElement(self, historyDate, idx): + def historyElement(self, historyIdx, idx): + # self.cur = self.con.cursor() + print(idx) self.index_history = idx - print(self.index_history) - print("panjang historyDate: ", len(historyDate)) - tanggal = historyDate[self.index_history][0] - print(tanggal) + tanggal = self.cur.execute(f""" + SELECT strftime(date) FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}' + """).fetchone()[0] + # menyiapkan history card self.card = QLabel(self) self.card.setPixmap(QPixmap('img/card-dashboard.png')) self.card.move(633, 172) - daftar_latihan = cur.execute(f""" - SELECT name FROM riwayat_latihan WHERE date = '{tanggal}' + daftar_latihan = self.cur.execute(f""" + SELECT name FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}' """).fetchall() jumlahCard = len(daftar_latihan) self.banyaknyaKartu = jumlahCard + print(self.banyaknyaKartu) self.date = QLabel(self) self.date.setText(f"{tanggal}") @@ -105,8 +113,8 @@ class dashboard(QWidget): self.date.setFont(dateFont) self.date.setAlignment(Qt.AlignmentFlag.AlignLeft) - keterangan = cur.execute(f""" - SELECT tot_duration, title_program FROM riwayat_latihan WHERE date = '{tanggal}' + keterangan = self.cur.execute(f""" + SELECT tot_duration, title_program FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}' """).fetchone() print(keterangan) self.duration = QLabel(self) @@ -121,7 +129,7 @@ class dashboard(QWidget): self.prog.setText("Program Name: " + keterangan[1]) self.prog.setStyleSheet(f'color: {button_color}; background-color: {card_color};') self.prog.move(667, 317) - self.prog.setFixedWidth(300) + self.prog.setFixedWidth(497) self.prog.setFont(historyFont) self.prog.setAlignment(Qt.AlignmentFlag.AlignLeft) @@ -150,23 +158,22 @@ class dashboard(QWidget): """ self.scroll.horizontalScrollBar().setStyleSheet(scroll_bar_style) self.hbox = QHBoxLayout() - print(jumlahCard) for j in range(self.banyaknyaKartu): self.label = QLabel() self.label.setFixedSize(150, 175) self.label.setStyleSheet(styleSheetCard) self.hbox.addWidget(self.label) nama_latihan = daftar_latihan[j][0] - repetisi_latihan = cur.execute(f""" + repetisi_latihan = self.cur.execute(f""" SELECT repetition FROM daftar_latihan WHERE title = '{nama_latihan}' """).fetchone() - durasi_latihan = cur.execute(f""" + durasi_latihan = self.cur.execute(f""" SELECT duration FROM daftar_latihan WHERE title = '{nama_latihan}' """).fetchone() - gambar_latihan = cur.execute(f""" + gambar_latihan = self.cur.execute(f""" SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}' """).fetchone() - con.commit() + self.con.commit() self.show_nama_latihan = QLabel(self.label) self.show_nama_latihan.setText(nama_latihan) self.show_nama_latihan.setStyleSheet(f'color: {card_color};') @@ -184,7 +191,9 @@ class dashboard(QWidget): self.show_repetisi_latihan.setFont(repetisiFont) self.show_repetisi_latihan.setAlignment(Qt.AlignmentFlag.AlignLeft) - self.gif = "img/exercise-unscreen.gif" + self.gif = self.cur.execute(f""" + SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone()[0] self.gif2 = QMovie(self.gif) self.gif2.setScaledSize(QSize(90, 90)) self.gif2.start() @@ -207,7 +216,7 @@ class dashboard(QWidget): self.kiri.setFont(dateFont) self.kiri.move(727, 195) self.kiri.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) - self.kiri.clicked.connect(lambda:self.prev(historyDate)) + self.kiri.clicked.connect(lambda:self.prev(historyIdx)) self.kanan = QPushButton(self) @@ -223,14 +232,46 @@ class dashboard(QWidget): self.kanan.setFont(dateFont) self.kanan.move(1047, 195) self.kanan.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) - self.kanan.clicked.connect(lambda:self.next(historyDate)) + self.kanan.clicked.connect(lambda:self.next(historyIdx)) - if(idx == len(historyDate)-1): + if(self.index_history == len(historyIdx)-1): self.kanan.hide() - elif (idx == 0): + self.kiri.show() + elif (self.index_history == 0): self.kiri.hide() + self.kanan.show() + else: + self.kiri.show() + self.kanan.show() + def historyKosong(self): + # menyiapkan history card + self.card = QLabel(self) + self.card.setPixmap(QPixmap('img/card-dashboard.png')) + self.card.move(633, 172) + + self.text1 = QLabel(self) + self.text1.setText("You Haven't Completed\nAny Training yet!") + self.text1.setStyleSheet(f'color: {button_color}; background-color: {card_color};') + self.text1.move(743, 286) + dateFont.setBold(False) + self.text1.setFont(dateFont) + self.text1.setAlignment(Qt.AlignmentFlag.AlignCenter) + + + self.text2 = QLabel(self) + self.text2.setText("Let's start training now!") + self.text2.setStyleSheet(f'color: {button_color}; background-color: {card_color};') + self.text2.move(780, 448) + dateFont.setPointSize(18) + self.text2.setFont(dateFont) + dateFont.setBold(True) + dateFont.setPointSize(23) + self.text2.setAlignment(Qt.AlignmentFlag.AlignLeft) + + def element(self): + self.cur = self.con.cursor() # masukkan logo logo = QLabel(self) logo.setPixmap(QPixmap('img/logo-dashboard.png')) @@ -249,11 +290,11 @@ class dashboard(QWidget): ''') homeButton.setFont(buttonFont) homeButton.setFixedSize(96, 42) #pake ini buat kalau dia buletan - homeButton.move(507, 53) - homeButton.setCursor( - QCursor(Qt.CursorShape.PointingHandCursor)) + homeButton.move(660, 53) + # homeButton.setCursor( + # QCursor(Qt.CursorShape.PointingHandCursor)) - # tombol customize + # tombol customize customizeButton = QPushButton(self) customizeButton.setText('Customize') customizeButton.setStyleSheet(f''' @@ -263,9 +304,12 @@ class dashboard(QWidget): border: none; border-radius: 20px; }} + QPushButton:hover {{ + color: {button_color}; + }} ''') customizeButton.setFont(buttonFont) - customizeButton.move(649, 58) + customizeButton.move(798, 58) customizeButton.setCursor( QCursor(Qt.CursorShape.PointingHandCursor)) customizeButton.clicked.connect(self.customWindow) @@ -280,9 +324,12 @@ class dashboard(QWidget): border: none; border-radius: 20px; }} + QPushButton:hover {{ + color: {button_color}; + }} ''') planButton.setFont(buttonFont) - planButton.move(807, 58) + planButton.move(956, 58) planButton.setCursor( QCursor(Qt.CursorShape.PointingHandCursor)) planButton.clicked.connect(self.planWindow) @@ -297,30 +344,16 @@ class dashboard(QWidget): border: none; border-radius: 20px; }} + QPushButton:hover {{ + color: {button_color}; + }} ''') listButton.setFont(buttonFont) - listButton.move(898, 58) + listButton.move(1047, 58) listButton.setCursor( QCursor(Qt.CursorShape.PointingHandCursor)) listButton.clicked.connect(self.listWindow) - - # tombol history - historyButton = QPushButton(self) - historyButton.setText('History') - historyButton.setStyleSheet(f''' - QPushButton {{ - color: {text_color}; - background-color: {background}; - border: none; - border-radius: 20px; - }} - ''') - historyButton.setFont(buttonFont) - historyButton.move(979, 58) - historyButton.setCursor( - QCursor(Qt.CursorShape.PointingHandCursor)) - # foto profil profilePhoto = QLabel(self) profilePhoto.setPixmap(QPixmap('img/profile-dashboard.png')) @@ -328,15 +361,19 @@ class dashboard(QWidget): # say Hello self.hello = QLabel(self) - self.hello.setText(f"Hello, {self.user['name']}!") + # self.hello.setText(f"Hello, krisi!") self.hello.move(101, 236) self.hello.setFont(helloFont) + if(self.biodata == []): + self.hello.setText(f"Hello, dummy!") + else: + self.hello.setText(f"Hello, {self.biodata[0][0].split(' ')[0]}!") self.hello.setStyleSheet(f'color: {text_color};') self.hello.setAlignment(Qt.AlignmentFlag.AlignLeft) # quote quote = QLabel(self) - quote.setText("Saran quote dong maz\nbingung mau naro quote apa nih") + quote.setText("“Strength does not come from\nphysical capacity. It comes from\nan indomitable will.â€\n-Mahatma Gandhi") quote.setStyleSheet(f'color: {text_color};') quote.move(101, 320) quote.setFont(quoteFont) @@ -351,6 +388,10 @@ class dashboard(QWidget): background-color: {button_color}; border: none; border-radius: 20px; + }} + QPushButton:hover {{ + color: #5A8D6C; + background-color: #D2DCC4; }} ''') start.setFont(buttonFont) @@ -360,89 +401,95 @@ class dashboard(QWidget): start.clicked.connect(self.planWindow) # membuat history card - historyDate = cur.execute(""" - SELECT DISTINCT strftime(date) FROM riwayat_latihan + historyIdx = self.cur.execute(""" + SELECT DISTINCT history_id FROM riwayat_latihan """).fetchall() + print(historyIdx) # menyiapkan history card - - print(len(historyDate)) - tanggal = historyDate[0][0] - print(tanggal) - idx = (len(historyDate)-1) - # print(idx) - self.historyElement(historyDate, idx) - - def prev(self, historyDate): - if (self.index_history == 0): - self.kiri.hide() + + if (len(historyIdx) <= 0): + self.historyKosong() else: + tanggal = historyIdx[0][0] + idx = (len(historyIdx)-1) + self.historyElement(historyIdx, idx) + + def prev(self, historyIdx): + self.cur = self.con.cursor() + self.index_history -= 1 + if(self.index_history == len(historyIdx)-1): + self.kanan.hide() + self.kiri.show() + elif (self.index_history == 0): + self.kiri.hide() + self.kanan.show() + else: + self.kiri.show() + self.kanan.show() self.scroll.setParent(None) - tanggal = historyDate[self.index_history-1][0] + tanggal = self.cur.execute(f""" + SELECT strftime(date) FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}' + """).fetchone()[0] + print('tanggal',tanggal) self.date.setText(f"{tanggal}") - daftar_latihan = cur.execute(f""" - SELECT name FROM riwayat_latihan WHERE date = '{tanggal}' + daftar_latihan = self.cur.execute(f""" + SELECT name FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}' """).fetchall() - print(daftar_latihan) jumlahCard = len(daftar_latihan) - keterangan = cur.execute(f""" - SELECT tot_duration, title_program FROM riwayat_latihan WHERE date = '{tanggal}' + keterangan = self.cur.execute(f""" + SELECT tot_duration, title_program FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}' """).fetchone() + print('keterangan',keterangan) self.duration.setText("Duration : " + str(keterangan[0]) + " minutes") self.prog.setText("Program Name: " + keterangan[1]) - # for k in range(self.banyaknyaKartu): - # print(k) - # self.boxdelete(k) - # self.scroll.setParent(None) for i in reversed(range(self.banyaknyaKartu)): self.hbox.itemAt(i).widget().setParent(None) - # self.scroll = QScrollArea(self) - # self.scroll.setGeometry(654, 369, 486, 204) # mengatur posisi dan ukuran QScrollArea - # self.scroll.setStyleSheet(f"background-color: {card_color}; border-radius: 0px;") - # self.scrollWidget = QWidget(self.scroll) - # self.scrollLayout = QVBoxLayout(self.scrollWidget) - # self.scrollWidget.setStyleSheet(f"background-color: {card_color}; border-radius: 0px;") - # self.scrollWidget.setLayout(self.scrollLayout) - # horizontal_scrollbar = self.scroll.horizontalScrollBar() - # # Mengatur bentuk scroll bar - # scroll_bar_style = """ - # QScrollBar:horizontal { - # border : 0px; - # background-color: #5A8D6C; - # height: 10px; - # margin: 0px 0px 0px 0px; - # } - # QScrollBar::handle:horizontal { - # background-color: #174728; - # border-radius: 50px; - # border: 0px; - # } - # """ - # self.scroll.horizontalScrollBar().setStyleSheet(scroll_bar_style) - # self.hbox = QHBoxLayout() - # print(jumlahCard) + self.scroll = QScrollArea(self) + self.scroll.setGeometry(654, 369, 486, 204) # mengatur posisi dan ukuran QScrollArea + self.scroll.setStyleSheet(f"background-color: {card_color}; border-radius: 0px;") + self.scrollWidget = QWidget(self.scroll) + self.scrollLayout = QVBoxLayout(self.scrollWidget) + self.scrollWidget.setStyleSheet(f"background-color: {card_color}; border-radius: 0px;") + self.scrollWidget.setLayout(self.scrollLayout) + horizontal_scrollbar = self.scroll.horizontalScrollBar() + # Mengatur bentuk scroll bar + scroll_bar_style = """ + QScrollBar:horizontal { + border : 0px; + background-color: #5A8D6C; + height: 10px; + margin: 0px 0px 0px 0px; + } + QScrollBar::handle:horizontal { + background-color: #174728; + border-radius: 50px; + border: 0px; + } + """ + self.scroll.horizontalScrollBar().setStyleSheet(scroll_bar_style) + self.hbox = QHBoxLayout() + self.banyaknyaKartu = jumlahCard for j in range(self.banyaknyaKartu): - print(j) self.label = QLabel() self.label.setFixedSize(150, 175) self.label.setStyleSheet(styleSheetCard) self.hbox.addWidget(self.label) nama_latihan = daftar_latihan[j][0] - print(nama_latihan) - repetisi_latihan = cur.execute(f""" + repetisi_latihan = self.cur.execute(f""" SELECT repetition FROM daftar_latihan WHERE title = '{nama_latihan}' """).fetchone() - durasi_latihan = cur.execute(f""" + durasi_latihan = self.cur.execute(f""" SELECT duration FROM daftar_latihan WHERE title = '{nama_latihan}' """).fetchone() - gambar_latihan = cur.execute(f""" + gambar_latihan = self.cur.execute(f""" SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}' """).fetchone() - con.commit() + self.con.commit() self.show_nama_latihan = QLabel(self.label) self.show_nama_latihan.setText(nama_latihan) self.show_nama_latihan.setStyleSheet(f'color: {card_color};') @@ -460,7 +507,9 @@ class dashboard(QWidget): self.show_repetisi_latihan.setFont(repetisiFont) self.show_repetisi_latihan.setAlignment(Qt.AlignmentFlag.AlignLeft) - self.gif = "img/exercise-unscreen.gif" + self.gif = self.cur.execute(f""" + SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone()[0] self.gif2 = QMovie(self.gif) self.gif2.setScaledSize(QSize(90, 90)) self.gif2.start() @@ -469,56 +518,124 @@ class dashboard(QWidget): self.show_gambar_latihan.move(25, 20) self.scrollLayout.addLayout(self.hbox) self.scroll.setWidget(self.scrollWidget) + self.scroll.show() - def next(self, historyDate): - if (self.index_history == len(historyDate)-1): - self.kanan.hide() - else: - self.historyElement(historyDate, self.index_history+1) + def next(self, historyIdx): + self.cur = self.con.cursor() + self.index_history += 1 + if(self.index_history == len(historyIdx)-1): + self.kanan.hide() + self.kiri.show() + elif (self.index_history == 0): + self.kiri.hide() + self.kanan.show() + else: + self.kiri.show() + self.kanan.show() + self.scroll.setParent(None) + tanggal = self.cur.execute(f""" + SELECT strftime(date) FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}' + """).fetchone()[0] + self.date.setText(f"{tanggal}") + daftar_latihan = self.cur.execute(f""" + SELECT name FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}' + """).fetchall() + jumlahCard = len(daftar_latihan) + keterangan = self.cur.execute(f""" + SELECT tot_duration, title_program FROM riwayat_latihan WHERE history_id = '{historyIdx[self.index_history][0]}' + """).fetchone() + + self.duration.setText("Duration : " + str(keterangan[0]) + " minutes") + self.prog.setText("Program Name: " + keterangan[1]) + + for i in reversed(range(self.banyaknyaKartu)): + self.hbox.itemAt(i).widget().setParent(None) + + self.scroll = QScrollArea(self) + self.scroll.setGeometry(654, 369, 486, 204) # mengatur posisi dan ukuran QScrollArea + self.scroll.setStyleSheet(f"background-color: {card_color}; border-radius: 0px;") + self.scrollWidget = QWidget(self.scroll) + self.scrollLayout = QVBoxLayout(self.scrollWidget) + self.scrollWidget.setStyleSheet(f"background-color: {card_color}; border-radius: 0px;") + self.scrollWidget.setLayout(self.scrollLayout) + horizontal_scrollbar = self.scroll.horizontalScrollBar() + # Mengatur bentuk scroll bar + scroll_bar_style = """ + QScrollBar:horizontal { + border : 0px; + background-color: #5A8D6C; + height: 10px; + margin: 0px 0px 0px 0px; + } + QScrollBar::handle:horizontal { + background-color: #174728; + border-radius: 50px; + border: 0px; + } + """ + self.scroll.horizontalScrollBar().setStyleSheet(scroll_bar_style) + self.hbox = QHBoxLayout() + + self.banyaknyaKartu = jumlahCard + for j in range(self.banyaknyaKartu): + self.label = QLabel() + self.label.setFixedSize(150, 175) + self.label.setStyleSheet(styleSheetCard) + self.hbox.addWidget(self.label) + nama_latihan = daftar_latihan[j][0] + repetisi_latihan = self.cur.execute(f""" + SELECT repetition FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone() + durasi_latihan = self.cur.execute(f""" + SELECT duration FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone() + gambar_latihan = self.cur.execute(f""" + SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone() + self.con.commit() + self.show_nama_latihan = QLabel(self.label) + self.show_nama_latihan.setText(nama_latihan) + self.show_nama_latihan.setStyleSheet(f'color: {card_color};') + self.show_nama_latihan.move(10, 120) + self.show_nama_latihan.setFont(rincianFont) + self.show_nama_latihan.setAlignment(Qt.AlignmentFlag.AlignLeft) + + self.show_repetisi_latihan = QLabel(self.label) + if (repetisi_latihan[0] == None): + self.show_repetisi_latihan.setText("Duration: " + str(durasi_latihan[0]) + " seconds") + else: + self.show_repetisi_latihan.setText("Repetition: " + str(repetisi_latihan[0])) + self.show_repetisi_latihan.setStyleSheet(f'color: {card_color};') + self.show_repetisi_latihan.move(10, 145) + self.show_repetisi_latihan.setFont(repetisiFont) + self.show_repetisi_latihan.setAlignment(Qt.AlignmentFlag.AlignLeft) + + self.gif = self.cur.execute(f""" + SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone()[0] + self.gif2 = QMovie(self.gif) + self.gif2.setScaledSize(QSize(90, 90)) + self.gif2.start() + self.show_gambar_latihan = QLabel(self.label) + self.show_gambar_latihan.setMovie(self.gif2) + self.show_gambar_latihan.move(25, 20) + self.scrollLayout.addLayout(self.hbox) + self.scroll.setWidget(self.scrollWidget) + self.scroll.show() def planWindow(self): - self.switch.emit("plan", {}) + self.switch.emit("plan", 0, {}) def listWindow(self): - self.switch.emit("listLatihan", {}) + self.switch.emit("listLatihan",0, {}) def customWindow(self): - self.switch.emit("customize", {}) + self.switch.emit("customize", 0, {}) - def boxdelete(self, box): - for i in range(self.vlayout.count()): - layout_item = self.vlayout.itemAt(i) - if layout_item.layout() == box: - deleteItemsOfLayout(layout_item.layout()) - self.vlayout.removeItem(layout_item) - break - def clear_item(self, item): - if hasattr(item, "layout"): - if callable(item.layout): - layout = item.layout() - else: - layout = None - - if hasattr(item, "widget"): - if callable(item.widget): - widget = item.widget() - else: - widget = None - - if widget: - widget.setParent(None) - elif layout: - for i in reversed(range(layout.count())): - self.clear_item(layout.itemAt(i)) - - - - if __name__ == '__main__': app = QApplication(sys.argv) window = dashboard() window.show() - sys.exit(app.exec()) - \ No newline at end of file + sys.exit(app.exec()) \ No newline at end of file diff --git a/src/endOfExercise.py b/src/endOfExercise.py index c1f77f337cf331755f0c7dfd9245fbc8be9c4773..c89186a7351c8704085cfccf1fcede4a71b2c2b7 100644 --- a/src/endOfExercise.py +++ b/src/endOfExercise.py @@ -5,14 +5,14 @@ from PyQt6.QtGui import QFont, QPixmap, QCursor from PyQt6.QtCore import Qt, pyqtSignal class endOfExe(QWidget): - switch = pyqtSignal(str) + switch = pyqtSignal(str, dict) def __init__(self): super().__init__() self.conn = sqlite3.connect('fitu.db') self.setUpWindow() def setUpWindow(self): - self.setWindowTitle("FitU - Enf Of Exercise") + self.setWindowTitle("FitU - End Of Exercise") self.setFixedSize(1280, 720) self.setUpEndOfExe() @@ -72,7 +72,7 @@ class endOfExe(QWidget): backButton.clicked.connect(self.backToDash) def backToDash(self): - self.switch.emit("dashboard") + self.switch.emit("dashboard", {}) if __name__ == "__main__": diff --git a/src/listlatihan2.py b/src/listlatihan2.py index 0b618542efc303012bee8fe2b652aba81ebee346..62060e7badd9b3bda415ba9679661adbc817c41d 100644 --- a/src/listlatihan2.py +++ b/src/listlatihan2.py @@ -17,7 +17,7 @@ card_color = '#D2DCC4' class listLatihan2(QWidget): - switch = pyqtSignal(str, dict) + switch = pyqtSignal(str, int, dict) def __init__(self): super().__init__() self.con = sqlite3.connect('fitu.db') @@ -143,7 +143,7 @@ class listLatihan2(QWidget): listButton.move(1025, 53) listButton.setCursor( QCursor(Qt.CursorShape.PointingHandCursor)) - listButton.clicked.connect(self.listWindow) + # listButton.clicked.connect(self.listWindow) # # tombol history @@ -268,16 +268,13 @@ class listLatihan2(QWidget): scroll.setWidget(scrollWidget) def customWindow(self): - self.switch.emit("customize", {}) + self.switch.emit("customize", 0, {}) def planWindow(self): - self.switch.emit("plan", {}) - - def listWindow(self): - self.switch.emit("listLatihan", {}) + self.switch.emit("plan", 0, {}) def dashboard(self): - self.switch.emit("dashboard", {}) + self.switch.emit("dashboard",0, {}) class MyPopup(QDialog): def __init__(self, count, listLat): diff --git a/src/plan.py b/src/plan.py index b0d869e15f403baeb68d84d647aeb7c0b3ea2907..25c67347fd8f3bf35cda9e296532fccace3c5eff 100644 --- a/src/plan.py +++ b/src/plan.py @@ -1,20 +1,20 @@ import sqlite3 import sys -from PyQt6.QtCore import Qt +from PyQt6.QtCore import Qt, pyqtSignal from PyQt6.QtGui import QPixmap, QCursor, QFont from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QHBoxLayout, QVBoxLayout, QPushButton, QScrollArea -# COLORS PALLETE BACKGROUNDCOLOR = '#5A8D6C' BUTTONCOLOR = '#174728' TEXTCOLOR = '#EEEEE2' CARDCOLOR = '#D2DCC4' class plan(QWidget): - + switch = pyqtSignal(str, int, dict ) def __init__(self): super().__init__() + self.clickedRowData = 0 self.con = sqlite3.connect('fitu.db') self.programExercises = self.fetchProgramExercises() self.planWindow() @@ -176,7 +176,8 @@ class plan(QWidget): homeButton.setFixedSize(96, 42) homeButton.move(507, 53) homeButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) - + homeButton.clicked.connect(self.dashboardWindow) + # Customize Button customizeButton = QPushButton(self) customizeButton.setText('Customize') @@ -184,6 +185,7 @@ class plan(QWidget): customizeButton.setFont(buttonFont) customizeButton.move(649, 58) customizeButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + customizeButton.clicked.connect(self.customWindow) # Plan Button planButton = QPushButton(self) @@ -200,6 +202,7 @@ class plan(QWidget): listButton.setFont(buttonFont) listButton.move(898, 58) listButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + listButton.clicked.connect(self.listWindow) # History Button historyButton = QPushButton(self) @@ -253,10 +256,11 @@ class plan(QWidget): con = sqlite3.connect('fitu.db') c = con.cursor() c.execute("SELECT title FROM latihan_program, daftar_latihan WHERE latihan_program.exercise_id = daftar_latihan.exercise_id AND latihan_program.program_id = ?", (data[i][0],)) - data2 = c.fetchall() + self.data2 = c.fetchall() + # c.commit() c.close() - predict = len(data2) + predict = len(self.data2) dur = QLabel(exButton) dur.setText(f'<font style="font-size:18px;" color="#D2DCC4"; font-family="Sogoe UI";>{predict} Minutes') dur.move(20, 50) @@ -285,19 +289,20 @@ class plan(QWidget): # create a function to show exercise data based on index def showExercise(index): - clickedRowData = data[index][0] + self.clickedRowData = data[index][0] con = sqlite3.connect('fitu.db') c = con.cursor() - c.execute("SELECT title, repetition, duration, gif FROM latihan_program, daftar_latihan WHERE latihan_program.exercise_id = daftar_latihan.exercise_id AND latihan_program.program_id = ?", (clickedRowData,)) - data2 = c.fetchall() + c.execute("SELECT title, repetition, duration, gif FROM latihan_program, daftar_latihan WHERE latihan_program.exercise_id = daftar_latihan.exercise_id AND latihan_program.program_id = ?", (self.clickedRowData,)) + self.data3 = c.fetchall() + # print("clicked:" + str(clickedRowData)) c.close() # clear the exercise data list exercise_data.clear() # append new exercise data to the list - for i in range(len(data2)): - exercise_data.append(data2[i]) + for i in range(len(self.data3)): + exercise_data.append(self.data3[i]) # remove all widgets from scrollLayout2 for i in reversed(range(scrollLayout2.count())): @@ -313,7 +318,7 @@ class plan(QWidget): title.move(20, 15) repDur = QLabel(exLabel) if exercise_data[i][1] == None: - repDur.setText(f'<font style="font-size:18px;" color="#D2DCC4"; font-family="Sogoe UI";>{exercise_data[i][2]} Minutes') + repDur.setText(f'<font style="font-size:18px;" color="#D2DCC4"; font-family="Sogoe UI";>{exercise_data[i][2]} Seconds') else: repDur.setText(f'<font style="font-size:18px;" color="#D2DCC4"; font-family="Sogoe UI";>{exercise_data[i][1]} Repetitions') repDur.move(20, 50) @@ -325,8 +330,6 @@ class plan(QWidget): image.setFixedSize(160, 160) scrollLayout2.addWidget(exLabel) - - # set the widget of scroll2 to scrollWidget2 to update the view scroll2.setWidget(scrollWidget2) font = QFont() @@ -354,7 +357,6 @@ class plan(QWidget): progText.setFont(font) progText.move(599, 182) - startButton = QPushButton(self) startButton.setFont(font) startButton.setText("START >") @@ -363,6 +365,7 @@ class plan(QWidget): startButton.setStyleSheet(styleSheetStart) startButton.setFont(font1) startButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + startButton.clicked.connect(self.plan2Window) custButton = QPushButton(self) custButton.setFont(font) @@ -371,6 +374,21 @@ class plan(QWidget): custButton.setStyleSheet(styleSheetCutomize) custButton.setFont(font1) custButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + custButton.clicked.connect(self.customWindow) + + def dashboardWindow(self): + self.switch.emit("dashboard",0, {}) + + def listWindow(self): + self.switch.emit("listLatihan", 0, {}) + + def customWindow(self): + self.switch.emit("customize", self.clickedRowData, {}) + # else: + # self.switch.emit("customize", 0, {}) + + def plan2Window(self): + self.switch.emit("plan2", self.clickedRowData, {}) if __name__ == '__main__': app = QApplication(sys.argv) diff --git a/src/plan2.py b/src/plan2.py index e371dab9b9a1170fd9e2a6cb92febb84e9bebe7e..267a48b89f6e62af1ef9126df836eb0788fee87c 100644 --- a/src/plan2.py +++ b/src/plan2.py @@ -1,18 +1,23 @@ 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.QtCore import Qt, QSize, QUrl, QTimer, pyqtSignal from PyQt6.QtMultimedia import QMediaPlayer +from plan import plan +import time # from PyQt6.QtMultimedia import QSoundEffect import time import sys -class plan(QWidget): - def __init__(self): +class plan2(QWidget): + switch = pyqtSignal(str, dict) + def __init__(self, program_id): 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() + self.program_id = program_id + print("prgram" + str(self.program_id)) + self.latihan = self.c.execute(f"SELECT gif FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = {self.program_id}").fetchall() print(self.latihan) # self.remaining_time = 0 self.timer = QTimer(self) @@ -72,6 +77,7 @@ class plan(QWidget): backButton.setStyleSheet("background-color: #174728; color: #EEEEE2; border-radius: 30px; border: 2px;") backButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) backButton.move(50, 64) + backButton.clicked.connect(self.backToPlan) self.currEx = QLabel(self) self.currEx.setFixedSize(360, 335) @@ -94,37 +100,37 @@ class plan(QWidget): # prevLabel.move(513, 581) # prevLabel.setStyleSheet("background-color: #5A8D6C; border-radius: 20px;") - nextButton = QPushButton(self) - nextButton.setGeometry(200, 150, 100, 100) - nextButton.setIcon(QIcon("img/arrow-right.png")) - nextButton.setIconSize(QPixmap("img/arrow-right.png").size()) - nextButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) - nextButton.setStyleSheet(''' + self.nextButton = QPushButton(self) + self.nextButton.setGeometry(200, 150, 100, 100) + self.nextButton.setIcon(QIcon("img/arrow-right.png")) + self.nextButton.setIconSize(QPixmap("img/arrow-right.png").size()) + self.nextButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + self.nextButton.setStyleSheet(''' QPushButton{ border: 5px #5A8D6C; } QPushButton:hover { background-color: #174728; }''') - nextButton.move(700, 581) - nextButton.clicked.connect(self.nextEx) - - prevButton = QPushButton(self) - prevButton.setGeometry(200, 150, 100, 100) - # prevButton.setStyleSheet("background-image: url(img/arrow-left.png)") - prevButton.setIcon(QIcon("img/arrow-left.png")) - prevButton.setIconSize(QPixmap("img/arrow-left.png").size()) + self.nextButton.move(700, 581) + self.nextButton.clicked.connect(self.nextEx) + + self.prevButton = QPushButton(self) + self.prevButton.setGeometry(200, 150, 100, 100) + # self.prevButton.setStyleSheet("background-image: url(img/arrow-left.png)") + self.prevButton.setIcon(QIcon("img/arrow-left.png")) + self.prevButton.setIconSize(QPixmap("img/arrow-left.png").size()) # print("size: "+ str(QPixmap("img/arrow-left.png").size())) - prevButton.setStyleSheet(''' + self.prevButton.setStyleSheet(''' QPushButton{ border: 5px #5A8D6C; } QPushButton:hover { background-color: #174728; }''') - prevButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) - prevButton.move(513, 581) - prevButton.clicked.connect(self.prevEx) + self.prevButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + self.prevButton.move(513, 581) + self.prevButton.clicked.connect(self.prevEx) # filename = "img/BGM NKCTHI.mp3" # effect = QSoundEffect(self) @@ -133,15 +139,7 @@ class plan(QWidget): # effect.setLoopCount(-2) # effect.play() - # 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_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_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 = self.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 = {self.program_id}").fetchall() print(self.name) self.nameLabel = QLabel(self) self.nameLabel.setText(self.name[self.index][0]) @@ -163,9 +161,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") + self.start = time.time() # 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() + self.repCount = self.c.execute(f"SELECT repetition FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = {self.program_id}").fetchall() + self.duration = self.c.execute(f"SELECT duration FROM daftar_latihan NATURAL JOIN latihan_program WHERE program_id = {self.program_id}").fetchall() print(type(self.duration[self.index+1][0])) for i in self.repCount: print("rep",i) @@ -179,6 +178,22 @@ class plan(QWidget): self.repetitionLabel() print((self.repCount[self.index][0])==None) + self.historyButton = QPushButton(self) + self.historyButton.setFixedSize(100, 100) + self.historyButton.setEnabled(False) + self.historyButton.setText("End") + # self.historyButton.setIcon(QIcon("img/history.png")) + # self.historyButton.setIconSize(QPixmap("img/history.png").size()) + self.historyButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + self.historyButton.setStyleSheet(''' + QPushButton{ + border: 5px #5A8D6C; + } + QPushButton:hover { + background-color: #174728; + }''') + self.historyButton.move(1000, 500) + self.historyButton.clicked.connect(self.addHistory) # player = QMediaPlayer() # # playlist = QMediaPlaylist() # media = QMediaContent(QUrl.fromLocalFile("BGM ITS OKAY NOT TO BE OKAY.mp3")) # Add your background music file here @@ -226,8 +241,52 @@ class plan(QWidget): self.repetitionLabel() self.nameLabel.setText(self.name[self.index][0]) print(self.index) + if self.index == (len(self.latihan)) - 1: + print("selsdasi") + self.historyButton.setEnabled(True) + - + def addHistory(self): + # if self.index +1 >= len(self.latihan): + print(len(self.latihan)) + print("selesai") + self.nextButton.setEnabled(False) + titleProgram = self.c.execute(f"SELECT title_program FROM program WHERE program_id = {self.program_id}").fetchone() + print("tit", titleProgram[0]) + nameExe = self.c.execute(f"SELECT title FROM daftar_latihan WHERE exercise_id in (SELECT exercise_id FROM latihan_program WHERE program_id = {self.program_id})").fetchall() + print(nameExe) + date = time.strftime("%Y-%m-%d", time.localtime()) + print(date) + histId = self.c.execute("SELECT DISTINCT history_id FROM riwayat_latihan").fetchall() + totDuration = time.time() - self.start + print(totDuration) + for i in range (len(self.latihan)): + print(nameExe[i][0], titleProgram[0], date, int(totDuration)) + self.c.execute(f"""INSERT INTO riwayat_latihan (history_id, program_id, name, title_program, date, calories, tot_duration) + VALUES + ({len(histId)+401}, {self.program_id}, '{nameExe[i][0]}', '{(titleProgram[0])}', '{date}', NULL, {int(totDuration)})""") + self.conn.commit() + self.switch.emit("endOfExe", {}) + + # def endButton(self): + # # historyButton = QPushButton(self) + # # historyButton.setFixedSize(100, 100) + # # historyButton.setText("End") + # # # historyButton.setIcon(QIcon("img/history.png")) + # # # historyButton.setIconSize(QPixmap("img/history.png").size()) + # # historyButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + # # historyButton.setStyleSheet(''' + # # QPushButton{ + # # border: 5px #5A8D6C; + # # } + # # QPushButton:hover { + # # background-color: #174728; + # # }''') + # # historyButton.move(1000, 500) + # # historyButton.clicked.connect(self.addHistory) + + def backToPlan(self): + self.switch.emit("plan", 0, {}) if __name__ == "__main__":