def _write_header(paths): hh_file_name = paths.resource_id_hh with open(hh_file_name, 'w') as hh_file: hh_file.write('// Generated by %s\n' % os.path.basename(__file__)) hh_file.write('#ifndef %s\n' % util.create_include_guard(hh_file_name)) hh_file.write('#define %s\n' % util.create_include_guard(hh_file_name)) hh_file.write("\n") hh_file.write("namespace faint{\n"); hh_file.write("\n"); hh_file.write("enum class Cursor{\n") cursor_labels = _cursor_labels(paths) cursor_labels.append('DONT_CARE') cursor_labels.extend(DEFAULT_CURSORS.keys()) cursor_labels = sorted(cursor_labels) hh_file.write(' ' + ',\n '.join(cursor_labels) + '\n') hh_file.write('};\n') hh_file.write('\n') hh_file.write('enum class Icon{\n') icon_labels, icon_paths = _icon_labels(paths) for num, (label, path) in enumerate(zip(icon_labels, icon_paths)): last = num == len(icon_labels) - 1 hh_file.write(_icon_entry(2, last, label, path, ENABLE_EMACS_IIMAGE)) hh_file.write('};\n') hh_file.write('\n') hh_file.write("} // namespace\n"); hh_file.write('\n') hh_file.write('#endif')
def _write_header(paths): hh_file_name = paths.resource_id_hh with open(hh_file_name, 'w') as hh_file: hh_file.write('// Generated by %s\n' % os.path.basename(__file__)) hh_file.write('#ifndef %s\n' % util.create_include_guard(hh_file_name)) hh_file.write('#define %s\n' % util.create_include_guard(hh_file_name)) hh_file.write("\n") hh_file.write("namespace faint{\n") hh_file.write("\n") hh_file.write("enum class Cursor{\n") cursor_labels = _cursor_labels(paths) cursor_labels.append('DONT_CARE') cursor_labels.extend(DEFAULT_CURSORS.keys()) cursor_labels = sorted(cursor_labels) hh_file.write(' ' + ',\n '.join(cursor_labels) + '\n') hh_file.write('};\n') hh_file.write('\n') hh_file.write('enum class Icon{\n') icon_labels, icon_paths = _icon_labels(paths) for num, (label, path) in enumerate(zip(icon_labels, icon_paths)): last = num == len(icon_labels) - 1 hh_file.write( _icon_entry(2, last, label, path, ENABLE_EMACS_IIMAGE)) hh_file.write('};\n') hh_file.write('\n') hh_file.write("} // namespace\n") hh_file.write('\n') hh_file.write('#endif')
def _write_header(paths): hh_file_name = paths.resource_id_hh hh_file = open(hh_file_name, 'w') hh_file.write('// Generated by %s\n' % os.path.basename(__file__)) hh_file.write('#ifndef %s\n' % util.create_include_guard(hh_file_name)) hh_file.write('#define %s\n' % util.create_include_guard(hh_file_name)) hh_file.write("\n") hh_file.write("namespace faint{\n") hh_file.write("\n") hh_file.write("enum class Cursor{\n") cursor_labels = _cursor_labels(paths) cursor_labels.append('DONT_CARE') cursor_labels.extend(DEFAULT_CURSORS.keys()) cursor_labels = sorted(cursor_labels) hh_file.write(' ' + ',\n '.join(cursor_labels) + '\n') hh_file.write('};\n') hh_file.write('\n') hh_file.write('enum class Icon{\n') icon_labels = _icon_labels(paths) hh_file.write(' ' + ',\n '.join(icon_labels) + '\n') hh_file.write('};\n') hh_file.write('\n') hh_file.write("} // namespace\n") hh_file.write('\n') hh_file.write('#endif')
def write_cpp_header(file_name, settings): out = open(file_name, 'w') out.write('// Generated by %s\n' % os.path.basename(__file__)) out.write('#ifndef %s\n' % util.create_include_guard(file_name)) out.write('#define %s\n' % util.create_include_guard(file_name)) out.write('#include "util/settings.hh"\n\n') out.write('\n') out.write('namespace faint{\n') for setting_id in sorted(settings.keys()): setting = settings[setting_id] if setting.get_type() == "stringtoint": write_cpp_stringtoint(out, setting) else: write_cpp_setting_decl(out, setting) out.write("\n") out.write("utf8_string setting_name(const UntypedSetting&);\n") out.write("utf8_string setting_name_pretty(const UntypedSetting&);\n") out.write("\n") out.write( "// Returns the name for this value if the IntSetting has names for values\n" ) out.write("// otherwise, just returns the value as a string\n") out.write("utf8_string value_string(const IntSetting&, int value);\n") out.write("\n") out.write('} // namespace\n') out.write("\n") out.write("#endif\n")
def _write_load_function(paths): with open(paths.target_cpp, 'w', newline='\n') as cpp_file: cpp_file.write('// Generated by %s\n' % os.path.basename(__file__)) cpp_file.write('#include "gui/art-container.hh"\n') cpp_file.write('#include "util-wx/file-path-util.hh"\n') cpp_file.write('\n') cpp_file.write('namespace faint{\n') cpp_file.write( 'void load_faint_resources(faint::ArtContainer& art) {\n') cpp_file.write('\n') cpp_file.write(' // Cursors\n') for cursor_file in _cursor_files(paths): res_id = _resource_identifier(cursor_file) cpp_file.write(' art.Load("%s", Cursor::%s);\n' % (cursor_file, res_id)) cpp_file.write('\n') cpp_file.write(' // Cursors (wx-defaults)\n') for cursorId in sorted(DEFAULT_CURSORS.keys()): cpp_file.write(' art.Add(wxCursor(%s), Cursor::%s);\n' % (DEFAULT_CURSORS[cursorId], cursorId)) cpp_file.write('\n') cpp_file.write(' // Icons\n') for icon_file in _icon_files(paths): cpp_file.write(' art.Load("%s", Icon::%s);\n' % (icon_file, _resource_identifier(icon_file))) cpp_file.write('}\n') cpp_file.write('} // namespace\n') with open(paths.target_hh, 'w') as hh_file: hh_file.write("// Generated by %s\n" % os.path.basename(__file__)) hh_file.write('#ifndef %s\n' % util.create_include_guard(paths.target_hh)) hh_file.write('#define %s\n' % util.create_include_guard(paths.target_hh)) hh_file.write("\n") hh_file.write('namespace faint{\n') hh_file.write("\n") hh_file.write('void load_faint_resources(ArtContainer&);\n') hh_file.write("\n") hh_file.write('} // namespace\n') hh_file.write("\n") hh_file.write('#endif\n')
def _write_load_function(paths): with open(paths.target_cpp, 'w', newline='\n') as cpp_file: cpp_file.write('// Generated by %s\n' % os.path.basename(__file__)) cpp_file.write('#include "generated/resource/gen-resource-id.hh"\n') cpp_file.write('#include "generated/resource/load-resources.hh"\n') cpp_file.write('#include "util-wx/file-path-util.hh"\n') cpp_file.write('\n') cpp_file.write('namespace faint{\n') cpp_file.write('void load_faint_resources(faint::Art& art){\n') cpp_file.write('\n') cpp_file.write(' // Cursors\n') for cursor_file in _cursor_files(paths): res_id = _resource_identifier(cursor_file) cpp_file.write(' art.Load("%s", Cursor::%s);\n' % (cursor_file, res_id)) cpp_file.write('\n') cpp_file.write(' // Cursors (wx-defaults)\n') for cursorId in sorted(DEFAULT_CURSORS.keys()): cpp_file.write(' art.Add(wxCursor(%s), Cursor::%s);\n' % ( DEFAULT_CURSORS[cursorId], cursorId)) cpp_file.write('\n') cpp_file.write(' // Icons\n') for icon_file in _icon_files(paths): cpp_file.write(' art.Load("%s", Icon::%s);\n' % (icon_file, _resource_identifier(icon_file))) cpp_file.write('}\n') cpp_file.write('} // namespace\n') with open(paths.target_hh, 'w') as hh_file: hh_file.write("// Generated by %s\n" % os.path.basename(__file__)) hh_file.write('#ifndef %s\n' % util.create_include_guard(paths.target_hh)) hh_file.write('#define %s\n' % util.create_include_guard(paths.target_hh)) hh_file.write('#include "gui/art.hh"\n') hh_file.write("\n") hh_file.write('namespace faint{\n') hh_file.write("\n") hh_file.write('void load_faint_resources(Art&);\n') hh_file.write("\n") hh_file.write('} // namespace\n') hh_file.write("\n") hh_file.write('#endif\n')
def run(root_dir, force=False): oldDir = os.getcwd() os.chdir(root_dir) sys.path.append(os.getcwd()) if not force and not _need_generate( "set_and_get.py", [os.path.join("templates", f) for f in os.listdir("templates")]): print(" Up to date.") os.chdir(oldDir) return print( "Generating: interface.hh, interface.cpp, generated_methods.hh, py_settings_setget.hh" ) Files.targetCC = open("output/interface.cpp", 'w') Files.targetHH = open("output/interface.hh", 'w') Files.targetSettingsHH = open("output/py_settings_setget.hh", 'w') # Write the preamble for f in Files.targetCC, Files.targetHH, Files.targetSettingsHH: f.write('// Generated by %s\n' % os.path.basename(__file__)) Files.targetHH.write('#ifndef %s\n' % util.create_include_guard('output/interface.hh')) Files.targetHH.write('#define %s\n' % util.create_include_guard('output/interface.hh')) Files.targetHH.write('\n') Files.targetHH.write('namespace faint{\n') Files.targetSettingsHH.write( '#ifndef %s\n' % util.create_include_guard('output/py_settings_setget.hh')) Files.targetSettingsHH.write( '#define %s\n' % util.create_include_guard('output/py_settings_setget.hh')) Files.targetSettingsHH.write("\n") Files.targetSettingsHH.write('namespace faint{\n') Files.targetCC.write('#include <string>\n') Files.targetCC.write('#include "python/py-include.hh"\n') Files.targetCC.write('#include "app/get-app-context.hh"\n') Files.targetCC.write('#include "util/settings.hh"\n') Files.targetCC.write('#include "util/setting-id.hh"\n') Files.targetCC.write('#include "util/canvas.hh"\n') Files.targetCC.write('\n\n') Files.targetCC.write('namespace faint{\n') # Collects all defined methods Defs.methodDef = [] Defs.settings_methodDef = [] # C++ code templates Texts.template_hh = open("templates/header_template.txt").readlines() Texts.template_int_cc = open("templates/int_template.txt").readlines() Texts.template_float_cc = open("templates/float_template.txt").readlines() Texts.template_stringtoint_cc = open( "templates/stringtoint_template.txt").readlines() Texts.template_settings_header = open( "templates/settings_header_template.txt").readlines() Texts.template_settings_float = open( "templates/settings_float_template.txt").readlines() Texts.template_settings_int = open( "templates/settings_int_template.txt").readlines() Texts.template_settings_color = open( "templates/settings_color_template.txt").readlines() Texts.template_settings_stringtoint = open( "templates/settings_stringtoint_template.txt").readlines() Texts.template_settings_bool = open( "templates/settings_bool_template.txt").readlines() Texts.template_settings_string = open( "templates/settings_string_template.txt").readlines() import set_and_get setters_and_getters = set_and_get.setters_and_getters for setting in setters_and_getters: item = setters_and_getters[setting] type = item.get_type() if type == "int": generate_int_function(setting, item) generate_int_settings_function(setting, item) elif type == "stringtoint": generate_stringtoint_function(setting, item) generate_stringtoint_settings_function(setting, item) elif type == "float": generate_float_function(setting, item) generate_float_settings_function(setting, item) elif type == "color": generate_color_settings_function(setting, item) elif type == "bool": generate_bool_settings_function(setting, item) elif type == "string": generate_string_settings_function(setting, item) # Create the python-export f_genMethods = open('output/generated-methods.hh', 'w') f_genMethods.write("#ifndef FAINT_GENERATED_METHODS_HH\n") f_genMethods.write("#define FAINT_GENERATED_METHODS_HH\n") f_genMethods.write('// Generated by %s\n' % os.path.basename(__file__)) for index, line in enumerate(Defs.methodDef): f_genMethods.write(' ' + line + ",\n") f_genMethods.write("#endif") Files.targetSettingsHH.write( "static PyGetSetDef settings_getseters[] = {\n") for line in Defs.settings_methodDef: Files.targetSettingsHH.write(line + ",\n") Files.targetSettingsHH.write(" {0,0,0,0,0} // Sentinel */\n") Files.targetSettingsHH.write("};\n") Files.targetSettingsHH.write('} // namespace\n') write_cpp_header("output/cpp_settingid.hh", setters_and_getters) write_cpp_impl("output/cpp_settingid.cpp", "cpp_settingid.hh", setters_and_getters) Files.targetHH.write("\n") Files.targetHH.write('} // namespace\n') Files.targetHH.write("#endif\n") Files.targetCC.write('} // namespace\n') # Close generated files Files.targetCC.close() Files.targetHH.close() Files.targetSettingsHH.write("\n") Files.targetSettingsHH.write("#endif") Files.targetSettingsHH.close() os.chdir(oldDir)