lvgl/docs/example_list.py

164 lines
3.7 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
2021-06-15 05:13:22 +08:00
import os
2021-06-15 05:13:22 +08:00
def process_index_rst(path):
# 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"
2021-06-15 05:13:22 +08:00
}
widgets = {
2024-10-24 02:53:33 +08:00
"obj": "Base Widget",
"animimg": "Animation Image",
"arc": "Arc",
"bar": "Bar",
"button": "Button",
"buttonmatrix": "Button Matrix",
"calendar": "Calendar",
"canvas": "Canvas",
"chart": "Chart",
"checkbox": "Checkbox",
"dropdown": "Dropdown",
"image": "Image",
"imagebutton": "Image Button",
"keyboard": "Keyboard",
"label": "Label",
"led": "LED",
"line": "Line",
"list": "List",
"lottie": "Lottie",
"menu": "Menu",
"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
2021-06-15 05:13:22 +08:00
}
layouts = {
"flex": "Flex",
"grid": "Grid",
2021-06-15 05:13:22 +08:00
}
2021-06-15 16:47:09 +08:00
def print_item(path, lvl, d, fout):
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("")