This commit is contained in:
Anish Lakhwara 2022-12-16 00:31:04 +10:00
commit 5543b927d3
5 changed files with 195 additions and 0 deletions

26
flake.lock Normal file
View file

@ -0,0 +1,26 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1670918062,
"narHash": "sha256-iOhkyBYUU9Jfkk0lvI4ahpjyrTsLXj9uyJWwmjKg+gg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "84575b0bd882be979516f4fecfe4d7c8de8f6a92",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

19
flake.nix Normal file
View file

@ -0,0 +1,19 @@
{
inputs.nixpkgs.url = "github:nixos/nixpkgs";
outputs = { self, nixpkgs }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
my-python = pkgs.python3;
python-with-my-packages = my-python.withPackages (p: with p; [
tkinter
]);
in
{
devShell.x86_64-linux = pkgs.mkShell {
buildInputs = with pkgs; [
yad
python-with-my-packages
];
};
};
}

41
popup-calendar.sh Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env bash
BAR_HEIGHT=22 # polybar height
BORDER_SIZE=1 # border size from your wm settings
YAD_WIDTH=222 # 222 is minimum possible value
YAD_HEIGHT=193 # 193 is minimum possible value
DATE="$(date +"%a %d %H:%M")"
case "$1" in
--popup)
if [ "$(xdotool getwindowfocus getwindowname)" = "yad-calendar" ]; then
exit 0
fi
eval "$(xdotool getmouselocation --shell)"
eval "$(xdotool getdisplaygeometry --shell)"
# X
if [ "$((X + YAD_WIDTH / 2 + BORDER_SIZE))" -gt "$WIDTH" ]; then #Right side
: $((pos_x = WIDTH - YAD_WIDTH - BORDER_SIZE))
elif [ "$((X - YAD_WIDTH / 2 - BORDER_SIZE))" -lt 0 ]; then #Left side
: $((pos_x = BORDER_SIZE))
else #Center
: $((pos_x = X - YAD_WIDTH / 2))
fi
# Y
if [ "$Y" -gt "$((HEIGHT / 2))" ]; then #Bottom
: $((pos_y = HEIGHT - YAD_HEIGHT - BAR_HEIGHT - BORDER_SIZE))
else #Top
: $((pos_y = BAR_HEIGHT + BORDER_SIZE))
fi
yad --calendar --undecorated --fixed --close-on-unfocus --no-buttons \
--width="$YAD_WIDTH" --height="$YAD_HEIGHT" --posx="$pos_x" --posy="$pos_y" \
--title="yad-calendar" --borders=0 >/dev/null &
;;
*)
echo "$DATE"
;;
esac

55
tk-test.py Normal file
View file

@ -0,0 +1,55 @@
from tkinter import Tk, Frame, Label, Button
import sys
import subprocess
LIGHT_BROWN_COLOR = "#ebdbb2" # Gruvbox color
window_width = 200
window_height = 150
calendar = subprocess.check_output(["cal", "-m"])
calendar = calendar.decode("utf-8")
calendar = calendar.split("\n")
calendar = [x.split() for x in calendar]
today = subprocess.check_output(["date", "+\"%d\""])
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]]
WINDOW_SIZE_POSITION = str(window_width) + "x" + str(window_height) + "+" + str(900 - int(window_width / 2)) + "+" + str(1820)
root = Tk()
# root.overrideredirect(True)
root.geometry(WINDOW_SIZE_POSITION)
root.attributes("-type", "dialog")
date_label = Label(root, text=month_year, fg=LIGHT_BROWN_COLOR)
date_label.pack(side="top")
frame = Frame(root)
frame.pack()
row_count = 0
column_count = 0
for r in calendar_fields:
for c in r:
if c == today:
label = Label(frame, text=c, bg=LIGHT_BROWN_COLOR, fg="black")
label.grid(row=row_count, column=column_count)
else:
label = Label(frame, text=c, fg=LIGHT_BROWN_COLOR)
label.grid(row=row_count, column=column_count)
column_count += 1
column_count = 0
row_count += 1
def exit():
sys.exit()
exit_button = Button(root, text="X", command=exit, activebackground=LIGHT_BROWN_COLOR, highlightthickness=0, highlightbackground=LIGHT_BROWN_COLOR, highlightcolor=LIGHT_BROWN_COLOR)
exit_button.pack()
root.mainloop()

View file

@ -0,0 +1,54 @@
from tkinter import *
from tkinter import ttk
import sys
import subprocess
calendar = subprocess.check_output(["cal", "-m"])
calendar = calendar.decode("utf-8")
calendar = calendar.split("\n")
calendar = [x.split() for x in calendar]
today = subprocess.check_output(["date", "+\"%d\""])
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.geometry("+0+0")
root.attributes("-type", "dialog")
frame = ttk.Frame(root)
frame.grid()
date_label = ttk.Label(frame, text=" ".join(month_year)).grid(row=0, columnspan=7)
prev_month_button = ttk.Button(frame, text="<", command=exit, width=1).grid(row=0, column=0)
next_month_button = ttk.Button(frame, text=">", command=exit, width=1).grid(row=0, column=6)
def get_agenda(date):
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
row_count = 1
column_count = 0
for r in calendar_fields:
for c in r:
if c == today:
label = ttk.Label(frame, text=c, background="green").grid(row=row_count, column=column_count)
else:
label = ttk.Label(frame, text=c).grid(row=row_count, column=column_count)
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)
def exit():
sys.exit()
root.mainloop()