Skip to content

Commit 4c6b55d

Browse files
committed
rel 2024.0.1
1 parent 454fa88 commit 4c6b55d

File tree

3 files changed

+83
-80
lines changed

3 files changed

+83
-80
lines changed

documentation/reference/nxtheme_creator/process_themes.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
[Show source in process_themes.py:101](../../../nxtheme_creator/process_themes.py#L101)
1515

16-
Process images from the specified input directory to generate Nintendo Switch themes. This
17-
function handles the following tasks:
18-
1. Walks through the input directory to collect images and associate them with themes.
19-
2. Resolves and validates configuration paths for layout files.
20-
3. Iterates over each theme and its components, and builds the theme files using the `nxtheme`
21-
executable.
16+
Process images from the specified input directory to generate Nintendo Switch themes. This
17+
function handles the following tasks:
18+
1. Walks through the input directory to collect images and associate them with themes.
19+
2. Resolves and validates configuration paths for layout files.
20+
3. Iterates over each theme and its components, and builds the theme files using the `nxtheme`
21+
executable.
2222

2323
#### Arguments
2424

@@ -53,10 +53,10 @@ If the files are still not found, it tries to append `.json` to the filenames an
5353

5454
#### Arguments
5555

56-
- `nxthemebin` *str* - The path to the `nxtheme` executable, used to locate the default
57-
`Layouts` directory.
58-
- `conf` *dict* - A dictionary containing layout configuration. The keys should be screen types
59-
(e.g., 'home', 'lock') and the values should be file paths or filenames.
56+
- `nxthemebin` *str* - The path to the `nxtheme` executable, used to locate the default
57+
`Layouts` directory.
58+
- `conf` *dict* - A dictionary containing layout configuration. The keys should be screen types
59+
(e.g., 'home', 'lock') and the values should be file paths or filenames.
6060

6161
#### Returns
6262

@@ -87,8 +87,8 @@ theme names and corresponding images for each component.
8787
Type: *dict*
8888
the final theme_image_map
8989

90-
**Example**:
91-
Given the following directory structure:
90+
**Example**:
91+
Given the following directory structure:
9292

9393
```
9494
input_directory/

nxtheme_creator/process_themes.py

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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

33
import os
44
import re
@@ -10,38 +10,38 @@
1010

1111
def 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

6969
def 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

101101
def 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
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nxtheme_creator"
3-
version = "2024"
3+
version = "2024.0.1"
44
license = "mit"
55
description = ""
66
authors = ["FredHappyface"]

0 commit comments

Comments
 (0)