🔨 Automatically generate resources files with cmake (#4159)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
Fixes https://github.com/Chatterino/chatterino2/issues/3949
This commit is contained in:
Edgar
2022-11-19 12:29:12 +01:00
committed by GitHub
parent 2f4272cc2a
commit 9f5477c433
14 changed files with 134 additions and 425 deletions
-39
View File
@@ -1,39 +0,0 @@
resources_header = \
'''<RCC>
<qresource prefix="/">'''
resources_footer = \
''' </qresource>
</RCC>\n'''
header_header = \
'''#include <QPixmap>
#include "common/Singleton.hpp"
namespace chatterino {
class Resources2 : public Singleton
{
public:
Resources2();
'''
header_footer = \
'''};
} // namespace chatterino\n'''
source_header = \
'''#include "ResourcesAutogen.hpp"
namespace chatterino {
Resources2::Resources2()
{
'''
source_footer = \
'''}
} // namespace chatterino\n'''
-70
View File
@@ -1,70 +0,0 @@
#!/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']
ignored_names = ['.gitignore', '.DS_Store']
# 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
ignored_directories = ['__pycache__', 'linuxinstall']
def isNotIgnored(file):
# 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 and file.name not in ignored_names
all_files = sorted(list(filter(isNotIgnored, \
filter(Path.is_file, Path('.').glob('**/*')))))
image_files = sorted(list(filter(isNotIgnored, \
filter(Path.is_file, Path('.').glob('**/*.png')))))
with open('./resources_autogenerated.qrc', 'w') as out:
out.write(resources_header + '\n')
for file in all_files:
out.write(f" <file>{file.as_posix()}</file>\n")
out.write(resources_footer)
with open('../src/autogenerated/ResourcesAutogen.cpp', 'w') as out:
out.write(source_header)
for file in sorted(image_files):
var_name = file.with_suffix("").as_posix().replace("/",".")
out.write(f' this->{var_name}')
out.write(f' = QPixmap(":/{file.as_posix()}");\n')
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
directories = file.as_posix().split('/')[:-1]
filename = file.stem
for directory in directories:
if directory not in elements_ref:
elements_ref[directory] = {}
elements_ref = elements_ref[directory]
elements_ref[filename] = filename
writeHeader(out, "", elements, '')
out.write(header_footer)
-133
View File
@@ -1,133 +0,0 @@
<RCC>
<qresource prefix="/">
<file>avatars/_1xelerate.png</file>
<file>avatars/alazymeme.png</file>
<file>avatars/brian6932.png</file>
<file>avatars/explooosion_code.png</file>
<file>avatars/fourtf.png</file>
<file>avatars/hicupalot.png</file>
<file>avatars/iprodigy.png</file>
<file>avatars/jaxkey.png</file>
<file>avatars/kararty.png</file>
<file>avatars/karlpolice.png</file>
<file>avatars/matthewde.jpg</file>
<file>avatars/mm2pl.png</file>
<file>avatars/mohad12211.png</file>
<file>avatars/pajlada.png</file>
<file>avatars/revolter.jpg</file>
<file>avatars/slch.png</file>
<file>avatars/xheaveny.png</file>
<file>avatars/zneix.png</file>
<file>buttons/addSplit.png</file>
<file>buttons/addSplitDark.png</file>
<file>buttons/ban.png</file>
<file>buttons/banRed.png</file>
<file>buttons/cancel.svg</file>
<file>buttons/cancelDark.svg</file>
<file>buttons/clearSearch.png</file>
<file>buttons/copyDark.png</file>
<file>buttons/copyDark.svg</file>
<file>buttons/copyLight.png</file>
<file>buttons/copyLight.svg</file>
<file>buttons/emote.svg</file>
<file>buttons/emoteDark.svg</file>
<file>buttons/menuDark.png</file>
<file>buttons/menuLight.png</file>
<file>buttons/mod.png</file>
<file>buttons/modModeDisabled.png</file>
<file>buttons/modModeDisabled2.png</file>
<file>buttons/modModeEnabled.png</file>
<file>buttons/modModeEnabled2.png</file>
<file>buttons/pinDisabledDark.png</file>
<file>buttons/pinDisabledDark.svg</file>
<file>buttons/pinDisabledLight.png</file>
<file>buttons/pinDisabledLight.svg</file>
<file>buttons/pinEnabled.png</file>
<file>buttons/pinEnabled.svg</file>
<file>buttons/replyDark.png</file>
<file>buttons/replyDark.svg</file>
<file>buttons/replyThreadDark.png</file>
<file>buttons/replyThreadDark.svg</file>
<file>buttons/search.png</file>
<file>buttons/timeout.png</file>
<file>buttons/trashCan.png</file>
<file>buttons/trashcan.svg</file>
<file>buttons/unban.png</file>
<file>buttons/unmod.png</file>
<file>buttons/unvip.png</file>
<file>buttons/update.png</file>
<file>buttons/updateError.png</file>
<file>buttons/viewersDark.png</file>
<file>buttons/viewersLight.png</file>
<file>buttons/vip.png</file>
<file>chatterino.icns</file>
<file>com.chatterino.chatterino.appdata.xml</file>
<file>com.chatterino.chatterino.desktop</file>
<file>contributors.txt</file>
<file>emoji.json</file>
<file>error.png</file>
<file>examples/moving.gif</file>
<file>examples/splitting.gif</file>
<file>icon.ico</file>
<file>icon.png</file>
<file>licenses/boost_boost.txt</file>
<file>licenses/emoji-data-source.txt</file>
<file>licenses/libcommuni_BSD3.txt</file>
<file>licenses/lrucache.txt</file>
<file>licenses/magic_enum.txt</file>
<file>licenses/openssl.txt</file>
<file>licenses/pajlada_settings.txt</file>
<file>licenses/pajlada_signals.txt</file>
<file>licenses/qt_lgpl-3.0.txt</file>
<file>licenses/qtkeychain.txt</file>
<file>licenses/rapidjson.txt</file>
<file>licenses/websocketpp.txt</file>
<file>pajaDank.png</file>
<file>qss/settings.qss</file>
<file>scrolling/downScroll.png</file>
<file>scrolling/downScroll.svg</file>
<file>scrolling/neutralScroll.png</file>
<file>scrolling/neutralScroll.svg</file>
<file>scrolling/upScroll.png</file>
<file>scrolling/upScroll.svg</file>
<file>settings/about.svg</file>
<file>settings/aboutlogo.png</file>
<file>settings/accounts.svg</file>
<file>settings/advanced.svg</file>
<file>settings/behave.svg</file>
<file>settings/browser.svg</file>
<file>settings/commands.svg</file>
<file>settings/emote.svg</file>
<file>settings/externaltools.svg</file>
<file>settings/filters.svg</file>
<file>settings/ignore.svg</file>
<file>settings/keybinds.svg</file>
<file>settings/moderation.svg</file>
<file>settings/notification2.svg</file>
<file>settings/notifications.svg</file>
<file>settings/theme.svg</file>
<file>sounds/ping2.wav</file>
<file>split/down.png</file>
<file>split/left.png</file>
<file>split/move.png</file>
<file>split/right.png</file>
<file>split/up.png</file>
<file>streamerMode.png</file>
<file>switcher/plus.svg</file>
<file>switcher/popup.svg</file>
<file>switcher/switch.svg</file>
<file>tlds.txt</file>
<file>twitch/admin.png</file>
<file>twitch/automod.png</file>
<file>twitch/broadcaster.png</file>
<file>twitch/cheer1.png</file>
<file>twitch/globalmod.png</file>
<file>twitch/moderator.png</file>
<file>twitch/prime.png</file>
<file>twitch/staff.png</file>
<file>twitch/subscriber.png</file>
<file>twitch/turbo.png</file>
<file>twitch/verified.png</file>
<file>twitch/vip.png</file>
</qresource>
</RCC>