d0db0d687f
added calcure to the repo too, this one i'll probably move to nix-garden
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
from tkinter import *
|
|
from tkinter import ttk
|
|
from pydantic import ValidationError
|
|
from tkcalendar import Calendar
|
|
from datetime import datetime
|
|
from os import listdir
|
|
from ical.calendar_stream import IcsCalendarStream
|
|
|
|
# Later on...
|
|
# Import all ICS events into Tkinter Events
|
|
# for e in c.events:
|
|
# print(e.name)
|
|
|
|
### TKINTER Setup
|
|
|
|
root = Tk()
|
|
root.geometry("+0+0") # TODO set location of tkinter dialog
|
|
root.attributes("-type", "dialog")
|
|
|
|
style = ttk.Style(root)
|
|
style.theme_use("clam")
|
|
|
|
frame = ttk.Frame(root)
|
|
frame.grid()
|
|
|
|
calendar = Calendar(frame)
|
|
calendar.grid(row=0,columnspan=7)
|
|
calendar.calevent_create(date=datetime(2022, 12, 16), text="today")
|
|
|
|
### ICS setup
|
|
|
|
# List calendar folder (~/.calendar/)
|
|
calendar_folder = '/home/anish/.calendar/'
|
|
# Recurse through each folder
|
|
for c in listdir(calendar_folder):
|
|
files = listdir(calendar_folder + c)
|
|
full_text: str = ""
|
|
for file in files:
|
|
try:
|
|
with open(calendar_folder + c + "/" + file, 'r') as in_file:
|
|
cal = IcsCalendarStream.calendar_from_ics(in_file.read())
|
|
for e in cal.events:
|
|
calendar.calevent_create(date=e.dtstart, text=e.summary)
|
|
except ValidationError:
|
|
print(f"Could not parse file: {calendar_folder}{c}")
|
|
|
|
agenda_var = StringVar()
|
|
agenda_var.set("")
|
|
|
|
def update_agenda(_):
|
|
date = calendar.selection_get()
|
|
new_agenda = calendar.get_calevents(date)
|
|
if new_agenda:
|
|
new_agenda = calendar.calevent_cget(new_agenda[0], "text") # TODO list *all* events
|
|
agenda_var.set(new_agenda)
|
|
root.update_idletasks()
|
|
else:
|
|
agenda_var.set("")
|
|
|
|
agenda_label = ttk.Label(frame, textvariable=agenda_var)
|
|
agenda_label.grid(rowspan=13, columnspan=7) # TODO make agenda bigger to accomodate multiple events
|
|
|
|
update_agenda("") # initial set of agenda
|
|
root.bind("<<CalendarSelected>>", update_agenda)
|
|
|
|
root.mainloop()
|