how to create from month Gtk.Calendar a week calendar and display the notes in each day in python

2024/7/6 21:34:14

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.

Answer

Well I managed to display the notes according to date, changing the way of thinking the problem and starting from beginning.The new code is been added at the end of the old one, subtracting this:

            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)

The answer to the problem is the below code:

list_of_dates = list(self.d.keys())
list_of_notes = list(self.d.values())
dictionary = dict(zip(list_of_dates, list_of_notes))
for key in dictionary.items():date = datetime.date(year=key[0][0], month=key[0][1]+1, day=key[0][2])week_of_day = str(date.isocalendar()[1])            day_of_week = int(date.strftime("%w"))-1          if week == week_of_day:self.textviews[day_of_week].get_buffer().set_text(key[1])
https://en.xdnf.cn/q/119844.html

Related Q&A

How to access inner attribute class from outer class?

As title. the class set a attribute value inside inner class. then, access that inner attribute class from outer function. In below, attribute sets with inner function set_error. then, use outer functi…

Summing up the total based on the random number of inputs of a column

I need to sum up the "value" column amount for each value of col1 of the File1 and export it to an output file. Im new in python and need to do it for thousands of records.File1col1 col2 …

What is wrong with this Binomial Tree Backwards Induction European Call Option Pricing Function?

The function below works perfectly and only needs one thing: Removal of the for loop that creates the 1000 element array arr. Can you help me get rid of that for loop? Code is below #Test with europea…

Regex behaving weird when finding floating point strings [duplicate]

This question already has answers here:re.findall behaves weird(3 answers)Closed 4 years ago.So doing this (in python 3.7.3):>>> from re import findall >>> s = 7.95 + 10 pieces >&g…

how do i get this code to tell me what position a word in the sentence is

varSentence = ("The fat cat sat on the mat")print (varSentence)varWord = input("Enter word ")varSplit = varSentence.split()if varWord in varSplit:print ("Found word") else…

Reverse geocoding with Python/GoogleMaps API: How to parse response

Im attempting to use the Google Maps Geocoding API to find the State associated with a latitude and longitude with a Python script. I have no trouble getting back a response from the server, but when …

How to constantly generate random numbers inside for i in range loop

import random world_size=8 for i in range(world_size)chunk_type=random.randint(1,2)print(chunk_type)import randomclass chunk_type():chunk_type=random.randint(1,2)world_size=8for i in range(world_size):…

How to count IDs that have a given combination of flags?

I have dataframe like that. I need to choose and count all distinct users, who have title "banner_click" and "order". So I dont understand how to do it in pandas, in SQL you do like…

How to calculate quarterly wise churn and retention rate using python

How to calculate quarterly wise churn and retention rate with date column using python. with date column i want to group that quarterly using python.This is used to calculate the churn count groupby qu…

splitting a list into two lists based on a unique value

I have a text file that looks something like this:hello 12 hello 56 world 25 world 26Is there a way in python that I can somehow parse the list that I obtain from reading this data to obtain two separa…