Skip to content

Commit 966e06c

Browse files
committed
documentation and ruff fixes
1 parent 4395c60 commit 966e06c

File tree

6 files changed

+195
-23
lines changed

6 files changed

+195
-23
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@
1212

1313
<img src="readme-assets/icons/name.png" alt="Project Icon" width="750">
1414

15+
Generate custom themes for your Nintendo Switch from your images, with optional
16+
configuration for layout adjustments. Specify the path to the `nxtheme` executable
17+
and provide the directory for your input images, output files, and an optional
18+
configuration file.
19+
20+
**Usage**:
21+
22+
```bash
23+
usage: nxtheme-creator [-h] [--input INPUT] [--output OUTPUT] [--config CONFIG] nxtheme
24+
```
25+
26+
**Arguments**:
27+
28+
- `nxtheme`: The path to the `nxtheme` executable (e.g., `/path/to/SwitchThemes.exe`). This can be obtained from [SwitchThemeInjector](https://github.com/exelix11/SwitchThemeInjector).
29+
30+
**Options**:
31+
32+
- `-h, --help`: Show help message and exit.
33+
- `--input INPUT`: Specify the directory containing your input images.
34+
- `--output OUTPUT`: Define the directory where the generated theme files will be saved.
35+
- `--config CONFIG`: Provide an optional configuration file (`conf.json`) to customize layout settings.
36+
1537
- [Documentation](#documentation)
1638
- [Install With PIP](#install-with-pip)
1739
- [Language information](#language-information)
@@ -41,8 +63,8 @@ where to look for certain things:
4163
- The [Technical Reference](/documentation/reference) documents APIs and other aspects of the
4264
machinery. This documentation describes how to use the classes and functions at a lower level
4365
and assume that you have a good high-level understanding of the software.
44-
- The [Help](/documentation/help) guide provides a starting point and outlines common issues that you
45-
may have.
66+
<!-- - The [Help](/documentation/help) guide provides a starting point and outlines common issues that you
67+
may have. -->
4668

4769
## Install With PIP
4870

documentation/reference/nxtheme_creator/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
## cli
1212

13-
[Show source in __init__.py:14](../../../nxtheme_creator/__init__.py#L14)
13+
[Show source in __init__.py:17](../../../nxtheme_creator/__init__.py#L17)
1414

1515
Cli entry point.
1616

documentation/reference/nxtheme_creator/process_themes.md

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,112 @@
1111

1212
## processImages
1313

14-
[Show source in process_themes.py:51](../../../nxtheme_creator/process_themes.py#L51)
14+
[Show source in process_themes.py:101](../../../nxtheme_creator/process_themes.py#L101)
15+
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.
22+
23+
#### Arguments
24+
25+
- `nxthemebin` *str* - The path to the `nxtheme` executable used for building themes.
26+
- `inputdir` *str* - The directory containing the input images for the themes.
27+
- `outputdir` *str* - The directory where the generated theme files will be saved.
28+
- `config` *dict* - A dictionary containing configuration options such as the author name,
29+
and paths to layout files.
30+
31+
#### Returns
32+
33+
None
1534

1635
#### Signature
1736

1837
```python
19-
def processImages(nxthemebin: str, inputdir: str, outputdir: str, config: dict): ...
38+
def processImages(
39+
nxthemebin: str, inputdir: str, outputdir: str, config: dict
40+
) -> None: ...
2041
```
2142

2243

2344

2445
## resolveConf
2546

26-
[Show source in process_themes.py:33](../../../nxtheme_creator/process_themes.py#L33)
47+
[Show source in process_themes.py:69](../../../nxtheme_creator/process_themes.py#L69)
48+
49+
Resolve the file paths for layout configurations specified in the `conf` dictionary.
50+
This function checks if the specified layout files exist. If they do not, it attempts
51+
to find the files in a default `Layouts` directory relative to the `nxthemebin` executable.
52+
If the files are still not found, it tries to append `.json` to the filenames and checks again.
53+
54+
#### Arguments
55+
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.
60+
61+
#### Returns
62+
63+
Type: *dict*
64+
The updated `conf` dictionary with resolved file paths.
2765

2866
#### Signature
2967

3068
```python
31-
def resolveConf(nxthemebin: str, conf: dict): ...
69+
def resolveConf(nxthemebin: str, conf: dict) -> dict: ...
3270
```
3371

3472

3573

3674
## walkfiletree
3775

38-
[Show source in process_themes.py:9](../../../nxtheme_creator/process_themes.py#L9)
76+
[Show source in process_themes.py:11](../../../nxtheme_creator/process_themes.py#L11)
77+
78+
Create a theme_image_map from an input directory by walking the dir and getting
79+
theme names and corresponding images for each component.
80+
81+
#### Arguments
82+
83+
- `inputdir` *str* - the directory to walk
84+
85+
#### Returns
86+
87+
Type: *dict*
88+
the final theme_image_map
89+
90+
**Example**:
91+
Given the following directory structure:
92+
93+
```
94+
input_directory/
95+
├── ThemeA/
96+
│ ├── home.jpg
97+
│ ├── lock.jpg
98+
│ └── apps,news.jpg
99+
└── ThemeB/
100+
├── home.dds
101+
└── lock.dds
102+
```
103+
104+
Calling `walkfiletree("input_directory")` would produce:
105+
106+
```json
107+
{
108+
"ThemeA": {
109+
"home": "/path/to/input_directory/ThemeA/home.jpg",
110+
"lock": "/path/to/input_directory/ThemeA/lock.jpg",
111+
"apps": "/path/to/input_directory/ThemeA/apps,news.jpg",
112+
"news": "/path/to/input_directory/ThemeA/apps,news.jpg"
113+
},
114+
"ThemeB": {
115+
"home": "/path/to/input_directory/ThemeB/home.dds",
116+
"lock": "/path/to/input_directory/ThemeB/lock.dds"
117+
}
118+
}
119+
```
39120

40121
#### Signature
41122

documentation/tutorials/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ This tutorial will guide you through using the `nxtheme-creator` tool to generat
77

88
install with python-pip nxtheme-creator
99

10-
```
10+
```sh
1111
python3 -m pip install
1212
```
1313

1414
## **Step 2: Prepare Your Images**
1515

1616
**Create an Input Directory**: Organize your images in a directory. The directory structure should look like this:
1717

18-
```
18+
```sh
1919
themes_directory/
2020
├── theme1/
2121
│ ├── home.jpg
@@ -65,12 +65,12 @@ Note that items ["home", "lock", "apps", "set", "user", "news"] are configured w
6565
Open your terminal or command prompt and run the following command to generate your theme:
6666

6767
```bash
68-
python3 -m nxtheme-creator --nxtheme /path/to/nxtheme.exe --input input_directory --output output_directory --config conf.json
68+
python3 -m nxtheme-creator --nxtheme /path/to/SwitchThemes.exe --input input_directory --output output_directory --config conf.json
6969
```
7070

7171
Replace:
7272

73-
- `/path/to/nxtheme.exe` with the path to the `nxtheme` executable.
73+
- `/path/to/SwitchThemes.exe` with the path to the `nxtheme` executable.
7474
- `input_directory` with the path to your images. This defaults to the directory you run `nxtheme-creator` from
7575
- `output_directory` with the directory where you want to save the generated theme files.This defaults to `./output/`
7676
- `conf.json` with the path to your configuration file. Note this is optional, though needed if you wish to customise the layouts or set an `author_name`
@@ -79,15 +79,15 @@ Replace:
7979

8080
Assuming you have the following setup:
8181

82-
- `nxtheme.exe` located at `/path/to/nxtheme.exe`
82+
- `SwitchThemes.exe` located at `/path/to/SwitchThemes.exe`
8383
- Input directory is `./input_images`
8484
- Output directory is `./themes`
8585
- Configuration file is `./conf.json`
8686

8787
Run the command:
8888

8989
```bash
90-
python3 -m nxtheme-creator --nxtheme /path/to/nxtheme.exe --input ./input_images --output ./themes --config ./conf.json
90+
python3 -m nxtheme-creator --nxtheme /path/to/SwitchThemes.exe --input ./input_images --output ./themes --config ./conf.json
9191
```
9292

9393
## **Step 5: Verify and Install Your Theme**
@@ -99,4 +99,4 @@ python3 -m nxtheme-creator --nxtheme /path/to/nxtheme.exe --input ./input_images
9999
## **Troubleshooting**
100100

101101
- **Missing Images**: Ensure all required images are present and correctly named in your input directory.
102-
- **Executable Issues**: Make sure the path to `nxtheme.exe` is correct and that you have the necessary permissions to run it.
102+
- **Executable Issues**: Make sure the path to `SwitchThemes.exe` is correct and that you have the necessary permissions to run it.

nxtheme_creator/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
""" """
1+
"""Generate custom themes for your Nintendo Switch from your images, with optional
2+
configuration for layout adjustments. Specify the path to the `nxtheme` executable
3+
and provide the directory for your input images, output files, and an optional
4+
configuration file."""
25

36
from __future__ import annotations
47

@@ -17,7 +20,7 @@ def cli() -> None: # pragma: no cover
1720

1821
parser.add_argument(
1922
"nxtheme",
20-
help="Nxtheme command to use. eg /path/to/nxtheme.exe, obtain from https://github.com/exelix11/SwitchThemeInjector",
23+
help="Nxtheme command to use. eg /path/to/SwitchThemes.exe, obtain from https://github.com/exelix11/SwitchThemeInjector",
2124
)
2225
parser.add_argument("--input", help="input directory", default=".")
2326
parser.add_argument("--output", help="output directory", default="./output/")

nxtheme_creator/process_themes.py

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Underlying machineary to generate custom themes for your Nintendo Switch from your images. """
2+
13
import os
24
import re
35
import subprocess
@@ -7,19 +9,53 @@
79

810

911
def walkfiletree(inputdir: str) -> dict:
12+
"""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+
```
45+
"""
1046
theme_image_map = {}
1147

1248
# Walk over directories under inputdir
13-
for root, dirs, files in os.walk(inputdir):
49+
for root, _dirs, files in os.walk(inputdir):
1450
for file in files:
1551
if file.endswith((".jpg", ".dds")):
1652
# Extract theme name from the directory structure
17-
theme_name = os.path.basename(root)
53+
theme_name = Path(root).name
1854

1955
if theme_name not in theme_image_map:
2056
theme_image_map[theme_name] = {}
2157

22-
# Extract the screen types from the image name (e.g., 'home,lock.jpg')
58+
# Extract the screen types from the image name e.g., 'home,lock.jpg'
2359
screen_types = re.match(r"(\w+(,\w+)*)", file).group(1)
2460

2561
# Split by comma and map each screen type to the image path
@@ -30,7 +66,20 @@ def walkfiletree(inputdir: str) -> dict:
3066
return theme_image_map
3167

3268

33-
def resolveConf(nxthemebin: str, conf: dict):
69+
def resolveConf(nxthemebin: str, conf: dict) -> dict:
70+
"""
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.
75+
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.
80+
81+
:return dict: The updated `conf` dictionary with resolved file paths.
82+
"""
3483
for screen_type in SCREEN_TYPES:
3584
fname = conf.get(screen_type)
3685
if fname is None:
@@ -43,12 +92,29 @@ def resolveConf(nxthemebin: str, conf: dict):
4392
if not layout.exists():
4493
layout = Path(nxthemebin).parent / "Layouts" / layout.name
4594
if not layout.exists():
46-
raise RuntimeError(f"{conf[screen_type]} or {layout} does not exist :(")
95+
msg = f"{conf[screen_type]} or {layout} does not exist :("
96+
raise RuntimeError(msg)
4797
conf[screen_type] = layout
4898
return conf
4999

50100

51-
def processImages(nxthemebin: str, inputdir: str, outputdir: str, config: dict):
101+
def processImages(nxthemebin: str, inputdir: str, outputdir: str, config: dict) -> None:
102+
"""
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
117+
"""
52118
themeimgmap = walkfiletree(inputdir=inputdir)
53119
config = resolveConf(nxthemebin, conf=config)
54120

0 commit comments

Comments
 (0)