From 15c608b8cd663bf9267ade94d689164762c40ed9 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 25 Jun 2023 16:34:05 +0200 Subject: Use generated arrays in Config.layout_of_string This function is no longer an hardcoded list of layout ids. It's replaced by a linear scan of the previously generated array and a new corresponding array of resource ids. --- gen_layouts.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'gen_layouts.py') diff --git a/gen_layouts.py b/gen_layouts.py index 2b86883..bea9ba1 100644 --- a/gen_layouts.py +++ b/gen_layouts.py @@ -40,22 +40,22 @@ def sort_layouts(layouts): # Write the XML arrays used in the preferences. def generate_arrays(out, layouts): - def add_items(parent, strings): - for s in strings: + def mk_array(tag, name, strings_items): + elem = XML.Element(tag, name=name) + for s in strings_items: item = XML.Element("item") item.text = s - parent.append(item) + elem.append(item) + return elem none_item = [ ("none", "None") ] custom_item = [ ("custom", "@string/pref_layout_e_custom") ] - lids, names = zip(*(none_item + layouts + custom_item)) # unzip - values = XML.Element("string-array", name="pref_layout_values") - add_items(values, lids) - entries = XML.Element("string-array", name="pref_layout_entries") - add_items(entries, names) + values_items, entries_items = zip(*(none_item + layouts + custom_item)) # unzip + ids_items = map(lambda s: "@xml/%s" % s if s not in ["none", "custom"] else "-1", values_items) root = XML.Element("resources") root.append(XML.Comment(text="DO NOT EDIT. This file is generated, see gen_layouts.py.")) - root.append(values) - root.append(entries) + root.append(mk_array("string-array", "pref_layout_values", values_items)) + root.append(mk_array("string-array", "pref_layout_entries", entries_items)) + root.append(mk_array("integer-array", "layout_ids", ids_items)) XML.indent(root) XML.ElementTree(element=root).write(out, encoding="unicode", xml_declaration=True) -- cgit v1.2.3