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
+5
View File
@@ -0,0 +1,5 @@
__pycache__/
*.py[codz]
build/
*.egg-info/
.python-version
+1 -1
View File
@@ -4,7 +4,7 @@ Pure Python Timer GUI (with tkinter).
## Install ## Install
```sh ```sh
pipx install git+https://git.qu3.org/Qu3/timer.git uv tool install git+https://git.qu3.org/Qu3/timer.git
``` ```
## Usage ## Usage
+14
View File
@@ -0,0 +1,14 @@
[project]
name = "timer"
version = "0.3.1"
description = "Just a countdown"
readme = "README.md"
requires-python = ">=3.14"
dependencies = ["click"]
[project.scripts]
timer = "timer:main"
[tool.uv]
package = true
-14
View File
@@ -1,14 +0,0 @@
from setuptools import setup
setup(
name="timer",
version="0.3",
author="Alexander Nigl",
py_modules=["timer"],
install_requires=[
"click",
],
entry_points={
"console_scripts": ["timer=timer:main"],
},
)
+22 -25
View File
@@ -3,11 +3,10 @@ import datetime
from tkinter import Tk, CENTER, Label from tkinter import Tk, CENTER, Label
import click import click
import typing as t import typing as t
import os
DELTASECONDS = "+%Ss" DELTA_SECONDS = "+%Ss"
DELTAMINUTES = "+%Mm" DELTA_MINUTES = "+%Mm"
DELTAHOURS = "+%Hh" DELTA_HOURS = "+%Hh"
HOURS = "%H:%M" HOURS = "%H:%M"
DATETIME_FORMAT = [ DATETIME_FORMAT = [
"%Y-%m-%d", "%Y-%m-%d",
@@ -15,9 +14,9 @@ DATETIME_FORMAT = [
"%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M:%S",
"%Y-%m-%d %H:%M", "%Y-%m-%d %H:%M",
HOURS, HOURS,
DELTAHOURS, DELTA_HOURS,
DELTAMINUTES, DELTA_MINUTES,
DELTASECONDS, DELTA_SECONDS,
] ]
@@ -25,15 +24,15 @@ class DateTime(click.DateTime):
def _try_to_convert_date(self, value: t.Any, format: str) -> t.Optional[datetime]: def _try_to_convert_date(self, value: t.Any, format: str) -> t.Optional[datetime]:
try: try:
if value[0] == "+": if value[0] == "+":
if format == DELTASECONDS and value[-1] == "s": if format == DELTA_SECONDS and value[-1] == "s":
return datetime.datetime.now() + datetime.timedelta( return datetime.datetime.now() + datetime.timedelta(
seconds=int(value[1:-1]) 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( return datetime.datetime.now() + datetime.timedelta(
minutes=int(value[1:-1]) 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( return datetime.datetime.now() + datetime.timedelta(
hours=int(value[1:-1]) hours=int(value[1:-1])
) )
@@ -47,15 +46,15 @@ class DateTime(click.DateTime):
return None return None
def start_app(enddate): def start_app(end_date):
root = Tk() root = Tk()
root.geometry("300x100+200+200") root.geometry("300x100+200+200")
root.configure(background="#000") root.configure(background="#000")
tlbl = Label(root, text="", font=("Arial", -100), fg="#fff", bg="#000") timer_label = Label(root, text="", font=("Arial", -100), fg="#fff", bg="#000")
tlbl.pack() timer_label.pack()
tlbl.place(relx=0.5, rely=0.5, anchor=CENTER) 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) days, remainder = divmod(t.total_seconds(), 60 * 60 * 24)
hours, remainder = divmod(remainder, 3600) hours, remainder = divmod(remainder, 3600)
minutes, seconds = divmod(remainder, 60) minutes, seconds = divmod(remainder, 60)
@@ -69,29 +68,27 @@ def start_app(enddate):
def resize(_): def resize(_):
ratio = root.winfo_width() / 1920 ratio = root.winfo_width() / 1920
tlbl.configure(font=("Chicago", int(ratio * -200))) timer_label.configure(font=("Chicago", int(ratio * -200)))
def update(): def update():
delta = enddate - datetime.datetime.now() delta = end_date - datetime.datetime.now()
if delta.total_seconds() < 0: if delta.total_seconds() < 0:
tlbl.configure(text="Now") timer_label.configure(text="Now")
tlbl.config(fg="red") timer_label.config(fg="red")
else: else:
tlbl.configure(text=deltaStr(delta)) timer_label.configure(text=format_delta(delta))
root.after(1000 - datetime.datetime.now().microsecond // 1000, update) root.after(1000 - datetime.datetime.now().microsecond // 1000, update)
root.bind("<Configure>", resize) root.bind("<Configure>", resize)
root.bind("<Escape>", lambda x: root.destroy()) root.bind("<Escape>", lambda x: root.destroy())
root.after(1, update) root.after(1, update)
if os.environ.get("XDG_CURRENT_DESKTOP", "") == "i3":
root.wm_attributes("-type", "splash")
root.mainloop() root.mainloop()
@click.command() @click.command()
@click.argument("enddate", type=DateTime(formats=DATETIME_FORMAT)) @click.argument("end_date", type=DateTime(formats=DATETIME_FORMAT))
def main(enddate): def main(end_date):
start_app(enddate) start_app(end_date)
if __name__ == "__main__": if __name__ == "__main__":
Generated
+35
View File
@@ -0,0 +1,35 @@
version = 1
revision = 3
requires-python = ">=3.14"
[[package]]
name = "click"
version = "8.4.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "colorama", marker = "sys_platform == 'win32'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/9b/98/518d8e5081007684232226f475082b30087d0f585e8457db087298259f49/click-8.4.1.tar.gz", hash = "sha256:918b5633eddf6b41c32d4f454bf0de810065c74e3f7dbf8ee5452f8be88d3e96", size = 353007, upload-time = "2026-05-22T04:08:37.769Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/c7/0d/67e5b4109ea4a837e80daa87c2c696711955e40449a97e8926672534def2/click-8.4.1-py3-none-any.whl", hash = "sha256:482be17c6991b8c19c5429a1e995d9b0efdbb63172824c41f99965dc0ade8ec2", size = 116639, upload-time = "2026-05-22T04:08:35.26Z" },
]
[[package]]
name = "colorama"
version = "0.4.6"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
]
[[package]]
name = "timer"
version = "0.3.1"
source = { editable = "." }
dependencies = [
{ name = "click" },
]
[package.metadata]
requires-dist = [{ name = "click" }]