2018-08-02 14:23:27 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from _generate_resources import *
|
|
|
|
|
|
|
|
ignored_files = ['qt.conf', 'resources.qrc', 'resources_autogenerated.qrc', 'windows.rc',
|
|
|
|
'generate_resources.py', '_generate_resources.py']
|
2018-09-05 01:26:17 +02:00
|
|
|
|
|
|
|
# to ignore all files in a/b, add a/b to ignored_directories.
|
|
|
|
# this will ignore a/b/c/d.txt and a/b/xd.txt
|
2019-05-11 00:01:32 +02:00
|
|
|
ignored_directories = ['__pycache__', 'linuxinstall']
|
2018-08-02 14:23:27 +02:00
|
|
|
|
|
|
|
def isNotIgnored(file):
|
2018-09-05 01:26:17 +02:00
|
|
|
# check if file exists in an ignored direcory
|
|
|
|
for ignored_directory in ignored_directories:
|
|
|
|
if file.parent.as_posix().startswith(ignored_directory):
|
|
|
|
return False
|
|
|
|
|
|
|
|
return file.as_posix() not in ignored_files
|
2018-08-02 14:23:27 +02:00
|
|
|
|
|
|
|
all_files = list(filter(isNotIgnored, \
|
|
|
|
filter(Path.is_file, Path('.').glob('**/*'))))
|
|
|
|
image_files = list(filter(isNotIgnored, \
|
|
|
|
filter(Path.is_file, Path('.').glob('**/*.png'))))
|
|
|
|
|
|
|
|
with open('./resources_autogenerated.qrc', 'w') as out:
|
|
|
|
out.write(resources_header)
|
|
|
|
for file in all_files:
|
2018-09-05 01:26:17 +02:00
|
|
|
out.write(f" <file>{file.as_posix()}</file>\n")
|
2018-08-02 14:23:27 +02:00
|
|
|
out.write(resources_footer)
|
|
|
|
|
|
|
|
with open('../src/autogenerated/ResourcesAutogen.cpp', 'w') as out:
|
|
|
|
out.write(source_header)
|
|
|
|
for file in sorted(image_files):
|
2018-09-05 01:26:17 +02:00
|
|
|
var_name = file.with_suffix("").as_posix().replace("/",".")
|
2018-08-02 14:23:27 +02:00
|
|
|
out.write(f' this->{var_name}')
|
2018-09-05 01:26:17 +02:00
|
|
|
out.write(f' = QPixmap(":/{file.as_posix()}");\n')
|
2018-08-02 14:23:27 +02:00
|
|
|
out.write(source_footer)
|
|
|
|
|
|
|
|
def writeHeader(out, name, element, indent):
|
|
|
|
if isinstance(element, dict):
|
|
|
|
if name != "":
|
|
|
|
out.write(f"{indent}struct {{\n")
|
|
|
|
for (key, value) in element.items():
|
|
|
|
writeHeader(out, key, value, indent + ' ')
|
|
|
|
if name != "":
|
|
|
|
out.write(f"{indent}}} {name};\n");
|
|
|
|
else:
|
|
|
|
out.write(f"{indent}QPixmap {element};\n")
|
|
|
|
|
|
|
|
with open('../src/autogenerated/ResourcesAutogen.hpp', 'w') as out:
|
|
|
|
out.write(header_header)
|
|
|
|
|
|
|
|
elements = {}
|
|
|
|
for file in sorted(image_files):
|
|
|
|
elements_ref = elements
|
2018-09-05 01:26:17 +02:00
|
|
|
directories = file.as_posix().split('/')[:-1]
|
2018-08-02 14:23:27 +02:00
|
|
|
filename = file.stem
|
|
|
|
for directory in directories:
|
|
|
|
if directory not in elements_ref:
|
2018-09-05 01:26:17 +02:00
|
|
|
elements_ref[directory] = {}
|
2018-08-02 14:23:27 +02:00
|
|
|
elements_ref = elements_ref[directory]
|
|
|
|
elements_ref[filename] = filename
|
|
|
|
|
|
|
|
writeHeader(out, "", elements, '')
|
|
|
|
|
|
|
|
out.write(header_footer)
|
|
|
|
|