diff options
author | Aylur <[email protected]> | 2024-10-25 14:10:07 +0000 |
---|---|---|
committer | Aylur <[email protected]> | 2024-11-02 23:57:22 +0100 |
commit | 031321b3f418369a6c4ce578ba2673b7631117c1 (patch) | |
tree | 6929be0902b46bb6b42a765b465f0530d4dbe7a8 /lib/astal/gtk4/gir.py | |
parent | e8715aec5e05e0438192e611afea2fe6f10cb80f (diff) |
feat: gtk4
initial gtk4 version of app and window
Diffstat (limited to 'lib/astal/gtk4/gir.py')
-rw-r--r-- | lib/astal/gtk4/gir.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/astal/gtk4/gir.py b/lib/astal/gtk4/gir.py new file mode 100644 index 0000000..9ef680f --- /dev/null +++ b/lib/astal/gtk4/gir.py @@ -0,0 +1,58 @@ +""" +Vala's generated gir does not contain comments, +so we use valadoc to generate them. However, they are formatted +for valadoc and not gi-docgen so we need to fix it. +""" + +import xml.etree.ElementTree as ET +import html +import sys +import subprocess + + +def fix_gir(name: str, gir: str, out: str): + namespaces = { + "": "http://www.gtk.org/introspection/core/1.0", + "c": "http://www.gtk.org/introspection/c/1.0", + "glib": "http://www.gtk.org/introspection/glib/1.0", + } + for prefix, uri in namespaces.items(): + ET.register_namespace(prefix, uri) + + tree = ET.parse(gir) + root = tree.getroot() + + for doc in root.findall(".//doc", namespaces): + if doc.text: + doc.text = ( + html.unescape(doc.text).replace("<para>", "").replace("</para>", "") + ) + + if (inc := root.find("c:include", namespaces)) is not None: + inc.set("name", f"{name}.h") + else: + print("no c:include tag found", file=sys.stderr) + exit(1) + + tree.write(out, encoding="utf-8", xml_declaration=True) + + +def valadoc(name: str, gir: str, args: list[str]): + cmd = ["valadoc", "-o", "docs", "--package-name", name, "--gir", gir, *args] + try: + subprocess.run(cmd, check=True, text=True, capture_output=True) + except subprocess.CalledProcessError as e: + print(e.stderr, file=sys.stderr) + exit(1) + + +if __name__ == "__main__": + name = sys.argv[1] + in_out = sys.argv[2].split(":") + args = sys.argv[3:] + + gir = in_out[0] + out = in_out[1] if len(in_out) > 1 else gir + + valadoc(name, gir, args) + fix_gir(name, gir, out) |