From d3941e88cc7c3b3bd92129a5d04033fbba436a00 Mon Sep 17 00:00:00 2001 From: allebonvi Date: Wed, 21 Oct 2026 11:37:40 +0200 Subject: [PATCH] Corregge icona Esci HighDPI con CTkImage (main 1.0.4) --- main.py | 20 +++++++++++--------- requirements.txt | 1 + tests/test_inventory_gui.py | 12 ++++++++++-- version_info.py | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 9af8c66..b27a4e1 100644 --- a/main.py +++ b/main.py @@ -16,6 +16,7 @@ from runtime_support import ensure_stdio, run_with_fatal_log ensure_stdio("warehouse_main") import customtkinter as ctk +from PIL import Image, ImageDraw from tkinter import messagebox from async_loop_singleton import get_global_loop, stop_global_loop @@ -357,17 +358,18 @@ class Launcher(ctk.CTk): except Exception: pass - def _make_exit_icon(self, *, color: str) -> tk.PhotoImage: - """Create a small red X icon without adding image assets to the project.""" + def _make_exit_icon(self, *, color: str) -> ctk.CTkImage: + """Create a transparent X with extra resolution for HighDPI scaling.""" size = 14 - image = tk.PhotoImage(width=size, height=size) - for offset in range(3, 11): - image.put(color, (offset, offset)) - image.put(color, (offset + 1, offset)) - image.put(color, (offset, size - 1 - offset)) - image.put(color, (offset + 1, size - 1 - offset)) - return image + scale = 3 + image = Image.new("RGBA", (size * scale, size * scale), (0, 0, 0, 0)) + draw = ImageDraw.Draw(image) + draw.line((3 * scale, 3 * scale, 10 * scale, 10 * scale), + fill=color, width=2 * scale) + draw.line((3 * scale, 10 * scale, 10 * scale, 3 * scale), + fill=color, width=2 * scale) + return ctk.CTkImage(light_image=image, dark_image=image, size=(size, size)) def _apply_dynamic_geometry(self) -> None: """Size the launcher around its current content and keep it docked at the top.""" diff --git a/requirements.txt b/requirements.txt index cc7fb0e..94be01a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ customtkinter==5.2.2 loguru openpyxl==3.1.5 orjson +Pillow pyodbc==5.3.0 SQLAlchemy==2.0.49 tksheet==7.6.0 diff --git a/tests/test_inventory_gui.py b/tests/test_inventory_gui.py index 00174ff..be41a84 100644 --- a/tests/test_inventory_gui.py +++ b/tests/test_inventory_gui.py @@ -2,6 +2,7 @@ import tkinter as tk import unittest +import warnings from datetime import date from decimal import Decimal from unittest.mock import Mock, patch @@ -98,11 +99,18 @@ class InventoryLauncherTests(unittest.TestCase): from main import Launcher from user_session import UserSession session = UserSession(1, "TEST", "Test operator") - with patch.object(Launcher, "_apply_dynamic_geometry"), patch.object(Launcher, "lift"), \ - patch.object(Launcher, "focus_force"), patch.object(Launcher, "_make_exit_icon", return_value=None): + with warnings.catch_warnings(), patch.object(Launcher, "_apply_dynamic_geometry"), \ + patch.object(Launcher, "lift"), patch.object(Launcher, "focus_force"): + warnings.simplefilter("error", UserWarning) root = Launcher(session, Mock()) root.withdraw() try: + self.assertIsInstance(root._exit_icon, ctk.CTkImage) + self.assertEqual(root._exit_icon.cget("size"), (14, 14)) + for mode in ("light", "dark"): + for scale in (1, 2): + photo = root._exit_icon.create_scaled_photo_image(scale, mode) + self.assertEqual((photo.width(), photo.height()), (14 * scale, 14 * scale)) def widgets(widget): for child in widget.winfo_children(): yield child diff --git a/version_info.py b/version_info.py index 8e14705..7c740c9 100644 --- a/version_info.py +++ b/version_info.py @@ -12,7 +12,7 @@ MODULE_VERSIONS: dict[str, str] = { "async_loop_singleton": "1.0.0", "async_msssql_query": "1.0.1", "audit_log": "1.0.0", - "main": "1.0.3", + "main": "1.0.4", "inventario": "1.1.0", "inventory_service": "1.1.0", "barcode_client": "1.0.27",