Skip to content

Commit

Permalink
Merge pull request #14 from uhrfra/master
Browse files Browse the repository at this point in the history
Little beautification on calendar view
  • Loading branch information
LukeBriggsDev committed Jan 5, 2022
2 parents b0dfe8d + 2d875c1 commit d7ec771
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/python/CalendarFileSelector.py
Expand Up @@ -154,6 +154,12 @@ def paintCell(self, painter: QtGui.QPainter, rect: QtCore.QRect, date: typing.Un
with open(get_resource("config.json")) as file:
if date.toPyDate().strftime("%Y-%m-%d") in json.loads(file.read())["favorites"]:
painter.fillRect(rect, QtGui.QColor.fromRgb(255, 255, 0))

pen = painter.pen()

if not self.file_exists(date.toPyDate()):
painter.fillRect(rect, QtGui.QColor.fromHsl(pen.color().hue(), pen.color().saturation(), pen.color().lightness(), 50))

if (date.month() != self.monthShown()):
painter.setPen(QtGui.QColor("#888888"))
elif date.dayOfWeek() == 6 or date.dayOfWeek() == 7:
Expand All @@ -163,12 +169,18 @@ def paintCell(self, painter: QtGui.QPainter, rect: QtCore.QRect, date: typing.Un
rect.adjust(0, 0, -1, -1)
pen = painter.pen()
pen.setColor(QtGui.QColor.fromHsl(pen.color().hue(), pen.color().saturation(), pen.color().lightness(), 150))
if (date == QtCore.QDate.currentDate()):
pen.setColor(QtGui.QColor.fromHsl(pen.color().hue(), pen.color().saturation(), pen.color().lightness(), 255))
rect.adjust(2, 2, -1, -1)
pen.setWidth(4)
painter.setPen(pen)
painter.drawRect(rect)
pen.setColor(QtGui.QColor.fromHsl(pen.color().hue(), pen.color().saturation(), pen.color().lightness(), 255))
painter.setPen(pen)

rect.adjust(5, 2, 0, 0)
painter.drawText(rect, QtCore.Qt.AlignmentFlag.AlignTop, str(date.day()))
rect.adjust(-5, 2, 0, 0)
text = ""
try:
for tag in tags[:5]:
Expand All @@ -189,6 +201,18 @@ def paintCell(self, painter: QtGui.QPainter, rect: QtCore.QRect, date: typing.Un
painter.drawText(rect, QtCore.Qt.AlignmentFlag.AlignBottom | QtCore.Qt.AlignmentFlag.AlignHCenter, text)
painter.restore()

def file_exists(self, date: datetime.date) -> bool:
"""Checks if a file for the given date exists"""
formatted_date = date.strftime("%Y-%m-%d")

# Get folder for today's journal entry
config_file = get_resource("config.json")
with open(config_file, "r") as file:
file_directory = os.path.join(json.loads(file.read())["diary_directory"], str(date.year),
str(date.month), formatted_date)
return os.path.exists(file_directory)


def get_tags_from_date_file(self, date: datetime.date):
"""Open or create a markdown file corresponding to today"""
formatted_date = date.strftime("%Y-%m-%d")
Expand Down

0 comments on commit d7ec771

Please sign in to comment.