example_list.py 2.6 KB

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