summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/extract.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/python/extract.py b/python/extract.py
new file mode 100644
index 0000000..e04ba7e
--- /dev/null
+++ b/python/extract.py
@@ -0,0 +1,71 @@
+
+import gi
+import os
+import sys
+from gi.repository import Gio
+
+
+if len(sys.argv) != 2:
+ print('Usage: %s <theme file>' % sys.argv[0])
+ sys.exit(1)
+
+res = Gio.Resource.load(sys.argv[1])
+
+
+# Get the name of the theme
+
+children = res.enumerate_children('/org/chrysalide/gui/themes', Gio.ResourceLookupFlags.NONE)
+
+name = children[0][:-1]
+
+
+# Prepare the output directory
+
+if not(os.path.isdir(name)):
+ os.mkdir(name)
+
+
+# Dump resource files
+
+files = ''
+
+children = res.enumerate_children('/org/chrysalide/gui/themes/' + name, Gio.ResourceLookupFlags.NONE)
+
+for child in children:
+
+ raw = res.lookup_data('/org/chrysalide/gui/themes/' + name + '/' + child, Gio.ResourceLookupFlags.NONE)
+
+ with open(name + os.sep + child, 'wb') as out:
+ out.write(raw.get_data())
+
+ files += '\n <file compressed="true">%s</file>' % child
+
+
+# Create the gresource.xml file
+
+xml = '''<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/chrysalide/gui/themes/%s">%s
+ </gresource>
+</gresources>
+''' % (name, files)
+
+with open(name + os.sep + 'gresource.xml', 'w') as out:
+ out.write(xml)
+
+
+# Create a Makefile
+
+rules = '''
+GTK3_CSS = %s
+
+%s.ctm: gresource.xml $(GTK3_CSS)
+ glib-compile-resources --target=$@ --sourcedir=. gresource.xml
+
+clean:
+ rm -f %s
+
+''' % (' '.join(children), name.lower(), name.lower())
+
+with open(name + os.sep + 'Makefile', 'w') as out:
+ out.write(rules)