Skip to content

Commit 5f8a0dc

Browse files
committed
Improve turing-theme-extractor.py: create subfolders for extracted PNGs
1 parent 70fbea9 commit 5f8a0dc

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tools/turing-theme-extractor.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
# turing-theme-extractor.py: Extract resources from a Turing Smart Screen theme (.data files) made for Windows app
2323
# This program will search and extract PNGs from the theme data and extract theme in the current directory
2424
# The PNG can then be re-used to create a theme for System Monitor python program (see Wiki for theme creation)
25+
# To run for all files of a folder:
26+
# for file in "FOLDER"/*; do if [ -f "$file" ]; then python turing-theme-extractor.py "$file"; fi; done
2527
import mmap
2628
import os
2729
import sys
30+
from pathlib import Path
2831

2932
PNG_SIGNATURE = b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'
3033
PNG_IEND = b'\x49\x45\x4E\x44\xAE\x42\x60\x82'
@@ -46,6 +49,11 @@
4649
with open(sys.argv[1], "r+b") as theme_file:
4750
mm = mmap.mmap(theme_file.fileno(), 0)
4851

52+
theme_name = Path(sys.argv[1]).stem
53+
54+
if not os.path.isdir(theme_name):
55+
os.makedirs(theme_name)
56+
4957
# Find PNG signature in binary data
5058
start_pos=0
5159
header_found = mm.find(PNG_SIGNATURE, 0)
@@ -59,15 +67,14 @@
5967

6068
# Extract PNG data to a file
6169
theme_file.seek(header_found)
62-
png_file = open('theme_res_' + str(header_found) + '.png', 'wb')
70+
png_file = open(theme_name + "/" + str(header_found) + '.png', 'wb')
6371
png_file.write(theme_file.read(iend_found - header_found + len(PNG_IEND)))
6472
png_file.close()
6573

66-
print("PNG extracted to theme_res_%s.png" % str(header_found))
74+
print("PNG extracted to %s/%s.png" % (theme_name, str(header_found)))
6775
found_png = found_png + 1
6876

6977
# Find next PNG signature (if any)
7078
header_found = mm.find(PNG_SIGNATURE, iend_found)
7179

7280
print("\n%d PNG files extracted from theme to current directory" % found_png)
73-

0 commit comments

Comments
 (0)