INNER CODE UNIT · Python

read_layout

Julow/Unexpected-Keyboard · gen_layouts.py:15

def read_layout(fname):
    root = XML.parse(fname).getroot()
    if root.tag != "keyboard":
        return None
    return { "name": root.get("name") }

# Yields the id (based on the file name) and the display name for every layouts
def read_layouts(files):
    for layout_file in files:
        layout_id, _ = os.path.splitext(os.path.basename(layout_file))
        layout = read_layout(layout_file)
        if layout == None:
            print("Not a layout file: %s" % layout_file)
        elif layout["name"] == None:
            print("Layout doesn't have a name: %s" % layout_id)
        else:
            yield (layout_id, layout["name"])

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…