From 9f09de0e9c4e09cbe323d6c3a1d90f2fae934db4 Mon Sep 17 00:00:00 2001 From: Agsha Athalla Nurkareem <agshaathalla@gmail.com> Date: Sun, 16 Apr 2023 19:52:20 +0700 Subject: [PATCH 1/2] feat: add hover --- src/dashboard.py | 396 +++++++++++++++++++++++++++++++---------------- 1 file changed, 261 insertions(+), 135 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index bf038ff..9fb0824 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' @@ -56,17 +55,21 @@ class dashboard(QWidget): switch = pyqtSignal(str, 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.biodata = 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.con = sqlite3.connect("fitu.db") self.index_history = int(-1) self.banyaknyaKartu = int(-1) self.dashboardWindow() @@ -79,12 +82,13 @@ class dashboard(QWidget): self.label.setParent(self) self.element() - def historyElement(self, historyDate, idx): + def historyElement(self, historyIdx, idx): + self.cur = self.con.cursor() self.index_history = idx - print(self.index_history) - print("panjang historyDate: ", len(historyDate)) - tanggal = historyDate[self.index_history][0] - print(tanggal) + tanggal = 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')) @@ -97,6 +101,7 @@ class dashboard(QWidget): jumlahCard = len(daftar_latihan) self.banyaknyaKartu = jumlahCard + print(self.banyaknyaKartu) self.date = QLabel(self) self.date.setText(f"{tanggal}") @@ -108,7 +113,6 @@ class dashboard(QWidget): keterangan = cur.execute(f""" SELECT tot_duration, title_program FROM riwayat_latihan WHERE date = '{tanggal}' """).fetchone() - print(keterangan) self.duration = QLabel(self) self.duration.setText("Duration : " + str(keterangan[0]) + " minutes") self.duration.setStyleSheet(f'color: {button_color}; background-color: {card_color};') @@ -150,7 +154,6 @@ 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) @@ -166,7 +169,7 @@ class dashboard(QWidget): gambar_latihan = 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 +187,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 = 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 +212,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 +228,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 +286,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 +300,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 +320,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,29 +340,32 @@ 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)) + # # 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) @@ -328,9 +374,13 @@ 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]}!") self.hello.setStyleSheet(f'color: {text_color};') self.hello.setAlignment(Qt.AlignmentFlag.AlignLeft) @@ -351,39 +401,51 @@ class dashboard(QWidget): background-color: {button_color}; border: none; border-radius: 20px; + }} + QPushButton:hover {{ + color: #5A8D6C; + background-color: #D2DCC4; }} ''') start.setFont(buttonFont) start.setFixedSize(233, 47) #pake ini buat kalau dia buletan start.move(101, 511) start.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) - start.clicked.connect(self.planWindow) # membuat history card - historyDate = cur.execute(""" - SELECT DISTINCT strftime(date) FROM riwayat_latihan + historyIdx = cur.execute(""" + SELECT DISTINCT history_id FROM riwayat_latihan """).fetchall() # 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 = 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 = cur.execute(f""" SELECT name FROM riwayat_latihan WHERE date = '{tanggal}' """).fetchall() - print(daftar_latihan) jumlahCard = len(daftar_latihan) keterangan = cur.execute(f""" SELECT tot_duration, title_program FROM riwayat_latihan WHERE date = '{tanggal}' @@ -391,48 +453,42 @@ class dashboard(QWidget): 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""" SELECT repetition FROM daftar_latihan WHERE title = '{nama_latihan}' """).fetchone() @@ -442,7 +498,7 @@ class dashboard(QWidget): gambar_latihan = 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 +516,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 = 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,14 +527,112 @@ 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 = 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 = cur.execute(f""" + SELECT name FROM riwayat_latihan WHERE date = '{tanggal}' + """).fetchall() + jumlahCard = len(daftar_latihan) + keterangan = cur.execute(f""" + SELECT tot_duration, title_program FROM riwayat_latihan WHERE date = '{tanggal}' + """).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 = cur.execute(f""" + SELECT repetition FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone() + durasi_latihan = cur.execute(f""" + SELECT duration FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone() + gambar_latihan = 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 = 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", {}) @@ -487,38 +643,8 @@ class dashboard(QWidget): def customWindow(self): self.switch.emit("customize", {}) - 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 -- GitLab From 950ade5fbd37fa3efdd6d0d6884b1587a9d8b6aa Mon Sep 17 00:00:00 2001 From: Agsha Athalla Nurkareem <agshaathalla@gmail.com> Date: Mon, 17 Apr 2023 11:36:46 +0700 Subject: [PATCH 2/2] feat : add start button --- src/dashboard.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 9fb0824..a0400b2 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -350,23 +350,6 @@ class dashboard(QWidget): 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')) @@ -411,6 +394,7 @@ class dashboard(QWidget): start.setFixedSize(233, 47) #pake ini buat kalau dia buletan start.move(101, 511) start.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + start.clicked.connect(self.planWindow) # membuat history card historyIdx = cur.execute(""" -- GitLab