diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-06-12 17:54:40 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-06-12 17:54:40 +1000 |
| commit | 64bd9053a25297f7a442ca831c7da5b44bd33f84 (patch) | |
| tree | a90c6cad25a12028302ab1a5334510fba0229bae /lib/lvgl/docs/example_list.py | |
| parent | 611176ed667c4ed7ee9f609e958f9404f4aee91d (diff) | |
| download | tangara-fw-64bd9053a25297f7a442ca831c7da5b44bd33f84.tar.gz | |
Update LVGL to v9.1.0
Diffstat (limited to 'lib/lvgl/docs/example_list.py')
| -rwxr-xr-x | lib/lvgl/docs/example_list.py | 258 |
1 files changed, 148 insertions, 110 deletions
diff --git a/lib/lvgl/docs/example_list.py b/lib/lvgl/docs/example_list.py index c65554e3..6c2d4b8e 100755 --- a/lib/lvgl/docs/example_list.py +++ b/lib/lvgl/docs/example_list.py @@ -3,123 +3,161 @@ import os def process_index_rst(path): -# print(path) - with open(path) as fp: - last_line="" - line="" - title_tmp="" - line = fp.readline() - d = {} - while line: - if line[0:3] == '"""': - title_tmp = last_line - elif line[0:15] ==".. lv_example::": - name = line[16:].strip() - title_tmp = title_tmp.strip() - d[name] = title_tmp - last_line = line - line = fp.readline() - - return(d) - -h1= { - "get_started":"Get started", - "styles":"Styles", - "anim":"Animations", - "event":"Events", - "layouts":"Layouts", - "scroll":"Scrolling", - "widgets":"Widgets" + # print(path) + with open(path, 'r') as fp: + data = fp.read() + + data = data.split('\n') + + last_line = "" + title_tmp = "" + + for line in data: + line = line.strip() + + if not line: + continue + + if line.startswith('---'): + title_tmp = last_line.strip() + + elif line.startswith('.. lv_example::'): + name = line.replace('.. lv_example::', '').strip() + yield name, title_tmp + + last_line = line + + +h1 = { + "get_started": "Get started", + "styles": "Styles", + "anim": "Animations", + "event": "Events", + "layouts": "Layouts", + "scroll": "Scrolling", + "widgets": "Widgets" } widgets = { -"obj":"Base object", -"arc":"Arc", -"bar":"Bar", -"btn":"Button", -"btnmatrix":"Button matrix", -"calendar":"Calendar", -"canvas":"Canvas", -"chart":"Chart", -"checkbox":"Checkbox", -"colorwheel":"Colorwheel", -"dropdown":"Dropdown", -"img":"Image", -"imgbtn":"Image button", -"keyboard":"Keyboard", -"label":"Label", -"led":"LED", -"line":"Line", -"list":"List", -"menu":"Menu", -"meter":"Meter", -"msgbox":"Message box", -"roller":"Roller", -"slider":"Slider", -"span":"Span", -"spinbox":"Spinbox", -"spinner":"Spinner", -"switch":"Switch", -"table":"Table", -"tabview":"Tabview", -"textarea":"Textarea", -"tileview":"Tabview", -"win":"Window", + "obj": "Base object", + "arc": "Arc", + "bar": "Bar", + "btn": "Button", + "btnmatrix": "Button matrix", + "calendar": "Calendar", + "canvas": "Canvas", + "chart": "Chart", + "checkbox": "Checkbox", + "colorwheel": "Colorwheel", + "dropdown": "Dropdown", + "img": "Image", + "imagebutton": "Image button", + "keyboard": "Keyboard", + "label": "Label", + "led": "LED", + "line": "Line", + "list": "List", + "menu": "Menu", + "meter": "Meter", + "msgbox": "Message box", + "roller": "Roller", + "scale":"Scale", + "slider": "Slider", + "span": "Span", + "spinbox": "Spinbox", + "spinner": "Spinner", + "switch": "Switch", + "table": "Table", + "tabview": "Tabview", + "textarea": "Textarea", + "tileview": "Tileview", + "win": "Window", +} + +HEADING = '=' +CHAPTER = '#' +SECTION = '*' +SUBSECTION = '=' +SUBSUBSECTION = '-' + + +def write_header(h_num, text, f): + text = text.strip() + if h_num == 0: + f.write(header_defs[h_num] * len(text)) + f.write('\n') + + f.write(text + '\n') + f.write(header_defs[h_num] * len(text)) + f.write('\n\n') + + +# This is the order that Sphinx uses for the headings/titles. 0 is the +# largest and 4 is the smallest. If this order is not kept in the reST files +# Sphinx will complain +header_defs = { + 0: HEADING, + 1: CHAPTER, + 2: SECTION, + 3: SUBSECTION, + 4: SUBSUBSECTION } layouts = { -"flex":"Flex", -"grid":"Grid", + "flex": "Flex", + "grid": "Grid", } def print_item(path, lvl, d, fout): - for k in d: - v = d[k] - if k.startswith(path + "/lv_example_"): - fout.write("#"*lvl + " " + v + "\n") - fout.write('```eval_rst\n') - fout.write(f".. lv_example:: {k}\n") - fout.write('```\n') - fout.write("\n") - -def exec(): - paths = [ "../examples/", "../demos/"] - fout = open("examples.md", "w") - filelist = [] - - for path in paths: - for root, dirs, files in os.walk(path): - for f in files: - #append the file name to the list - filelist.append(os.path.join(root,f)) - - filelist = [ fi for fi in filelist if fi.endswith("index.rst") ] - - d_all = {} - #print all the file names - for fn in filelist: - d_act = process_index_rst(fn) - d_all.update(d_act) - - fout.write("```eval_rst\n") - fout.write(":github_url: |github_link_base|/examples.md\n") - fout.write("```\n") - fout.write("\n") - fout.write("# Examples\n") - - for h in h1: - fout.write("## " + h1[h] + "\n") - - if h == "widgets": - for w in widgets: - fout.write("### " + widgets[w] + "\n") - print_item(h + "/" + w, 4, d_all, fout) - elif h == "layouts": - for l in layouts: - fout.write("### " + layouts[l] + "\n") - print_item(h + "/" + l, 4, d_all, fout) - else: - print_item(h, 3, d_all, fout) - - fout.write("") + for k in d: + v = d[k] + if k.startswith(path + "/lv_example_"): + write_header(lvl, v, fout) + fout.write(f".. lv_example:: {k}\n") + fout.write("\n") + + +def exec(temp_directory): + output_path = os.path.join(temp_directory, 'examples.rst') + + paths = ["../examples/", "../demos/"] + fout = open(output_path, "w") + filelist = [] + + for path in paths: + for root, dirs, files in os.walk(path): + for f in files: + # append the file name to the list + filelist.append(os.path.join(root, f)) + + filelist = [fi for fi in filelist if fi.endswith("index.rst")] + + d_all = {} + # print all the file names + for fn in filelist: + d_all.update(dict(tuple(item for item in process_index_rst(fn)))) + + # fout.write("```eval_rst\n") + # fout.write(":github_url: |github_link_base|/examples.md\n") + # fout.write("```\n") + # fout.write("\n") + + fout.write('.. _examples:\n\n') + write_header(0, 'Examples', fout) + + for h in h1: + write_header(1, h1[h], fout) + + if h == "widgets": + for w in widgets: + write_header(2, widgets[w], fout) + print_item(h + "/" + w, 3, d_all, fout) + elif h == "layouts": + for l in layouts: + write_header(2, layouts[l], fout) + print_item(h + "/" + l, 3, d_all, fout) + else: + print_item(h, 2, d_all, fout) + + fout.write("") |
