the calendar works but looks fucking ugly
added calcure to the repo too, this one i'll probably move to nix-garden
This commit is contained in:
parent
5543b927d3
commit
d0db0d687f
66
flake.nix
66
flake.nix
|
@ -4,15 +4,81 @@
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||||
my-python = pkgs.python3;
|
my-python = pkgs.python3;
|
||||||
|
tkcalendar = pkgs.python3Packages.buildPythonPackage rec {
|
||||||
|
pname = "tkcalendar";
|
||||||
|
version = "1.6.1";
|
||||||
|
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "j4321";
|
||||||
|
repo = "tkcalendar";
|
||||||
|
rev = "v${version}";
|
||||||
|
sha256 = "Z5Sg1kT9VS0WNyJ3nXXhKbzL1VEXwkbF4bV8OwprYfE=";
|
||||||
|
};
|
||||||
|
|
||||||
|
propagatedBuildInputs = [
|
||||||
|
pkgs.python310Packages.tkinter
|
||||||
|
pkgs.python310Packages.babel
|
||||||
|
];
|
||||||
|
|
||||||
|
doCheck = false;
|
||||||
|
pythonImportsCheck = [ "tkcalendar" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
calcure = pkgs.python3Packages.buildPythonApplication rec {
|
||||||
|
pname = "calcure";
|
||||||
|
version = "2.6";
|
||||||
|
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "anufrievroman";
|
||||||
|
repo = "calcure";
|
||||||
|
rev = "${version}";
|
||||||
|
sha256 = "VvK8kLQd8JKaLQoxtMbweOKnR9nKMEnlj0103DeLXRI=";
|
||||||
|
};
|
||||||
|
|
||||||
|
propagatedBuildInputs = [
|
||||||
|
pkgs.python310Packages.holidays
|
||||||
|
pkgs.python310Packages.jdatetime
|
||||||
|
];
|
||||||
|
|
||||||
|
# doCheck = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
ttkbootstrap = pkgs.python3Packages.buildPythonPackage rec {
|
||||||
|
pname = "ttkbootstrap";
|
||||||
|
version = "1.10.0";
|
||||||
|
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "israel-dryer";
|
||||||
|
repo = "ttkbootstrap";
|
||||||
|
rev = "v${version}";
|
||||||
|
sha256 = "tWzpgNv54uuB9hntO/iek6zrH4RWk9MrREXdwpDRDPw=";
|
||||||
|
};
|
||||||
|
|
||||||
|
propagatedBuildInputs = [
|
||||||
|
pkgs.python310Packages.pillow
|
||||||
|
pkgs.python310Packages.tkinter
|
||||||
|
];
|
||||||
|
|
||||||
|
# doCheck = false;
|
||||||
|
pythonImportsCheck = [ "ttkbootstrap" ];
|
||||||
|
};
|
||||||
|
|
||||||
python-with-my-packages = my-python.withPackages (p: with p; [
|
python-with-my-packages = my-python.withPackages (p: with p; [
|
||||||
tkinter
|
tkinter
|
||||||
|
tkcalendar
|
||||||
|
ttkbootstrap
|
||||||
|
ical
|
||||||
]);
|
]);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
packages.tkcalendar = pkgs.callPackage tkcalendar { };
|
||||||
|
packages.ttkbootsrap = pkgs.callPackage ttkbootstrap { };
|
||||||
|
packages.calcure = pkgs.callPackage calcure { };
|
||||||
devShell.x86_64-linux = pkgs.mkShell {
|
devShell.x86_64-linux = pkgs.mkShell {
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
yad
|
yad
|
||||||
python-with-my-packages
|
python-with-my-packages
|
||||||
|
calcure
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,54 +1,66 @@
|
||||||
from tkinter import *
|
from tkinter import *
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
import sys
|
from pydantic import ValidationError
|
||||||
import subprocess
|
from tkcalendar import Calendar
|
||||||
|
from datetime import datetime
|
||||||
|
from os import listdir
|
||||||
|
from ical.calendar_stream import IcsCalendarStream
|
||||||
|
|
||||||
calendar = subprocess.check_output(["cal", "-m"])
|
# Later on...
|
||||||
calendar = calendar.decode("utf-8")
|
# Import all ICS events into Tkinter Events
|
||||||
calendar = calendar.split("\n")
|
# for e in c.events:
|
||||||
calendar = [x.split() for x in calendar]
|
# print(e.name)
|
||||||
|
|
||||||
today = subprocess.check_output(["date", "+\"%d\""])
|
### TKINTER Setup
|
||||||
today = today.decode("utf-8")[:-1]
|
|
||||||
today = today.strip("\"")
|
|
||||||
|
|
||||||
month_year = calendar[0]
|
|
||||||
calendar_fields = [calendar[1], calendar[2], calendar[3], calendar[4], calendar[5], calendar[6]]
|
|
||||||
|
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.geometry("+0+0")
|
root.geometry("+0+0") # TODO set location of tkinter dialog
|
||||||
root.attributes("-type", "dialog")
|
root.attributes("-type", "dialog")
|
||||||
|
|
||||||
|
style = ttk.Style(root)
|
||||||
|
style.theme_use("clam")
|
||||||
|
|
||||||
frame = ttk.Frame(root)
|
frame = ttk.Frame(root)
|
||||||
frame.grid()
|
frame.grid()
|
||||||
|
|
||||||
date_label = ttk.Label(frame, text=" ".join(month_year)).grid(row=0, columnspan=7)
|
calendar = Calendar(frame)
|
||||||
prev_month_button = ttk.Button(frame, text="<", command=exit, width=1).grid(row=0, column=0)
|
calendar.grid(row=0,columnspan=7)
|
||||||
next_month_button = ttk.Button(frame, text=">", command=exit, width=1).grid(row=0, column=6)
|
calendar.calevent_create(date=datetime(2022, 12, 16), text="today")
|
||||||
|
|
||||||
def get_agenda(date):
|
### ICS setup
|
||||||
date = "2022-12-" + date
|
|
||||||
agenda = subprocess.check_output(["khal", "list", date, date])
|
|
||||||
agenda = agenda.decode("utf-8")[:-1]
|
|
||||||
agenda = agenda.split("\n")[1]
|
|
||||||
return agenda
|
|
||||||
|
|
||||||
|
# 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}")
|
||||||
|
|
||||||
row_count = 1
|
agenda_var = StringVar()
|
||||||
column_count = 0
|
agenda_var.set("")
|
||||||
for r in calendar_fields:
|
|
||||||
for c in r:
|
def update_agenda(_):
|
||||||
if c == today:
|
date = calendar.selection_get()
|
||||||
label = ttk.Label(frame, text=c, background="green").grid(row=row_count, column=column_count)
|
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:
|
else:
|
||||||
label = ttk.Label(frame, text=c).grid(row=row_count, column=column_count)
|
agenda_var.set("")
|
||||||
column_count += 1
|
|
||||||
column_count = 0
|
|
||||||
row_count += 1
|
|
||||||
|
|
||||||
agenda_label = ttk.Label(frame, text=get_agenda(today)).grid(row=row_count+1, columnspan=7)
|
agenda_label = ttk.Label(frame, textvariable=agenda_var)
|
||||||
|
agenda_label.grid(rowspan=13, columnspan=7) # TODO make agenda bigger to accomodate multiple events
|
||||||
|
|
||||||
def exit():
|
update_agenda("") # initial set of agenda
|
||||||
sys.exit()
|
root.bind("<<CalendarSelected>>", update_agenda)
|
||||||
|
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
Loading…
Reference in a new issue