calendar widget / notification box
This commit is contained in:
55
src/ui/widgets/MessageCalendar.py
Normal file
55
src/ui/widgets/MessageCalendar.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
from PyQt6 import QtWidgets, QtCore
|
||||||
|
from src.backend.database import Database
|
||||||
|
from PyQt6.QtCore import QDate
|
||||||
|
from PyQt6.QtGui import QColor, QPen
|
||||||
|
import darkdetect
|
||||||
|
|
||||||
|
color = "#ddfb00" if darkdetect.isDark() else "#2204ff"
|
||||||
|
pen = QPen(QColor(color))
|
||||||
|
pen.setWidth(5)
|
||||||
|
|
||||||
|
|
||||||
|
class MessageCalendar(QtWidgets.QCalendarWidget):
|
||||||
|
# Widget for MessageCalendar
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.messages = {} # Dictionary to store dates with messages
|
||||||
|
self.setFirstDayOfWeek(QtCore.Qt.DayOfWeek.Monday)
|
||||||
|
self.setGridVisible(True)
|
||||||
|
self.getMessages()
|
||||||
|
|
||||||
|
def getMessages(self):
|
||||||
|
# Get the messages from the database
|
||||||
|
messages = Database().getAllMessages()
|
||||||
|
self.setMessages(messages)
|
||||||
|
|
||||||
|
def setMessages(self, messages):
|
||||||
|
for message in messages:
|
||||||
|
print(message)
|
||||||
|
# Convert the date string to a QDate object
|
||||||
|
date = QDate.fromString(message["remind_at"], "yyyy-MM-dd")
|
||||||
|
# Store the message for the date
|
||||||
|
self.messages[date] = message["message"]
|
||||||
|
self.updateCells()
|
||||||
|
|
||||||
|
def updateCells(self):
|
||||||
|
self.repaint()
|
||||||
|
|
||||||
|
def paintCell(self, painter, rect, date):
|
||||||
|
super().paintCell(painter, rect, date)
|
||||||
|
|
||||||
|
# Check if there is a message for the current date
|
||||||
|
if date in self.messages:
|
||||||
|
# draw a circle below the date
|
||||||
|
painter.setPen(pen)
|
||||||
|
# increase draw size
|
||||||
|
bl = rect.bottomLeft()
|
||||||
|
bl.setX(bl.x() + 8)
|
||||||
|
bl.setY(bl.y() - 8)
|
||||||
|
painter.drawEllipse(bl, 5, 5)
|
||||||
|
|
||||||
|
# def change_stylesheet_cell(self, date: QDate, color: str):
|
||||||
|
# # change the stylesheet of a cell
|
||||||
|
# self.setStyleSheet(
|
||||||
|
# f"QCalendarWidget QTableView QTableCornerButton::section {{background-color: {color};}}"
|
||||||
|
# )
|
||||||
76
src/ui/widgets/calendar_entry.py
Normal file
76
src/ui/widgets/calendar_entry.py
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
from .widget_sources.Ui_calendar_entry import Ui_Dialog
|
||||||
|
from PyQt6 import QtWidgets, QtCore
|
||||||
|
from PyQt6.QtCore import pyqtSignal
|
||||||
|
from src.backend.database import Database
|
||||||
|
from src import Icon
|
||||||
|
|
||||||
|
|
||||||
|
class CalendarEntry(QtWidgets.QDialog, Ui_Dialog):
|
||||||
|
deleteSignal = pyqtSignal(
|
||||||
|
int
|
||||||
|
) # when emit, send the id of the message to be deleted
|
||||||
|
repaintSignal = pyqtSignal()
|
||||||
|
|
||||||
|
def __init__(self, parent=None, messages=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.setupUi(self)
|
||||||
|
self.messages = messages
|
||||||
|
self.spin_select_message.setMaximum(len(self.messages))
|
||||||
|
self.spin_select_message.setMinimum(1)
|
||||||
|
self.spin_select_message.setValue(1)
|
||||||
|
print(self.messages)
|
||||||
|
self.set_message()
|
||||||
|
self.spin_select_message.valueChanged.connect(self.set_message)
|
||||||
|
Icon("close", self.btn_close)
|
||||||
|
self.btn_delete_message.clicked.connect(self.delete_message)
|
||||||
|
self.btn_close.clicked.connect(self.close)
|
||||||
|
|
||||||
|
def __get_id(self, message):
|
||||||
|
for i in range(len(self.messages)):
|
||||||
|
if self.messages[i] == message:
|
||||||
|
return self.messages[i]["id"]
|
||||||
|
|
||||||
|
def delete_message(self):
|
||||||
|
value = self.spin_select_message.value()
|
||||||
|
if value > 0:
|
||||||
|
value = value - 1
|
||||||
|
message = self.messages[value]
|
||||||
|
|
||||||
|
id = self.__get_id(message)
|
||||||
|
print("id", id)
|
||||||
|
del self.messages[value - 1]
|
||||||
|
self.spin_select_message.setMaximum(len(self.messages))
|
||||||
|
self.message_box.clear()
|
||||||
|
if value > 0:
|
||||||
|
self.set_message()
|
||||||
|
self.deleteSignal.emit(id)
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
#
|
||||||
|
self.repaintSignal.emit()
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
def set_message(self):
|
||||||
|
value = self.spin_select_message.value()
|
||||||
|
if value < 1:
|
||||||
|
return
|
||||||
|
message = self.messages[value - 1]
|
||||||
|
appnr = message["appnr"]
|
||||||
|
text = message["message"]
|
||||||
|
if appnr is not None:
|
||||||
|
self.line_app_info.setText(str(appnr))
|
||||||
|
else:
|
||||||
|
self.line_app_info.setText("/")
|
||||||
|
self.message_box.setText(text)
|
||||||
|
self.message_box.repaint()
|
||||||
|
|
||||||
|
|
||||||
|
def launch_calendar_entry():
|
||||||
|
|
||||||
|
messages = Database().getMessages("2024-06-10")
|
||||||
|
|
||||||
|
app = QtWidgets.QApplication([])
|
||||||
|
dialog = CalendarEntry(messages=messages)
|
||||||
|
dialog.show()
|
||||||
|
app.exec()
|
||||||
70
src/ui/widgets/widget_sources/Ui_calendar_entry.py
Normal file
70
src/ui/widgets/widget_sources/Ui_calendar_entry.py
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
# Form implementation generated from reading ui file 'c:\Users\aky547\GitHub\SemesterapparatsManager\src\ui\dialogs\dialog_sources\calendar_entry.ui'
|
||||||
|
#
|
||||||
|
# Created by: PyQt6 UI code generator 6.6.1
|
||||||
|
#
|
||||||
|
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
||||||
|
# run again. Do not edit this file unless you know what you are doing.
|
||||||
|
|
||||||
|
|
||||||
|
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
|
|
||||||
|
class Ui_Dialog(object):
|
||||||
|
def setupUi(self, Dialog):
|
||||||
|
Dialog.setObjectName("Dialog")
|
||||||
|
Dialog.resize(400, 300)
|
||||||
|
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
|
||||||
|
self.verticalLayout.setObjectName("verticalLayout")
|
||||||
|
self.horizontalLayout = QtWidgets.QHBoxLayout()
|
||||||
|
self.horizontalLayout.setObjectName("horizontalLayout")
|
||||||
|
self.label_14 = QtWidgets.QLabel(parent=Dialog)
|
||||||
|
self.label_14.setObjectName("label_14")
|
||||||
|
self.horizontalLayout.addWidget(self.label_14)
|
||||||
|
self.line_app_info = QtWidgets.QLineEdit(parent=Dialog)
|
||||||
|
self.line_app_info.setEnabled(True)
|
||||||
|
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Fixed)
|
||||||
|
sizePolicy.setHorizontalStretch(0)
|
||||||
|
sizePolicy.setVerticalStretch(0)
|
||||||
|
sizePolicy.setHeightForWidth(self.line_app_info.sizePolicy().hasHeightForWidth())
|
||||||
|
self.line_app_info.setSizePolicy(sizePolicy)
|
||||||
|
self.line_app_info.setMaximumSize(QtCore.QSize(30, 16777215))
|
||||||
|
self.line_app_info.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
|
||||||
|
self.line_app_info.setInputMask("")
|
||||||
|
self.line_app_info.setMaxLength(3)
|
||||||
|
self.line_app_info.setObjectName("line_app_info")
|
||||||
|
self.horizontalLayout.addWidget(self.line_app_info)
|
||||||
|
self.btn_delete_message = QtWidgets.QPushButton(parent=Dialog)
|
||||||
|
self.btn_delete_message.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
|
||||||
|
self.btn_delete_message.setObjectName("btn_delete_message")
|
||||||
|
self.horizontalLayout.addWidget(self.btn_delete_message)
|
||||||
|
self.spin_select_message = QtWidgets.QSpinBox(parent=Dialog)
|
||||||
|
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Fixed)
|
||||||
|
sizePolicy.setHorizontalStretch(0)
|
||||||
|
sizePolicy.setVerticalStretch(0)
|
||||||
|
sizePolicy.setHeightForWidth(self.spin_select_message.sizePolicy().hasHeightForWidth())
|
||||||
|
self.spin_select_message.setSizePolicy(sizePolicy)
|
||||||
|
self.spin_select_message.setMaximumSize(QtCore.QSize(500, 16777215))
|
||||||
|
self.spin_select_message.setMinimum(1)
|
||||||
|
self.spin_select_message.setObjectName("spin_select_message")
|
||||||
|
self.horizontalLayout.addWidget(self.spin_select_message)
|
||||||
|
self.btn_close = QtWidgets.QToolButton(parent=Dialog)
|
||||||
|
self.btn_close.setText("")
|
||||||
|
self.btn_close.setIconSize(QtCore.QSize(20, 20))
|
||||||
|
self.btn_close.setAutoRaise(False)
|
||||||
|
self.btn_close.setObjectName("btn_close")
|
||||||
|
self.horizontalLayout.addWidget(self.btn_close)
|
||||||
|
self.verticalLayout.addLayout(self.horizontalLayout)
|
||||||
|
self.message_box = QtWidgets.QTextEdit(parent=Dialog)
|
||||||
|
self.message_box.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
|
||||||
|
self.message_box.setObjectName("message_box")
|
||||||
|
self.verticalLayout.addWidget(self.message_box)
|
||||||
|
|
||||||
|
self.retranslateUi(Dialog)
|
||||||
|
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||||||
|
|
||||||
|
def retranslateUi(self, Dialog):
|
||||||
|
_translate = QtCore.QCoreApplication.translate
|
||||||
|
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
|
||||||
|
self.label_14.setText(_translate("Dialog", "Apparat"))
|
||||||
|
self.line_app_info.setText(_translate("Dialog", "200"))
|
||||||
|
self.btn_delete_message.setText(_translate("Dialog", "Löschen"))
|
||||||
115
src/ui/widgets/widget_sources/calendar_entry.ui
Normal file
115
src/ui/widgets/widget_sources/calendar_entry.ui
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_14">
|
||||||
|
<property name="text">
|
||||||
|
<string>Apparat</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="line_app_info">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>30</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="inputMask">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>200</string>
|
||||||
|
</property>
|
||||||
|
<property name="maxLength">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_delete_message">
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Löschen</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="spin_select_message">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>500</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="btn_close">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTextEdit" name="message_box">
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user