Skip to content

Commit

Permalink
feat(widget/clock): enhance calendar widget with improved date handli…
Browse files Browse the repository at this point in the history
…ng and rendering
  • Loading branch information
amnweb committed Jan 25, 2025
1 parent bfb00ac commit 1b8b3ba
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/core/widgets/yasb/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def __init__(self, parent=None, timezone=None):
self.setLocale(qt_locale)

self.update_calendar_display()

def paintCell(self, painter, rect, date):
if date < self.minimumDate() or date > self.maximumDate():
return # Skip drawing
super().paintCell(painter, rect, date)
def update_calendar_display(self):
if self.timezone:
datetime_now = datetime.now(pytz.timezone(self.timezone))
Expand Down Expand Up @@ -180,15 +183,17 @@ def _next_timezone(self):
self.setToolTip(self._active_tz)
self._update_label()




def update_month_label(self, year, month):
qlocale = QLocale(self._locale) if self._locale else QLocale.system()
new_month = qlocale.monthName(month)
new_day = qlocale.dayName(QDate(year, month, 1).dayOfWeek())

self.day_label.setText(new_day)
self.month_label.setText(new_month)
# Update day and date based on the calendar’s selected day
selectedDate = self.calendar.selectedDate()
newDate = QDate(year, month, selectedDate.day())
self.day_label.setText(qlocale.dayName(newDate.dayOfWeek()))
self.date_label.setText(newDate.toString("d"))


def update_selected_date(self, date: QDate):
qlocale = QLocale(self._locale) if self._locale else QLocale.system()
Expand All @@ -198,7 +203,6 @@ def update_selected_date(self, date: QDate):


def show_calendar(self):
# Create popup widget
self._yasb_calendar = PopupWidget(self, self._calendar['blur'], self._calendar['round_corners'],
self._calendar['round_corners_type'], self._calendar['border_color'])
self._yasb_calendar.setProperty('class', 'calendar')
Expand Down

0 comments on commit 1b8b3ba

Please sign in to comment.