Corregge icona Esci HighDPI con CTkImage (main 1.0.4)

This commit is contained in:
2026-10-21 11:37:40 +02:00
parent 04406e840d
commit d3941e88cc
4 changed files with 23 additions and 12 deletions

20
main.py
View File

@@ -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."""

View File

@@ -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

View File

@@ -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

View File

@@ -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",