SCsub 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env python
  2. Import('env')
  3. from compat import StringIO
  4. def make_editor_icons_action(target, source, env):
  5. import os
  6. dst = target[0].srcnode().abspath
  7. svg_icons = source
  8. icons_string = StringIO()
  9. for f in svg_icons:
  10. fname = str(f)
  11. icons_string.write('\t"')
  12. with open(fname, 'rb') as svgf:
  13. b = svgf.read(1)
  14. while(len(b) == 1):
  15. icons_string.write("\\" + str(hex(ord(b)))[1:])
  16. b = svgf.read(1)
  17. icons_string.write('"')
  18. if fname != svg_icons[-1]:
  19. icons_string.write(",")
  20. icons_string.write('\n')
  21. s = StringIO()
  22. s.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  23. s.write("#ifndef _EDITOR_ICONS_H\n")
  24. s.write("#define _EDITOR_ICONS_H\n")
  25. s.write("static const int editor_icons_count = %s;\n" % len(svg_icons))
  26. s.write("static const char *editor_icons_sources[] = {\n")
  27. s.write(icons_string.getvalue())
  28. s.write('};\n\n')
  29. s.write("static const char *editor_icons_names[] = {\n")
  30. # this is used to store the indices of thumbnail icons
  31. thumb_medium_indices = [];
  32. thumb_big_indices = [];
  33. index = 0
  34. for f in svg_icons:
  35. fname = str(f)
  36. icon_name = os.path.basename(fname)[5:-4].title().replace("_", "")
  37. if icon_name.endswith("MediumThumb"): # dont know a better way to handle this
  38. thumb_medium_indices.append(str(index))
  39. if icon_name.endswith("BigThumb"): # dont know a better way to handle this
  40. thumb_big_indices.append(str(index))
  41. s.write('\t"%s"' % icon_name)
  42. if fname != svg_icons[-1]:
  43. s.write(",")
  44. s.write('\n')
  45. index += 1
  46. s.write('};\n')
  47. if thumb_medium_indices:
  48. s.write("\n\n")
  49. s.write("static const int editor_md_thumbs_count = %s;\n" % len(thumb_medium_indices))
  50. s.write("static const int editor_md_thumbs_indices[] = {")
  51. s.write(", ".join(thumb_medium_indices))
  52. s.write("};\n")
  53. if thumb_big_indices:
  54. s.write("\n\n")
  55. s.write("static const int editor_bg_thumbs_count = %s;\n" % len(thumb_big_indices))
  56. s.write("static const int editor_bg_thumbs_indices[] = {")
  57. s.write(", ".join(thumb_big_indices))
  58. s.write("};\n")
  59. s.write("#endif\n")
  60. f = open(dst, "w")
  61. f.write(s.getvalue())
  62. f.close()
  63. s.close()
  64. icons_string.close()
  65. make_editor_icons_builder = Builder(action=make_editor_icons_action,
  66. suffix='.h',
  67. src_suffix='.svg')
  68. env['BUILDERS']['MakeEditorIconsBuilder'] = make_editor_icons_builder
  69. env.Alias('editor_icons', [env.MakeEditorIconsBuilder('#editor/editor_icons.gen.h', Glob("*.svg"))])
  70. Export('env')