style: apply ruff lint fixes and formatting
This commit is contained in:
+21
-19
@@ -10,13 +10,11 @@ Requirements:
|
||||
pip install pillow # for .ico
|
||||
iconutil # built into macOS; for .icns
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
@@ -32,7 +30,8 @@ def build_ico():
|
||||
print("Pillow not installed — skipping .ico generation (pip install pillow)")
|
||||
return
|
||||
|
||||
import io, struct
|
||||
import io
|
||||
import struct
|
||||
|
||||
sizes = [16, 24, 32, 48, 64, 128, 256]
|
||||
images: list[tuple[int, object]] = []
|
||||
@@ -58,18 +57,21 @@ def build_ico():
|
||||
# biHeight is doubled: top half = XOR mask (color), bottom = AND mask
|
||||
hdr = struct.pack(
|
||||
"<IiiHHIIiiII",
|
||||
40, # biSize
|
||||
40, # biSize
|
||||
w,
|
||||
h * 2, # biHeight (doubled per ICO convention)
|
||||
1, # biPlanes
|
||||
32, # biBitCount
|
||||
0, # biCompression (BI_RGB)
|
||||
0, # biSizeImage (0 ok for BI_RGB)
|
||||
0, 0, 0, 0,
|
||||
1, # biPlanes
|
||||
32, # biBitCount
|
||||
0, # biCompression (BI_RGB)
|
||||
0, # biSizeImage (0 ok for BI_RGB)
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
)
|
||||
pix = img.load()
|
||||
rows = bytearray()
|
||||
for y in range(h - 1, -1, -1): # bottom-up
|
||||
for y in range(h - 1, -1, -1): # bottom-up
|
||||
for x in range(w):
|
||||
r, g, b, a = pix[x, y]
|
||||
rows += bytes([b, g, r, a])
|
||||
@@ -88,14 +90,14 @@ def build_ico():
|
||||
blobs.append((s, bmp_dib(img) if s < 256 else png_bytes(img)))
|
||||
|
||||
n = len(blobs)
|
||||
dir_offset = 6 + n * 16 # ICONDIR (6) + n × ICONDIRENTRY (16)
|
||||
dir_offset = 6 + n * 16 # ICONDIR (6) + n × ICONDIRENTRY (16)
|
||||
|
||||
out = bytearray()
|
||||
out += struct.pack("<HHH", 0, 1, n) # ICONDIR
|
||||
out += struct.pack("<HHH", 0, 1, n) # ICONDIR
|
||||
|
||||
cur = dir_offset
|
||||
for s, blob in blobs:
|
||||
w = h = s % 256 # 256 is stored as 0 in the byte field
|
||||
w = h = s % 256 # 256 is stored as 0 in the byte field
|
||||
out += struct.pack("<BBBBHHII", w, h, 0, 0, 1, 32, len(blob), cur)
|
||||
cur += len(blob)
|
||||
|
||||
@@ -115,15 +117,15 @@ def build_icns():
|
||||
iconset = Path(tempfile.mkdtemp()) / "app.iconset"
|
||||
iconset.mkdir()
|
||||
mapping = {
|
||||
"icon_16x16.png": "icon-16.png",
|
||||
"icon_16x16.png": "icon-16.png",
|
||||
"icon_16x16@2x.png": "icon-32.png",
|
||||
"icon_32x32.png": "icon-32.png",
|
||||
"icon_32x32.png": "icon-32.png",
|
||||
"icon_32x32@2x.png": "icon-64.png",
|
||||
"icon_128x128.png": "icon-128.png",
|
||||
"icon_128x128.png": "icon-128.png",
|
||||
"icon_128x128@2x.png": "icon-256.png",
|
||||
"icon_256x256.png": "icon-256.png",
|
||||
"icon_256x256.png": "icon-256.png",
|
||||
"icon_256x256@2x.png": "icon-512.png",
|
||||
"icon_512x512.png": "icon-512.png",
|
||||
"icon_512x512.png": "icon-512.png",
|
||||
"icon_512x512@2x.png": "icon-1024.png",
|
||||
}
|
||||
for dst_name, src_name in mapping.items():
|
||||
|
||||
Reference in New Issue
Block a user