1- """Underlying machineary to generate custom themes for your Nintendo Switch from your images. """
1+ """Underlying machineary to generate custom themes for your Nintendo Switch from your images."""
22
33import os
44import re
1010
1111def walkfiletree (inputdir : str ) -> dict :
1212 """Create a theme_image_map from an input directory by walking the dir and getting
13- theme names and corresponding images for each component.
14-
15- :param str inputdir: the directory to walk
16- :return dict: the final theme_image_map
17-
18- **Example**:
19- Given the following directory structure:
20- ```
21- input_directory/
22- ├── ThemeA/
23- │ ├── home.jpg
24- │ ├── lock.jpg
25- │ └── apps,news.jpg
26- └── ThemeB/
27- ├── home.dds
28- └── lock.dds
29- ```
30- Calling `walkfiletree("input_directory")` would produce:
31- ```json
32- {
33- "ThemeA": {
34- "home": "/path/to/input_directory/ThemeA/home.jpg",
35- "lock": "/path/to/input_directory/ThemeA/lock.jpg",
36- "apps": "/path/to/input_directory/ThemeA/apps,news.jpg",
37- "news": "/path/to/input_directory/ThemeA/apps,news.jpg"
38- },
39- "ThemeB": {
40- "home": "/path/to/input_directory/ThemeB/home.dds",
41- "lock": "/path/to/input_directory/ThemeB/lock.dds"
42- }
43- }
44- ```
13+ theme names and corresponding images for each component.
14+
15+ :param str inputdir: the directory to walk
16+ :return dict: the final theme_image_map
17+
18+ **Example**:
19+ Given the following directory structure:
20+ ```
21+ input_directory/
22+ ├── ThemeA/
23+ │ ├── home.jpg
24+ │ ├── lock.jpg
25+ │ └── apps,news.jpg
26+ └── ThemeB/
27+ ├── home.dds
28+ └── lock.dds
29+ ```
30+ Calling `walkfiletree("input_directory")` would produce:
31+ ```json
32+ {
33+ "ThemeA": {
34+ "home": "/path/to/input_directory/ThemeA/home.jpg",
35+ "lock": "/path/to/input_directory/ThemeA/lock.jpg",
36+ "apps": "/path/to/input_directory/ThemeA/apps,news.jpg",
37+ "news": "/path/to/input_directory/ThemeA/apps,news.jpg"
38+ },
39+ "ThemeB": {
40+ "home": "/path/to/input_directory/ThemeB/home.dds",
41+ "lock": "/path/to/input_directory/ThemeB/lock.dds"
42+ }
43+ }
44+ ```
4545 """
4646 theme_image_map = {}
4747
@@ -68,17 +68,17 @@ def walkfiletree(inputdir: str) -> dict:
6868
6969def resolveConf (nxthemebin : str , conf : dict ) -> dict :
7070 """
71- Resolve the file paths for layout configurations specified in the `conf` dictionary.
72- This function checks if the specified layout files exist. If they do not, it attempts
73- to find the files in a default `Layouts` directory relative to the `nxthemebin` executable.
74- If the files are still not found, it tries to append `.json` to the filenames and checks again.
71+ Resolve the file paths for layout configurations specified in the `conf` dictionary.
72+ This function checks if the specified layout files exist. If they do not, it attempts
73+ to find the files in a default `Layouts` directory relative to the `nxthemebin` executable.
74+ If the files are still not found, it tries to append `.json` to the filenames and checks again.
7575
76- :param str nxthemebin: The path to the `nxtheme` executable, used to locate the default
77- `Layouts` directory.
78- :param dict conf: A dictionary containing layout configuration. The keys should be screen types
79- (e.g., 'home', 'lock') and the values should be file paths or filenames.
76+ :param str nxthemebin: The path to the `nxtheme` executable, used to locate the default
77+ `Layouts` directory.
78+ :param dict conf: A dictionary containing layout configuration. The keys should be screen types
79+ (e.g., 'home', 'lock') and the values should be file paths or filenames.
8080
81- :return dict: The updated `conf` dictionary with resolved file paths.
81+ :return dict: The updated `conf` dictionary with resolved file paths.
8282 """
8383 for screen_type in SCREEN_TYPES :
8484 fname = conf .get (screen_type )
@@ -94,26 +94,26 @@ def resolveConf(nxthemebin: str, conf: dict) -> dict:
9494 if not layout .exists ():
9595 msg = f"{ conf [screen_type ]} or { layout } does not exist :("
9696 raise RuntimeError (msg )
97- conf [screen_type ] = layout
97+ conf [screen_type ] = str ( layout )
9898 return conf
9999
100100
101101def processImages (nxthemebin : str , inputdir : str , outputdir : str , config : dict ) -> None :
102102 """
103- Process images from the specified input directory to generate Nintendo Switch themes. This
104- function handles the following tasks:
105- 1. Walks through the input directory to collect images and associate them with themes.
106- 2. Resolves and validates configuration paths for layout files.
107- 3. Iterates over each theme and its components, and builds the theme files using the `nxtheme`
108- executable.
109-
110- :param str nxthemebin: The path to the `nxtheme` executable used for building themes.
111- :param str inputdir: The directory containing the input images for the themes.
112- :param str outputdir: The directory where the generated theme files will be saved.
113- :param dict config: A dictionary containing configuration options such as the author name,
114- and paths to layout files.
115-
116- :return: None
103+ Process images from the specified input directory to generate Nintendo Switch themes. This
104+ function handles the following tasks:
105+ 1. Walks through the input directory to collect images and associate them with themes.
106+ 2. Resolves and validates configuration paths for layout files.
107+ 3. Iterates over each theme and its components, and builds the theme files using the `nxtheme`
108+ executable.
109+
110+ :param str nxthemebin: The path to the `nxtheme` executable used for building themes.
111+ :param str inputdir: The directory containing the input images for the themes.
112+ :param str outputdir: The directory where the generated theme files will be saved.
113+ :param dict config: A dictionary containing configuration options such as the author name,
114+ and paths to layout files.
115+
116+ :return: None
117117 """
118118 themeimgmap = walkfiletree (inputdir = inputdir )
119119 config = resolveConf (nxthemebin , conf = config )
@@ -125,16 +125,19 @@ def processImages(nxthemebin: str, inputdir: str, outputdir: str, config: dict)
125125 for component_name , image_path in theme .items ():
126126 name = f"{ theme_name } _{ component_name } "
127127 (Path (outputdir ) / theme_name ).mkdir (exist_ok = True , parents = True )
128+ cmd = [
129+ nxthemebin ,
130+ "buildNX" ,
131+ component_name ,
132+ image_path ,
133+ config .get (component_name ) or "" ,
134+ f"name={ name } " ,
135+ f"author={ author_name } " ,
136+ f"out={ outputdir } /{ theme_name } /{ name } .nxtheme" ,
137+ ]
138+ if os .name != "nt" : # Not Windows, so run with mono
139+ cmd = ["mono" ] + cmd
128140 subprocess .run (
129- [
130- nxthemebin ,
131- "buildNX" ,
132- component_name ,
133- image_path ,
134- config .get (component_name ) or "" ,
135- f"name={ name } " ,
136- f"author={ author_name } " ,
137- f"out={ outputdir } /{ theme_name } /{ name } .nxtheme" ,
138- ],
141+ cmd ,
139142 check = False ,
140143 )
0 commit comments