1#!/usr/bin/env python3 2import os 3 4 5def process_index_rst(path): 6# print(path) 7 with open(path) as fp: 8 last_line="" 9 line="" 10 title_tmp="" 11 line = fp.readline() 12 d = {} 13 while line: 14 if line[0:3] == '"""': 15 title_tmp = last_line 16 elif line[0:15] ==".. lv_example::": 17 name = line[16:].strip() 18 title_tmp = title_tmp.strip() 19 d[name] = title_tmp 20 last_line = line 21 line = fp.readline() 22 23 return(d) 24 25h1= { 26 "get_started":"Get started", 27 "styles":"Styles", 28 "anim":"Animations", 29 "event":"Events", 30 "layouts":"Layouts", 31 "scroll":"Scrolling", 32 "widgets":"Widgets" 33} 34 35widgets = { 36"obj":"Base object", 37"arc":"Arc", 38"bar":"Bar", 39"btn":"Button", 40"btnmatrix":"Button matrix", 41"calendar":"Calendar", 42"canvas":"Canvas", 43"chart":"Chart", 44"checkbox":"Checkbox", 45"colorwheel":"Colorwheel", 46"dropdown":"Dropdown", 47"img":"Image", 48"imgbtn":"Image button", 49"keyboard":"Keyboard", 50"label":"Label", 51"led":"LED", 52"line":"Line", 53"list":"List", 54"menu":"Menu", 55"meter":"Meter", 56"msgbox":"Message box", 57"roller":"Roller", 58"slider":"Slider", 59"span":"Span", 60"spinbox":"Spinbox", 61"spinner":"Spinner", 62"switch":"Switch", 63"table":"Table", 64"tabview":"Tabview", 65"textarea":"Textarea", 66"tileview":"Tabview", 67"win":"Window", 68} 69 70layouts = { 71"flex":"Flex", 72"grid":"Grid", 73} 74 75 76def print_item(path, lvl, d, fout): 77 for k in d: 78 v = d[k] 79 if k.startswith(path + "/lv_example_"): 80 fout.write("#"*lvl + " " + v + "\n") 81 fout.write('```eval_rst\n') 82 fout.write(f".. lv_example:: {k}\n") 83 fout.write('```\n') 84 fout.write("\n") 85 86def exec(): 87 paths = [ "../examples/", "../demos/"] 88 fout = open("examples.md", "w") 89 filelist = [] 90 91 for path in paths: 92 for root, dirs, files in os.walk(path): 93 for f in files: 94 #append the file name to the list 95 filelist.append(os.path.join(root,f)) 96 97 filelist = [ fi for fi in filelist if fi.endswith("index.rst") ] 98 99 d_all = {} 100 #print all the file names 101 for fn in filelist: 102 d_act = process_index_rst(fn) 103 d_all.update(d_act) 104 105 fout.write("```eval_rst\n") 106 fout.write(":github_url: |github_link_base|/examples.md\n") 107 fout.write("```\n") 108 fout.write("\n") 109 fout.write("# Examples\n") 110 111 for h in h1: 112 fout.write("## " + h1[h] + "\n") 113 114 if h == "widgets": 115 for w in widgets: 116 fout.write("### " + widgets[w] + "\n") 117 print_item(h + "/" + w, 4, d_all, fout) 118 elif h == "layouts": 119 for l in layouts: 120 fout.write("### " + layouts[l] + "\n") 121 print_item(h + "/" + l, 4, d_all, fout) 122 else: 123 print_item(h, 3, d_all, fout) 124 125 fout.write("") 126