From d7c74c9b47603cad58d7b3c790b718728c74cf28 Mon Sep 17 00:00:00 2001 From: alexnigl Date: Fri, 19 Jun 2026 11:13:02 +0200 Subject: [PATCH] some reformatiing, uv setup, removed i3 special case --- .gitignore | 5 +++++ README.md | 2 +- pyproject.toml | 14 ++++++++++++++ setup.py | 14 -------------- timer.py | 47 ++++++++++++++++++++++------------------------- uv.lock | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 77 insertions(+), 40 deletions(-) create mode 100644 .gitignore create mode 100644 pyproject.toml delete mode 100644 setup.py create mode 100644 uv.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7bfb48d --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +__pycache__/ +*.py[codz] +build/ +*.egg-info/ +.python-version diff --git a/README.md b/README.md index aa0f216..ee6e043 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Pure Python Timer GUI (with tkinter). ## Install ```sh -pipx install git+https://git.qu3.org/Qu3/timer.git +uv tool install git+https://git.qu3.org/Qu3/timer.git ``` ## Usage diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5deda59 --- /dev/null +++ b/pyproject.toml @@ -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 + diff --git a/setup.py b/setup.py deleted file mode 100644 index 2a45792..0000000 --- a/setup.py +++ /dev/null @@ -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"], - }, -) diff --git a/timer.py b/timer.py index bad1798..d01d7e7 100755 --- a/timer.py +++ b/timer.py @@ -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("", resize) root.bind("", 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__": diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..9b25bea --- /dev/null +++ b/uv.lock @@ -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" }]