From 554cd1af72e4da08d1600d284b81e6771c15fcb4 Mon Sep 17 00:00:00 2001 From: Auric Vente Date: Fri, 19 Jul 2024 19:44:58 -0600 Subject: [PATCH] Mods --- cromulant/game.py | 9 +++++++-- cromulant/utils.py | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cromulant/game.py b/cromulant/game.py index 119ba3d..c1d2c20 100644 --- a/cromulant/game.py +++ b/cromulant/game.py @@ -46,7 +46,8 @@ class Game: elif ant.method == "thinking": status = f"Thinking about {status}" - image_label = Game.get_image(Config.status_image_path, color) + tooltip = Utils.to_date(ant.updated) + image_label = Game.get_image(Config.status_image_path, color, tooltip=tooltip) right_container = Game.make_right_container(ant.name, status) container.addWidget(image_label) @@ -104,7 +105,8 @@ class Game: @staticmethod def get_image( - image_path: Path, color: tuple[int, int, int] | None = None + image_path: Path, color: tuple[int, int, int] | None = None, + tooltip: str = "" ) -> QLabel: image_label = QLabel() pixmap = QPixmap(str(image_path)) @@ -123,6 +125,9 @@ class Game: rgb = Utils.get_rgb(color) image_label.setStyleSheet(f"border: 2px solid {rgb};") + if tooltip: + image_label.setToolTip(tooltip) + image_label.mousePressEvent = lambda event: Game.toggle_song() return image_label diff --git a/cromulant/utils.py b/cromulant/utils.py index 04a4f63..09f7e4e 100644 --- a/cromulant/utils.py +++ b/cromulant/utils.py @@ -3,6 +3,7 @@ from __future__ import annotations import random import colorsys import time +from datetime import datetime from typing import ClassVar from fontTools.ttLib import TTFont # type: ignore @@ -108,3 +109,9 @@ class Utils: @staticmethod def get_random_emoji(num: int) -> str: return Utils.get_random_character(str(Config.emoji_font_path), num) + + @staticmethod + def to_date(timestamp: float) -> str: + dt_object = datetime.fromtimestamp(timestamp) + hour = dt_object.strftime("%I").lstrip("0") + return dt_object.strftime(f"%b %d %Y - {hour}:%M %p") \ No newline at end of file