Corregge icona Esci HighDPI con CTkImage (main 1.0.4)
This commit is contained in:
20
main.py
20
main.py
@@ -16,6 +16,7 @@ from runtime_support import ensure_stdio, run_with_fatal_log
|
|||||||
ensure_stdio("warehouse_main")
|
ensure_stdio("warehouse_main")
|
||||||
|
|
||||||
import customtkinter as ctk
|
import customtkinter as ctk
|
||||||
|
from PIL import Image, ImageDraw
|
||||||
from tkinter import messagebox
|
from tkinter import messagebox
|
||||||
|
|
||||||
from async_loop_singleton import get_global_loop, stop_global_loop
|
from async_loop_singleton import get_global_loop, stop_global_loop
|
||||||
@@ -357,17 +358,18 @@ class Launcher(ctk.CTk):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _make_exit_icon(self, *, color: str) -> tk.PhotoImage:
|
def _make_exit_icon(self, *, color: str) -> ctk.CTkImage:
|
||||||
"""Create a small red X icon without adding image assets to the project."""
|
"""Create a transparent X with extra resolution for HighDPI scaling."""
|
||||||
|
|
||||||
size = 14
|
size = 14
|
||||||
image = tk.PhotoImage(width=size, height=size)
|
scale = 3
|
||||||
for offset in range(3, 11):
|
image = Image.new("RGBA", (size * scale, size * scale), (0, 0, 0, 0))
|
||||||
image.put(color, (offset, offset))
|
draw = ImageDraw.Draw(image)
|
||||||
image.put(color, (offset + 1, offset))
|
draw.line((3 * scale, 3 * scale, 10 * scale, 10 * scale),
|
||||||
image.put(color, (offset, size - 1 - offset))
|
fill=color, width=2 * scale)
|
||||||
image.put(color, (offset + 1, size - 1 - offset))
|
draw.line((3 * scale, 10 * scale, 10 * scale, 3 * scale),
|
||||||
return image
|
fill=color, width=2 * scale)
|
||||||
|
return ctk.CTkImage(light_image=image, dark_image=image, size=(size, size))
|
||||||
|
|
||||||
def _apply_dynamic_geometry(self) -> None:
|
def _apply_dynamic_geometry(self) -> None:
|
||||||
"""Size the launcher around its current content and keep it docked at the top."""
|
"""Size the launcher around its current content and keep it docked at the top."""
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ customtkinter==5.2.2
|
|||||||
loguru
|
loguru
|
||||||
openpyxl==3.1.5
|
openpyxl==3.1.5
|
||||||
orjson
|
orjson
|
||||||
|
Pillow
|
||||||
pyodbc==5.3.0
|
pyodbc==5.3.0
|
||||||
SQLAlchemy==2.0.49
|
SQLAlchemy==2.0.49
|
||||||
tksheet==7.6.0
|
tksheet==7.6.0
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
import unittest
|
import unittest
|
||||||
|
import warnings
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
@@ -98,11 +99,18 @@ class InventoryLauncherTests(unittest.TestCase):
|
|||||||
from main import Launcher
|
from main import Launcher
|
||||||
from user_session import UserSession
|
from user_session import UserSession
|
||||||
session = UserSession(1, "TEST", "Test operator")
|
session = UserSession(1, "TEST", "Test operator")
|
||||||
with patch.object(Launcher, "_apply_dynamic_geometry"), patch.object(Launcher, "lift"), \
|
with warnings.catch_warnings(), patch.object(Launcher, "_apply_dynamic_geometry"), \
|
||||||
patch.object(Launcher, "focus_force"), patch.object(Launcher, "_make_exit_icon", return_value=None):
|
patch.object(Launcher, "lift"), patch.object(Launcher, "focus_force"):
|
||||||
|
warnings.simplefilter("error", UserWarning)
|
||||||
root = Launcher(session, Mock())
|
root = Launcher(session, Mock())
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
try:
|
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):
|
def widgets(widget):
|
||||||
for child in widget.winfo_children():
|
for child in widget.winfo_children():
|
||||||
yield child
|
yield child
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ MODULE_VERSIONS: dict[str, str] = {
|
|||||||
"async_loop_singleton": "1.0.0",
|
"async_loop_singleton": "1.0.0",
|
||||||
"async_msssql_query": "1.0.1",
|
"async_msssql_query": "1.0.1",
|
||||||
"audit_log": "1.0.0",
|
"audit_log": "1.0.0",
|
||||||
"main": "1.0.3",
|
"main": "1.0.4",
|
||||||
"inventario": "1.1.0",
|
"inventario": "1.1.0",
|
||||||
"inventory_service": "1.1.0",
|
"inventory_service": "1.1.0",
|
||||||
"barcode_client": "1.0.27",
|
"barcode_client": "1.0.27",
|
||||||
|
|||||||
Reference in New Issue
Block a user