icon update: replace os.system w/ subprocess.check_call
[blender-staging.git] / release / datafiles / blender_icons_update.py
1 #!/usr/bin/env python3
2
3 # This script updates icons from the SVG file
4 import os
5 import subprocess
6 import sys
7
8 def run(cmd):
9     print("   ", " ".join(cmd))
10     subprocess.check_call(cmd)
11
12 BASEDIR = os.path.abspath(os.path.dirname(__file__))
13
14 inkscape_bin = "inkscape"
15 blender_bin = "blender"
16
17 if sys.platform == 'darwin':
18     inkscape_app_path = '/Applications/Inkscape.app/Contents/Resources/script'
19     if os.path.exists(inkscape_app_path):
20         inkscape_bin = inkscape_app_path
21
22 cmd = (
23     inkscape_bin,
24     os.path.join(BASEDIR, "blender_icons.svg"),
25     "--export-width=602",
26     "--export-height=640",
27     "--without-gui",
28     "--export-png=" + os.path.join(BASEDIR, "blender_icons16.png"),
29 )
30 run(cmd)
31
32 cmd = (
33     inkscape_bin,
34     os.path.join(BASEDIR, "blender_icons.svg"),
35     "--export-width=1204",
36     "--export-height=1280",
37     "--without-gui",
38     "--export-png=" + os.path.join(BASEDIR, "blender_icons32.png"),
39 )
40 run(cmd)
41
42
43 # For testing it can be good to clear all old
44 # rm ./blender_icons16/*.dat
45 # rm ./blender_icons32/*.dat
46
47 datatoc_icon_split_py = os.path.join(BASEDIR, "..", "..", "source", "blender", "datatoc", "datatoc_icon_split.py")
48
49 # create .dat pixmaps (which are stored in git)
50 cmd = (
51     blender_bin, "--background", "-noaudio",
52     "--python", datatoc_icon_split_py, "--",
53     "--image=" + os.path.join(BASEDIR, "blender_icons16.png"),
54     "--output=" + os.path.join(BASEDIR, "blender_icons16"),
55     "--output_prefix=icon16_",
56     "--name_style=UI_ICONS",
57     "--parts_x", "26", "--parts_y", "30",
58     "--minx", "3", "--maxx", "53", "--miny", "3", "--maxy", "8",
59     "--minx_icon", "2", "--maxx_icon", "2", "--miny_icon", "2", "--maxy_icon", "2",
60     "--spacex_icon", "1", "--spacey_icon", "1",
61 )
62 run(cmd)
63
64 cmd = (
65     blender_bin, "--background", "-noaudio",
66     "--python", datatoc_icon_split_py, "--",
67     "--image=" + os.path.join(BASEDIR, "blender_icons32.png"),
68     "--output=" + os.path.join(BASEDIR, "blender_icons32"),
69     "--output_prefix=icon32_",
70     "--name_style=UI_ICONS",
71     "--parts_x", "26", "--parts_y", "30",
72     "--minx", "6", "--maxx", "106", "--miny", "6", "--maxy", "16",
73     "--minx_icon", "4", "--maxx_icon", "4", "--miny_icon", "4", "--maxy_icon", "4",
74     "--spacex_icon", "2", "--spacey_icon", "2",
75 )
76 run(cmd)
77
78 os.remove(os.path.join(BASEDIR, "blender_icons16.png"))
79 os.remove(os.path.join(BASEDIR, "blender_icons32.png"))
80
81 # For testing, if we want the PNG of each image
82 # ./datatoc_icon_split_to_png.py ./blender_icons16/*.dat
83 # ./datatoc_icon_split_to_png.py ./blender_icons32/*.dat