diff --git a/src/controller.py b/src/controller.py new file mode 100644 index 0000000000000000000000000000000000000000..43b2ade880b8d67319c4ccfeb774b40323769653 --- /dev/null +++ b/src/controller.py @@ -0,0 +1,40 @@ +from PyQt6.QtWidgets import QApplication +import sys +from register import register +from dashboard import dashboard +from listLatihan import listLatihan +from tesBacaDB import tesBacaDB +class controller: + def __init__(self): + self.tesBacaDB = tesBacaDB() + self.registerWin = register() + self.registerWin.switch.connect(self.fromRegister) + self.dashboard = dashboard() + self.dashboard.switch.connect(self.fromDashboard) + self.listLatihan = listLatihan() + self.listLatihan.switch.connect(self.fromListLatihan) + pass + + def start(self): + # nanti disini kasih validasi dulu, user udah ada apa belum + self.registerWin.show() + + def fromRegister(self): + self.registerWin.close() + self.dashboard.show() + + def fromDashboard(self, page): + self.registerWin.close() + if (page == "listLatihan"): + self.listLatihan.show() + + def fromListLatihan(self, page): + self.listLatihan.close() + if (page == "dashboard"): + self.dashboard.show() + +if __name__ == "__main__": + app = QApplication(sys.argv) + controller = controller() + controller.start() + app.exec() diff --git a/src/dashboard.py b/src/dashboard.py index deea84a9742ea696f8a765f28f1df45d75437242..00bf39e700211b7d0692ea0e023d6fb26f5c2907 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -11,7 +11,7 @@ text_color = '#EEEEE2' card_color = '#D2DCC4' class dashboard(QWidget): - + switch = pyqtSignal(str, dict) def __init__(self, user=None): super().__init__() if (user == None): @@ -231,6 +231,11 @@ class dashboard(QWidget): prog.move(667, 317) prog.setFont(historyFont) prog.setAlignment(Qt.AlignmentFlag.AlignLeft) + def showRegister(self): + self.switch.emit(self, "register") + + def listLatihann(self): + self.switch.emit(self, "listLatihan") diff --git a/src/register.py b/src/register.py index d6ebef7d6cfc548ce7973eabe4d31a1608b5dc4d..13982027e676e2cdb9b52076a288a293f658b933 100644 --- a/src/register.py +++ b/src/register.py @@ -1,12 +1,13 @@ import sqlite3 from PyQt6.QtWidgets import QApplication, QLabel, QWidget, QLineEdit, QPushButton, QRadioButton, QCheckBox, QMessageBox from PyQt6.QtGui import QFont, QPixmap, QCursor -from PyQt6.QtCore import Qt +from PyQt6.QtCore import Qt, pyqtSignal import sys class register(QWidget): - + switch = pyqtSignal() def __init__(self): super().__init__() + self.conn = sqlite3.connect('fitu.db') self.setUpWindow() @@ -107,14 +108,21 @@ class register(QWidget): self.registerButton.setText("Register") self.registerButton.setFixedSize(172, 44) self.registerButton.setStyleSheet(''' - border: 1px solid rgba(255, 255, 255, 0.8); - border-radius: 20px; - color: rgba(23, 71, 40, 1); - background-color: #D2DCC4 + QPushButton { + color: rgba(23, 71, 40, 1); + background-color: #D2DCC4; + border: 1px solid rgba(255, 255, 255, 0.8); + border-radius: 20px; + } + QPushButton:hover { + background-color: #5A8D6C; + } ''') self.registerButton.move(873, 545) self.registerButton.setFont(registerText) self.registerButton.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + self.registerButton.clicked.connect(self.register) + self.fit = QCheckBox(self) self.fit.move(781, 486) @@ -131,7 +139,7 @@ class register(QWidget): self.thin.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) def register(self): - if (self.nameInput == '' or self.age == '' or self.height == '' or self.weight == '' or (not self.male and not self.female) or self.fit or self.thin): + if (self.nameInput == '' or self.age == '' or self.height == '' or self.weight == '' or (not self.male and not self.female) or self.fit == '' or self.thin == ''): msgBox = QMessageBox() msgBox.setText("<p>Please fill out the form properly!</p>") msgBox.setWindowTitle("Registration Failed") @@ -139,43 +147,66 @@ class register(QWidget): msgBox.setStyleSheet("background-color: white") msgBox.setStandardButtons(QMessageBox.StandardButton.Ok) msgBox.exec() - c = self.conn.cursor() - if (self.female): - if (self.thin): - c.execute( - f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'thin', 'female', '{self.age.text()}')" - ) - self.conn.commit() - elif (self.fit): - c.execute( - f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'fit', 'female', '{self.age.text()}')" - ) - self.conn.commit() - - else: - c.execute( - f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'fit, thin', 'female', '{self.age.text()}')" - ) - self.conn.commit() - - if (self.male): - if (self.thin): - c.execute( - f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'thin', 'male', '{self.age.text()}')" - ) - self.conn.commit() - - elif (self.fit): - c.execute( - f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'fit', 'male', '{self.age.text()}')" - ) - self.conn.commit() - - else: - c.execute( - f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'fit, thin', 'male', '{self.age.text()}')" - ) - self.conn.commit() + return + else: + c = self.conn.cursor() + if (self.female.isChecked()): + print("female") + if (self.fit.isChecked() == self.thin.isChecked()): + print("both") + c.execute( + f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'fit, thin', 'female', '{self.age.text()}')" + ) + self.conn.commit() + elif (self.thin.isChecked()): + c.execute( + f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'thin', 'female', '{self.age.text()}')" + ) + print("thin") + self.conn.commit() + elif (self.fit.isChecked()): + print("fit") + c.execute( + f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'fit', 'female', '{self.age.text()}')" + ) + self.conn.commit() + # if (self.fit and self.thin): + + + + elif(self.male.isChecked()): + print("male") + if(self.fit.isChecked() and self.thin.isChecked()): + print("both") + c.execute( + f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'fit, thin', 'male', '{self.age.text()}')" + ) + self.conn.commit() + elif (self.thin.isChecked()): + print("thin") + c.execute( + f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'thin', 'male', '{self.age.text()}')" + ) + self.conn.commit() + + elif (self.fit.isChecked()): + print("fit") + c.execute( + f"INSERT INTO user (name, height, weight, goal, gender, age) VALUES ('{self.nameInput.text()}', '{self.height.text()}', '{self.weight.text()}', 'fit', 'male', '{self.age.text()}')" + ) + self.conn.commit() + # if (self.fit and self.thin): + + + self.nameInput.clear() + self.age.clear() + self.height.clear() + self.weight.clear() + self.switch.emit() + + # def showDashboard(self): + # self.switch.emit("dashboard", {}) + if __name__ == "__main__": diff --git a/src/tesBacaDB.py b/src/tesBacaDB.py index 8a9629ba0b10314948bcbdc264c2f491e0f37649..79f3bc8ebb5decca7678ff5808cbaabbe5f8e80d 100644 --- a/src/tesBacaDB.py +++ b/src/tesBacaDB.py @@ -1,141 +1,142 @@ import sqlite3 -con = sqlite3.connect("fitu.db") -cur = con.cursor() +def tesBaca(): + con = sqlite3.connect("fitu.db") + cur = 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 text, - repetition integer, - gif text - ) - """) + 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 text, + repetition integer, + gif text + ) + """) -cur.execute(""" - CREATE TABLE IF NOT EXISTS riwayat_latihan ( - history_id integer PRIMARY KEY AUTOINCREMENT, - program_id integer, - name text, - title_program text, - calories integer, - date text, - tot_duration integer - ) - """) -cur.execute(""" - CREATE TABLE IF NOT EXISTS program ( - program_id integer PRIMARY KEY AUTOINCREMENT, - title_program text - ) - """) + cur.execute(""" + CREATE TABLE IF NOT EXISTS riwayat_latihan ( + history_id integer PRIMARY KEY AUTOINCREMENT, + program_id integer, + name text, + title_program text, + calories integer, + date text, + tot_duration integer + ) + """) + 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(""" + 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 - (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/push-up.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/"), - (203, "Pull 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/"), - (204, "Squat Jump", "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/"), - (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/"), - (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/"), - (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/"), - (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/"), - (101, "Jumping Rope", "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/"), - (102, "Running", "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/"), - (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/"), - (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/"), - (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/"), - (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/"), - (107, "Squat", "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/"), - (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/") - """) + cur.execute(""" + INSERT or IGNORE INTO daftar_latihan + (exercise_id, title, description, goals, duration, repetition, gif) + VALUES + (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/push-up.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/"), + (203, "Pull 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/"), + (204, "Squat Jump", "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/"), + (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/"), + (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/"), + (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/"), + (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/"), + (101, "Jumping Rope", "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/"), + (102, "Running", "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/"), + (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/"), + (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/"), + (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/"), + (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/"), + (107, "Squat", "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/"), + (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/") + """) -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 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, 202), - (1, 203), - (1, 204), - (1, 205), - (1, 206), - (2, 207), - (2, 208), - (2, 201), - (2, 202), - (2, 203), - (2, 204), - (3, 205), - (3, 206), - (3, 207), - (3, 208), - (3, 201), - (3, 202), - (4, 203), - (4, 204), - (4, 205), - (4, 206), - (4, 207), - (4, 208) - """) + cur.execute(""" + INSERT or IGNORE INTO latihan_program + (program_id, exercise_id) + VALUES + (1, 201), + (1, 202), + (1, 203), + (1, 204), + (1, 205), + (1, 206), + (2, 207), + (2, 208), + (2, 201), + (2, 202), + (2, 203), + (2, 204), + (3, 205), + (3, 206), + (3, 207), + (3, 208), + (3, 201), + (3, 202), + (4, 203), + (4, 204), + (4, 205), + (4, 206), + (4, 207), + (4, 208) + """) -con.commit() -con.close() -# cur.execute(""" -# INSERT INTO daftar_request -# (user_id, trainer_id, umur, jenis_kelamin, berat_badan, tinggi_badan, tujuan, status, title, description) -# VALUES -# (1, 2, 20, 'Laki-laki', 65, 170, 'I want to have a sixpack stomach', True, 'Chest Day', 'This workout plan is made to strengthen your \nabdominal muscles.'), -# (1,2,20, 'Laki-laki', 65, 170, 'I want to have a strong leg muscles', True, 'Leg Day', 'This workout plan is made to strengthen your \nleg muscles.') -# """) -# cur.execute(""" -# INSERT INTO workout -# (request_id, olahraga_id, status) -# VALUES -# (1, 2, False), -# (1, 3, False), -# (1, 6, False), -# (2, 4, False), -# (2, 7, False) -# """) + con.commit() + con.close() + # cur.execute(""" + # INSERT INTO daftar_request + # (user_id, trainer_id, umur, jenis_kelamin, berat_badan, tinggi_badan, tujuan, status, title, description) + # VALUES + # (1, 2, 20, 'Laki-laki', 65, 170, 'I want to have a sixpack stomach', True, 'Chest Day', 'This workout plan is made to strengthen your \nabdominal muscles.'), + # (1,2,20, 'Laki-laki', 65, 170, 'I want to have a strong leg muscles', True, 'Leg Day', 'This workout plan is made to strengthen your \nleg muscles.') + # """) + # cur.execute(""" + # INSERT INTO workout + # (request_id, olahraga_id, status) + # VALUES + # (1, 2, False), + # (1, 3, False), + # (1, 6, False), + # (2, 4, False), + # (2, 7, False) + # """) -# daftarLatihan = cur.execute("SELECT * FROM daftar_latihan") -# daftarLatihan = daftarLatihan.fetchall() + # daftarLatihan = cur.execute("SELECT * FROM daftar_latihan") + # daftarLatihan = daftarLatihan.fetchall() -# for i in daftarLatihan: -# print(i) \ No newline at end of file + # for i in daftarLatihan: + # print(i) \ No newline at end of file