some reformatiing, uv setup, removed i3 special case

This commit is contained in:
2026-06-19 11:13:02 +02:00
parent a1f58829a6
commit d7c74c9b47
6 changed files with 77 additions and 40 deletions
+22 -25
View File
@@ -3,11 +3,10 @@ import datetime
from tkinter import Tk, CENTER, Label
import click
import typing as t
import os
DELTASECONDS = "+%Ss"
DELTAMINUTES = "+%Mm"
DELTAHOURS = "+%Hh"
DELTA_SECONDS = "+%Ss"
DELTA_MINUTES = "+%Mm"
DELTA_HOURS = "+%Hh"
HOURS = "%H:%M"
DATETIME_FORMAT = [
"%Y-%m-%d",
@@ -15,9 +14,9 @@ DATETIME_FORMAT = [
"%Y-%m-%d %H:%M:%S",
"%Y-%m-%d %H:%M",
HOURS,
DELTAHOURS,
DELTAMINUTES,
DELTASECONDS,
DELTA_HOURS,
DELTA_MINUTES,
DELTA_SECONDS,
]
@@ -25,15 +24,15 @@ class DateTime(click.DateTime):
def _try_to_convert_date(self, value: t.Any, format: str) -> t.Optional[datetime]:
try:
if value[0] == "+":
if format == DELTASECONDS and value[-1] == "s":
if format == DELTA_SECONDS and value[-1] == "s":
return datetime.datetime.now() + datetime.timedelta(
seconds=int(value[1:-1])
)
if format == DELTAMINUTES and value[-1] == "m":
if format == DELTA_MINUTES and value[-1] == "m":
return datetime.datetime.now() + datetime.timedelta(
minutes=int(value[1:-1])
)
if format == DELTAHOURS and value[-1] == "h":
if format == DELTA_HOURS and value[-1] == "h":
return datetime.datetime.now() + datetime.timedelta(
hours=int(value[1:-1])
)
@@ -47,15 +46,15 @@ class DateTime(click.DateTime):
return None
def start_app(enddate):
def start_app(end_date):
root = Tk()
root.geometry("300x100+200+200")
root.configure(background="#000")
tlbl = Label(root, text="", font=("Arial", -100), fg="#fff", bg="#000")
tlbl.pack()
tlbl.place(relx=0.5, rely=0.5, anchor=CENTER)
timer_label = Label(root, text="", font=("Arial", -100), fg="#fff", bg="#000")
timer_label.pack()
timer_label.place(relx=0.5, rely=0.5, anchor=CENTER)
def deltaStr(t):
def format_delta(t):
days, remainder = divmod(t.total_seconds(), 60 * 60 * 24)
hours, remainder = divmod(remainder, 3600)
minutes, seconds = divmod(remainder, 60)
@@ -69,29 +68,27 @@ def start_app(enddate):
def resize(_):
ratio = root.winfo_width() / 1920
tlbl.configure(font=("Chicago", int(ratio * -200)))
timer_label.configure(font=("Chicago", int(ratio * -200)))
def update():
delta = enddate - datetime.datetime.now()
delta = end_date - datetime.datetime.now()
if delta.total_seconds() < 0:
tlbl.configure(text="Now")
tlbl.config(fg="red")
timer_label.configure(text="Now")
timer_label.config(fg="red")
else:
tlbl.configure(text=deltaStr(delta))
timer_label.configure(text=format_delta(delta))
root.after(1000 - datetime.datetime.now().microsecond // 1000, update)
root.bind("<Configure>", resize)
root.bind("<Escape>", lambda x: root.destroy())
root.after(1, update)
if os.environ.get("XDG_CURRENT_DESKTOP", "") == "i3":
root.wm_attributes("-type", "splash")
root.mainloop()
@click.command()
@click.argument("enddate", type=DateTime(formats=DATETIME_FORMAT))
def main(enddate):
start_app(enddate)
@click.argument("end_date", type=DateTime(formats=DATETIME_FORMAT))
def main(end_date):
start_app(end_date)
if __name__ == "__main__":