Restructure icon theme builder

This commit is contained in:
Veronica Berglyd Olsen
2025-01-16 19:26:04 +01:00
parent eb419fc4e0
commit b9602da177
6 changed files with 91 additions and 90 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
# Meta
meta:name = Font Awesome 6
meta:author = Fonticons Inc
meta:license = Font Awesome Free License
meta:license = CC BY 4.0
# Icons
icon:alert_error = <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="#000000" height="128" width="128"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zm0-384c13.3 0 24 10.7 24 24l0 112c0 13.3-10.7 24-24 24s-24-10.7-24-24l0-112c0-13.3 10.7-24 24-24zM224 352a32 32 0 1 1 64 0 32 32 0 1 1 -64 0z" /></svg>
+5 -88
View File
@@ -35,7 +35,8 @@ import zipfile
from pathlib import Path
from utils.icon_themes import processFontAwesome, processMaterialIcons, processRemix
import utils.binary_dist
import utils.icon_themes
CURR_DIR = Path(__file__).parent
SETUP_DIR = CURR_DIR / "setup"
@@ -325,90 +326,6 @@ def buildSampleZip(args: argparse.Namespace | None = None) -> None:
return
##
# Import Translations (import-i18n)
##
def buildIconTheme(args: argparse.Namespace) -> None:
"""Build icon themes."""
print("")
print("Build Icon Themes")
print("=================")
print("")
workDir = Path(args.sources).absolute()
if not workDir.is_dir():
print(f"Source directory not found: {workDir}")
sys.exit(1)
iconsDir = CURR_DIR / "novelwriter" / "assets" / "icons"
style = args.style
if style in ("all", "material"):
processMaterialIcons(workDir, iconsDir, {
"material_rounded_thin": {
"name": "Material Symbols - Rounded Thin",
"style": "rounded",
"filled": False,
"weight": 200,
},
"material_rounded_normal": {
"name": "Material Symbols - Rounded Medium",
"style": "rounded",
"filled": False,
"weight": 400,
},
"material_rounded_bold": {
"name": "Material Symbols - Rounded Bold",
"style": "rounded",
"filled": False,
"weight": 600,
},
"material_filled_thin": {
"name": "Material Symbols - Filled Thin",
"style": "rounded",
"filled": True,
"weight": 200,
},
"material_filled_normal": {
"name": "Material Symbols - Filled Medium",
"style": "rounded",
"filled": True,
"weight": 400,
},
"material_filled_bold": {
"name": "Material Symbols - Filled Bold",
"style": "rounded",
"filled": True,
"weight": 600,
},
})
if style in ("all", "fa"):
processFontAwesome(workDir, iconsDir, {
"font_awesome": {
"name": "Font Awesome 6",
},
})
if style in ("all", "remix"):
processRemix(workDir, iconsDir, {
"remix_outline": {
"name": "Remix Icon - Outline",
"filled": False,
},
"remix_filled": {
"name": "Remix Icon - Filled",
"filled": True,
},
})
print("Done")
print("")
return
##
# Import Translations (import-i18n)
##
@@ -1487,9 +1404,9 @@ if __name__ == "__main__":
cmdIcons = parsers.add_parser(
"icons", help="Build icon theme files from source."
)
cmdIcons.add_argument("sources", help="Working directory for sources.")
cmdIcons.add_argument("style", help="What icon style to build.")
cmdIcons.set_defaults(func=buildIconTheme)
cmdIcons.add_argument("--sources", help="Working directory for sources.")
cmdIcons.add_argument("--style", help="What icon style to build.")
cmdIcons.set_defaults(func=utils.icon_themes.main)
# Import Translations
cmdImportTS = parsers.add_parser(
+85 -1
View File
@@ -20,12 +20,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from __future__ import annotations
import argparse
import json
import subprocess
import sys
from pathlib import Path
from xml.etree import ElementTree as ET
from utils.common import ROOT_DIR
UTILS = Path(__file__).parent
ET.register_namespace("", "http://www.w3.org/2000/svg")
ICONS = [
@@ -140,7 +144,7 @@ ICONS = [
def _loadMap(name: str) -> dict[str, str]:
"""Load a theme map file."""
data = json.loads((UTILS / f"{name}.json").read_text(encoding="utf-8"))
data = json.loads((UTILS / "icon_themes" / f"{name}.json").read_text(encoding="utf-8"))
icons = {}
for key in ICONS:
if icon := data.get(key, ""):
@@ -311,3 +315,83 @@ def processRemix(workDir: Path, iconsDir: Path, jobs: dict) -> None:
print("")
return
def main(args: argparse.Namespace) -> None:
"""Build icon themes entry point."""
print("")
print("Build Icon Themes")
print("=================")
print("")
workDir = Path(args.sources).absolute()
if not workDir.is_dir():
print(f"Source directory not found: {workDir}")
sys.exit(1)
iconsDir = ROOT_DIR / "novelwriter" / "assets" / "icons"
style = args.style
if style in ("all", "material"):
processMaterialIcons(workDir, iconsDir, {
"material_rounded_thin": {
"name": "Material Symbols - Rounded Thin",
"style": "rounded",
"filled": False,
"weight": 200,
},
"material_rounded_normal": {
"name": "Material Symbols - Rounded Medium",
"style": "rounded",
"filled": False,
"weight": 400,
},
"material_rounded_bold": {
"name": "Material Symbols - Rounded Bold",
"style": "rounded",
"filled": False,
"weight": 600,
},
"material_filled_thin": {
"name": "Material Symbols - Filled Thin",
"style": "rounded",
"filled": True,
"weight": 200,
},
"material_filled_normal": {
"name": "Material Symbols - Filled Medium",
"style": "rounded",
"filled": True,
"weight": 400,
},
"material_filled_bold": {
"name": "Material Symbols - Filled Bold",
"style": "rounded",
"filled": True,
"weight": 600,
},
})
if style in ("all", "fa"):
processFontAwesome(workDir, iconsDir, {
"font_awesome": {
"name": "Font Awesome 6",
},
})
if style in ("all", "remix"):
processRemix(workDir, iconsDir, {
"remix_outline": {
"name": "Remix Icon - Outline",
"filled": False,
},
"remix_filled": {
"name": "Remix Icon - Filled",
"filled": True,
},
})
print("Done")
print("")
return