I have created a calendar app with month and week view in python. In month view, I can write notes in each day, store them in a dictionary and save the dictionary in to disk so I can read it any time.
Now I am working on week view.I managed to display the week of the month regard the day I have picked from month view (the number of the week and the days, Monday to Sunday).In code, I used Gtk.Label
for the number of the week and the days of the week attached them in a Gtk.Grid
. Beneath each day I have attached a Gtk.TextView
using a for in
loop creating a list of Gtk.TextView
where is being displayed the notes of each day from month view.Right now I have managed to display only one note each time I pick a day of a week.If I have multiple notes in different days can not display all of them.And here is my question.
Below is a snippet of code where the week calendar is updating(def update_week_cal
).How to modify the code in loop part, so I can display all the notes in each week I have picked from month view?
def update_week_cal(self, *args):year, month, day = self.calendar.get_date()month = month + 1today = datetime.date(year, month, day)self.page2.remove(self.label)self.label = Gtk.Label(str(today.isocalendar()[1]) + "η Εβδομάδα")self.page2.attach(self.label, 3, 1, 1, 1)dates = list([today + datetime.timedelta(days=i) for i in range(0 - today.weekday(), 7 - today.weekday())])j = 0for days in dates:self.labels[j].destroy()if days == today:self.labels[j] = Gtk.Label()self.labels[j].set_markup('<span font = "12" weight = "bold">{0}</span>'.format(days.strftime("%a ""%d/""%m")))else:self.labels[j] = Gtk.Label(days.strftime("%a ""%d/""%m"))self.page2.attach(self.labels[j], j, 2, 1, 1)self.page2.remove(self.textviews[j])self.textviews[j] = Gtk.TextView()self.textviews[j].set_editable(False)self.textviews[j].set_wrap_mode(Gtk.WrapMode.WORD_CHAR)self.page2.attach(self.textviews[j], j, 3, 1, 1)for i in range(7):try:if self.text is not None and self.d[(year, month, day)]:x = int(today.strftime("%w"))-1self.textviews[x].get_buffer().set_text(self.text)except KeyError:x = int(today.strftime("%w")) - 1self.textviews[x].get_buffer().set_text(self.text)print(i, j, x)except TypeError:x = int(today.strftime("%w")) - 1self.textviews[x].get_buffer().set_text(self.text)self.show_all()j = j + 1
Take into account that I have used the same Gtk.TextBuffer
for month and week view.
self.text
are the notes from month view.
Thanks in advance.