aboutsummaryrefslogtreecommitdiff
path: root/docs/example_list.py
blob: 6c2d4b8e5d6ab75878acb29473784b16fe348442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python3
import os


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"
}

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",
    "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",
}


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("")