1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-07-02 22:55:27 +02:00
jami-client-qt/gen-resources.py
Andreas Traczyk 1a61af02f3 resources: remove unused images and icons
gen-resources.py should be used to generate resources.qrc and
JamiResources.qml. Steps to add an image resource:
- add the resource file to the appropriate path under resources/
- run gen-resources.py
- use the newly available resource

Note: only icons and images will be represented by Qml properties.

The resource file generation may be made to run during CMake
configuration in a subsequent commit.

Some unused components were also removed during the refactor.

Gitlab: #477
Change-Id: I8e7f13d465031666be2bbadd5f29f9afc94d210d
2021-07-20 21:57:27 -04:00

33 lines
No EOL
1.3 KiB
Python

import os
import sys
import re
resdir = 'resources'
qmlfile = os.path.join('src', 'constant', 'JamiResources.qml')
sep = '_'
# replace characters that aren't valid within QML property names
formatProp = lambda str: (
"".join([{".": sep, "-": sep, " ": sep}
.get(c, c) for c in str]
).lower())
with open('resources.qrc', 'w') as qrc, open(qmlfile, 'w') as qml:
qrc.write('<RCC>\n')
qml.write('pragma Singleton\nimport QtQuick 2.14\nQtObject {\n')
for root, _, files in os.walk(resdir):
if len(files):
prefix = root.rsplit(os.sep, 1)[-1]
qrc.write('\t<qresource prefix="/%s">\n' % prefix)
for filename in files:
# use posix separators in the resource path
filepath = os.path.join(root, filename).replace(os.sep, '/')
qrc.write('\t\t<file alias="%s">%s</file>\n'
% (filename, filepath))
# only record images/icons as properties
if (re.match("icons|images", prefix)):
qml.write(' readonly property string %s: "qrc:/%s"\n'
% (formatProp(filename), filepath.split('/', 1)[1]))
qrc.write('\t</qresource>\n')
qml.write('}')
qrc.write('</RCC>')