update calendar to auto remove notification dot upon deletion

This commit is contained in:
WorldTeacher
2024-06-13 09:34:23 +02:00
parent 88fae1a5ec
commit 45b611fe83
2 changed files with 30 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ from src.backend.database import Database
from PyQt6.QtCore import QDate
from PyQt6.QtGui import QColor, QPen
import darkdetect
from icecream import ic
color = "#ddfb00" if darkdetect.isDark() else "#2204ff"
pen = QPen(QColor(color))
@@ -21,9 +22,17 @@ class MessageCalendar(QtWidgets.QCalendarWidget):
def getMessages(self):
# Get the messages from the database
messages = Database().getAllMessages()
ic(messages)
self.setMessages(messages)
def deleteMessage(self, id):
message = [message for message in self.messages if message["id"] == id][0]
self.messages.remove(message)
self.updateCells()
def setMessages(self, messages):
# remove all drawn circles
for message in messages:
print(message)
# Convert the date string to a QDate object
@@ -47,6 +56,20 @@ class MessageCalendar(QtWidgets.QCalendarWidget):
bl.setX(bl.x() + 8)
bl.setY(bl.y() - 8)
painter.drawEllipse(bl, 5, 5)
else:
for cell in self.messages:
if cell.month() == date.month() and cell.year() == date.year():
# draw a circle below the date
painter.setPen(QPen(QtCore.Qt.GlobalColor.transparent))
bl = rect.bottomLeft()
bl.setX(bl.x() + 8)
bl.setY(bl.y() - 8)
painter.drawEllipse(bl, 5, 5)
def reload(self, date):
qdate = QDate.fromString(date, "yyyy-MM-dd")
del self.messages[qdate]
self.updateCells()
# def change_stylesheet_cell(self, date: QDate, color: str):
# # change the stylesheet of a cell