Skip to content
Snippets Groups Projects
Commit be8659e7 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

chore: Script: Add type annotations

parent 0f3a42fd
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# Reads all .ui files and creates builder.pyi # Reads all .ui files and creates builder.pyi
# Excecute this script from the repo root dir # Excecute this script from the repo root dir
from io import TextIOWrapper
from pathlib import Path from pathlib import Path
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
...@@ -41,22 +42,22 @@ def get_builder(file_name: Literal['%s'], widgets: list[str] = ...) -> %s: ...'' ...@@ -41,22 +42,22 @@ def get_builder(file_name: Literal['%s'], widgets: list[str] = ...) -> %s: ...''
def get_builder(file_name: str, widgets: list[str] = ...) -> Builder: ...''' def get_builder(file_name: str, widgets: list[str] = ...) -> Builder: ...'''
def make_class_name(path): def make_class_name(path: Path) -> str:
name = path.name.removesuffix('.ui') name = path.name.removesuffix('.ui')
names = name.split('_') names = name.split('_')
names = map(lambda x: x.capitalize(), names) names = map(lambda x: x.capitalize(), names)
return ''.join(names) + 'Builder' return ''.join(names) + 'Builder'
def parse(path, file): def parse(path: Path, file: TextIOWrapper) -> str:
print('read', path) print('read', path)
lines = [] lines: list[str] = []
tree = ET.parse(path) tree = ET.parse(path)
for node in tree.iter(tag='object'): for node in tree.iter(tag='object'):
id_ = node.attrib.get('id') id_ = node.attrib.get('id')
if id_ is None: if id_ is None:
continue continue
klass = node.attrib.get('class') klass = node.attrib['class']
if klass.startswith('GtkSource'): if klass.startswith('GtkSource'):
klass = f'GtkSource.{klass.removeprefix("GtkSource")}' klass = f'GtkSource.{klass.removeprefix("GtkSource")}'
elif klass.startswith('Atk'): elif klass.startswith('Atk'):
...@@ -78,7 +79,7 @@ def parse(path, file): ...@@ -78,7 +79,7 @@ def parse(path, file):
return klass_name return klass_name
builder_names = [] builder_names: list[tuple[str, str]] = []
with out_path.open(mode='w', encoding='utf8') as file: with out_path.open(mode='w', encoding='utf8') as file:
file.write(IMPORTS) file.write(IMPORTS)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment