mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-11-13 12:38:15 +00:00
Changed icons SVG
Changed the way colours were managed in the SVG files to make them more amenable to scripting. Changed the scripts to automate icon resizing. Co-Authored-By: Joseph Abbey <me@josephabbey.dev>
This commit is contained in:
@@ -30,44 +30,32 @@
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
from bs4 import BeautifulSoup, Comment
|
||||
from bs4 import BeautifulSoup
|
||||
import os
|
||||
import shutil
|
||||
|
||||
output_dir_prefix = 'resources-icons-'
|
||||
input_dir = output_dir_prefix + '48'
|
||||
|
||||
Doub = 0
|
||||
Sing = 1
|
||||
Half = 2
|
||||
|
||||
# Original icons for 416x416 screen size with 48x48 icons
|
||||
original = (96, 48, 24)
|
||||
|
||||
# The icons need to scale as a ratio of screen size 48:416 pixels
|
||||
#
|
||||
# Icon 55 53 48 46 42 37 32 30 28 26 24 21 19 18
|
||||
# Screen 480 454 416 390 360 320 280 260 240 218 208 176 166 156
|
||||
|
||||
# Convert icons to different screen sizes by these parameters
|
||||
lookup = {
|
||||
# Doub Sing Half
|
||||
# 0 1 2
|
||||
480: (110, 55, 28),
|
||||
454: (106, 53, 27),
|
||||
# 416: ( 96, 48, 24),
|
||||
390: ( 90, 46, 23),
|
||||
360: ( 84, 42, 21),
|
||||
320: ( 74, 38, 19),
|
||||
295: ( 68, 34, 17), # Especially for the instinct3amoled50mm device that clip the icons
|
||||
280: ( 64, 32, 16),
|
||||
260: ( 60, 30, 15),
|
||||
240: ( 56, 28, 14),
|
||||
218: ( 50, 26, 13),
|
||||
208: ( 48, 24, 12),
|
||||
176: ( 42, 21, 11),
|
||||
156: ( 36, 18, 9)
|
||||
}
|
||||
lookup = [
|
||||
55,
|
||||
53,
|
||||
# 48,
|
||||
46,
|
||||
42,
|
||||
38,
|
||||
34, # Especially for the instinct3amoled50mm device that clip the icons
|
||||
32,
|
||||
30,
|
||||
28,
|
||||
26,
|
||||
24,
|
||||
"21-w",
|
||||
21,
|
||||
"18-w",
|
||||
18
|
||||
]
|
||||
|
||||
# Delete all but the original 48x48 icon directories
|
||||
for entry in os.listdir("."):
|
||||
@@ -75,8 +63,12 @@ for entry in os.listdir("."):
|
||||
shutil.rmtree(entry)
|
||||
|
||||
# (Re-)Create the resized icon directories
|
||||
for screen_size, icon_sizes in lookup.items():
|
||||
output_dir = output_dir_prefix + str(icon_sizes[Sing])
|
||||
for icon_size in lookup:
|
||||
output_dir = output_dir_prefix + str(icon_size)
|
||||
white = False
|
||||
if isinstance(icon_size, str):
|
||||
white = True
|
||||
icon_size = int(icon_size.split("-")[0])
|
||||
print("\nCreate directory:", output_dir)
|
||||
if os.path.exists(output_dir) and os.path.isdir(output_dir):
|
||||
shutil.rmtree(output_dir)
|
||||
@@ -87,16 +79,14 @@ for screen_size, icon_sizes in lookup.items():
|
||||
with open(input_dir + "/" + entry, "r") as f:
|
||||
soup = BeautifulSoup(f.read(), features="xml")
|
||||
svg: BeautifulSoup = list(soup.children)[0]
|
||||
h = int(svg.attrs["height"])
|
||||
if (h == original[Doub]):
|
||||
svg.attrs["width"] = lookup[screen_size][Doub]
|
||||
svg.attrs["height"] = lookup[screen_size][Doub]
|
||||
elif (h == original[Sing]):
|
||||
svg.attrs["width"] = lookup[screen_size][Sing]
|
||||
svg.attrs["height"] = lookup[screen_size][Sing]
|
||||
elif (h == original[Half]):
|
||||
svg.attrs["width"] = lookup[screen_size][Half]
|
||||
svg.attrs["height"] = lookup[screen_size][Half]
|
||||
svg.attrs["width"] = icon_size
|
||||
svg.attrs["height"] = icon_size
|
||||
if white:
|
||||
# Add white colour style
|
||||
svg.find("style", id="colours").string = """
|
||||
.colour1 { color: #dddddd; }
|
||||
.colour2 { color: #ffffff; }
|
||||
"""
|
||||
with open(output_dir + "/" + entry, "wb") as o:
|
||||
o.write(svg.encode("utf-8") + b"\n")
|
||||
elif entry.endswith(".xml"):
|
||||
|
||||
Reference in New Issue
Block a user