|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2026 The Dash Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | + |
| 6 | +import os |
| 7 | +import platform |
| 8 | +import shutil |
| 9 | +import subprocess |
| 10 | +import sys |
| 11 | +import tempfile |
| 12 | + |
| 13 | +# Assuming 1024x1024 canvas, the squircle content area is ~864x864 with |
| 14 | +# ~80px transparent padding on each side |
| 15 | +CONTENT_RATIO = 864 / 1024 |
| 16 | + |
| 17 | +DIR_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..")) |
| 18 | +DIR_SRC = os.path.join(DIR_ROOT, "src", "qt", "res", "src") |
| 19 | +DIR_OUT = os.path.join(DIR_ROOT, "src", "qt", "res", "icons") |
| 20 | + |
| 21 | +# Icon Composer exports to runtime icon map |
| 22 | +ICONS = [ |
| 23 | + ("macos_devnet.png", "dash_macos_devnet.png"), |
| 24 | + ("macos_mainnet.png", "dash_macos_mainnet.png"), |
| 25 | + ("macos_regtest.png", "dash_macos_regtest.png"), |
| 26 | + ("macos_testnet.png", "dash_macos_testnet.png"), |
| 27 | +] |
| 28 | + |
| 29 | +# Canvas to filename mapping for bundle icon |
| 30 | +ICNS_MAP = [ |
| 31 | + (16, "icon_16x16.png"), |
| 32 | + (32, "icon_16x16@2x.png"), |
| 33 | + (32, "icon_32x32.png"), |
| 34 | + (64, "icon_32x32@2x.png"), |
| 35 | + (128, "icon_128x128.png"), |
| 36 | + (256, "icon_128x128@2x.png"), |
| 37 | + (256, "icon_256x256.png"), |
| 38 | + (512, "icon_256x256@2x.png"), |
| 39 | + (512, "icon_512x512.png"), |
| 40 | + (1024, "icon_512x512@2x.png"), |
| 41 | +] |
| 42 | + |
| 43 | + |
| 44 | +def sips_resample_padded(src, dst, canvas_size): |
| 45 | + content_size = max(round(canvas_size * CONTENT_RATIO), 1) |
| 46 | + subprocess.check_call( |
| 47 | + ["sips", "-z", str(content_size), str(content_size), "-p", str(canvas_size), str(canvas_size), src, "--out", dst], |
| 48 | + stdout=subprocess.DEVNULL, |
| 49 | + ) |
| 50 | + |
| 51 | + |
| 52 | +def generate_icns(tmpdir): |
| 53 | + iconset = os.path.join(tmpdir, "dash.iconset") |
| 54 | + os.makedirs(iconset) |
| 55 | + |
| 56 | + src_main = os.path.join(DIR_SRC, ICONS[1][0]) |
| 57 | + for canvas_px, filename in ICNS_MAP: |
| 58 | + sips_resample_padded(src_main, os.path.join(iconset, filename), canvas_px) |
| 59 | + |
| 60 | + icns_out = os.path.join(DIR_OUT, "dash.icns") |
| 61 | + subprocess.check_call(["iconutil", "-c", "icns", iconset, "-o", icns_out]) |
| 62 | + print(f"Created: {icns_out}") |
| 63 | + |
| 64 | + |
| 65 | +def main(): |
| 66 | + if platform.system() != "Darwin": |
| 67 | + sys.exit("Error: This script requires macOS (needs sips, iconutil).") |
| 68 | + for tool in ("sips", "iconutil"): |
| 69 | + if shutil.which(tool) is None: |
| 70 | + sys.exit(f"Error: '{tool}' not found. Install Xcode command-line tools.") |
| 71 | + for src_name, _ in ICONS: |
| 72 | + src = os.path.join(DIR_SRC, src_name) |
| 73 | + if not os.path.isfile(src): |
| 74 | + sys.exit(f"Error: Source image not found: {src}") |
| 75 | + |
| 76 | + os.makedirs(DIR_OUT, exist_ok=True) |
| 77 | + |
| 78 | + # Generate bundle icon |
| 79 | + with tempfile.TemporaryDirectory(prefix="dash_icons_") as tmpdir: |
| 80 | + generate_icns(tmpdir) |
| 81 | + |
| 82 | + # Generate runtime icons |
| 83 | + for src_name, dst_name in ICONS: |
| 84 | + src = os.path.join(DIR_SRC, src_name) |
| 85 | + dst = os.path.join(DIR_OUT, dst_name) |
| 86 | + sips_resample_padded(src, dst, 256) |
| 87 | + print(f"Created: {dst}") |
| 88 | + |
| 89 | + |
| 90 | +if __name__ == "__main__": |
| 91 | + main() |
0 commit comments