Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,146 additions
and
767 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# ==== Condition enum redefines ==== | ||
{{ parser.fields_of("ImGuiCond_") }} | ||
|
||
# ==== Style var enum redefines ==== | ||
{{ parser.fields_of("ImGuiStyleVar_", prefix="STYLE_") }} | ||
|
||
# ==== Key map enum redefines ==== | ||
{{ parser.fields_of("ImGuiKey_", prefix="KEY_") }} | ||
|
||
# ==== Window flags enum redefines ==== | ||
{{ parser.fields_of("ImGuiWindowFlags_", prefix="WINDOW_") }} | ||
|
||
# ==== TreeNode flags enum redefines ==== | ||
{{ parser.fields_of("ImGuiTreeNodeFlags_", prefix="TREE_NODE_") }} | ||
|
||
# ==== Selectable flags enum redefines ==== | ||
{{ parser.fields_of("ImGuiSelectableFlags_", prefix="SELECTABLE_") }} | ||
|
||
# ==== Combo flags enum redefines ==== | ||
{{ parser.fields_of("ImGuiComboFlags_", prefix="COMBO_") }} | ||
|
||
# === Focus flag enum redefines ==== | ||
{{ parser.fields_of("ImGuiFocusedFlags_", prefix="FOCUS_") }} | ||
|
||
# === Hovered flag enum redefines ==== | ||
{{ parser.fields_of("ImGuiHoveredFlags_", prefix="HOVERED_") }} | ||
|
||
# === Drag Drop flag enum redefines ==== | ||
{{ parser.fields_of("ImGuiDragDropFlags_", prefix="DRAG_DROP_") }} | ||
|
||
# === Cardinal Direction enum redefines ==== | ||
{{ parser.fields_of("ImGuiDir_", prefix="DIRECTION_") }} | ||
|
||
# ==== Mouse Cursors ==== | ||
{{ parser.fields_of("ImGuiMouseCursor_", prefix="MOUSE_CURSOR_") }} | ||
|
||
# ==== Color identifiers for styling ==== | ||
{{ parser.fields_of("ImGuiCol_", prefix="COLOR_") }} | ||
|
||
# ==== Text input flags ==== | ||
{{ parser.fields_of("ImGuiInputTextFlags_", prefix="INPUT_TEXT") }} | ||
|
||
# ==== Config Flags ==== | ||
{{ parser.fields_of("ImGuiConfigFlags_", prefix="CONFIG_") }} | ||
|
||
# ==== Backend Flags ==== | ||
{{ parser.fields_of("ImGuiBackendFlags_", prefix="BACKEND_") }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
cdef extern from "imgui.h": | ||
ctypedef enum ImGuiKey_: | ||
{{ parser.fields_of("ImGuiKey_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiNavInput_: | ||
{{ parser.fields_of("ImGuiNavInput_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiConfigFlags_: | ||
{{ parser.fields_of("ImGuiConfigFlags_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiBackendFlags_: | ||
{{ parser.fields_of("ImGuiBackendFlags_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiCol_: | ||
{{ parser.fields_of("ImGuiCol_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiDataType_: | ||
{{ parser.fields_of("ImGuiDataType_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiStyleVar_: | ||
{{ parser.fields_of("ImGuiStyleVar_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiCond_: | ||
{{ parser.fields_of("ImGuiCond_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiWindowFlags_: | ||
{{ parser.fields_of("ImGuiWindowFlags_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiColorEditFlags_: | ||
{{ parser.fields_of("ImGuiColorEditFlags_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiTreeNodeFlags_: | ||
{{ parser.fields_of("ImGuiTreeNodeFlags_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiSelectableFlags_: | ||
{{ parser.fields_of("ImGuiSelectableFlags_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiComboFlags_: | ||
{{ parser.fields_of("ImGuiComboFlags_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiFocusedFlags_: | ||
{{ parser.fields_of("ImGuiFocusedFlags_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiHoveredFlags_: | ||
{{ parser.fields_of("ImGuiHoveredFlags_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiDragDropFlags_: | ||
{{ parser.fields_of("ImGuiDragDropFlags_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiDir_: | ||
{{ parser.fields_of("ImGuiDir_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiMouseCursor_: | ||
{{ parser.fields_of("ImGuiMouseCursor_") | indent(8)}} | ||
|
||
ctypedef enum ImGuiInputTextFlags_: | ||
{{ parser.fields_of("ImGuiInputTextFlags_") | indent(8)}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import os | ||
import re | ||
|
||
import click | ||
import inflection | ||
|
||
import jinja2 | ||
|
||
loader = jinja2.FileSystemLoader(searchpath="./") | ||
env = jinja2.Environment(loader=loader) | ||
base_dir = os.path.dirname(__file__) | ||
|
||
|
||
def extract_comment(line): | ||
parts = line.split("//") | ||
if len(parts) > 1: | ||
return "//".join(map(str.strip, parts[1:])) | ||
else: | ||
return "" | ||
|
||
|
||
def pxd_format(field, comment, max_len): | ||
if comment: | ||
return field + " " * (max_len - len(field) + 2) + "# " + comment | ||
else: | ||
return field | ||
|
||
|
||
def pyx_format(field, comment, max_len, prefix=""): | ||
key = inflection.underscore(field.split("_", 1)[-1]).upper() | ||
|
||
return "{prefix}{key} = enums.{field}{comment}".format( | ||
prefix=prefix, key=key, field=field, | ||
comment=" # " + comment if comment else "" | ||
) | ||
|
||
|
||
def py_format(field, comment, max_len, prefix=""): | ||
key = inflection.underscore(field.split("_", 1)[-1]).upper() | ||
|
||
return "{comment}{prefix}{key} = core.{prefix}{key}".format( | ||
prefix=prefix, key=key, | ||
comment="#: " + comment + "\n" if comment else "" | ||
) | ||
|
||
|
||
class EnumParser: | ||
FIELD_RE_TEMPLATE = r"\s+({name}_?\w+)[,\s=]?" | ||
|
||
def __init__(self, header_file, formatter): | ||
self.formatter = formatter | ||
|
||
with open(header_file) as f: | ||
self.contents = f.readlines() | ||
|
||
def fields_of(self, name, **format_kwargs): | ||
fields = [] | ||
started = False | ||
regexp = re.compile(self.FIELD_RE_TEMPLATE.format(name=name)) | ||
|
||
for line in self.contents: | ||
if not started and line.startswith("enum {}".format(name)): | ||
started = True | ||
continue | ||
elif started and "}" in line: | ||
break | ||
elif started: | ||
match = regexp.match(line) | ||
if match: | ||
comment = extract_comment(line) | ||
field = match.groups()[0] | ||
fields.append((field, comment)) | ||
|
||
max_len = max(map(lambda x: len(x[0]), fields)) | ||
out_lines = [] | ||
|
||
for field, comment in fields: | ||
out_lines.append(self.formatter(field, comment, max_len, **format_kwargs)) | ||
|
||
return "\n".join(out_lines) | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
pass | ||
|
||
|
||
@cli.command() | ||
def pxd(): | ||
template = env.get_template(os.path.join(base_dir, "enums.pxd.jinja2")) | ||
parser = EnumParser(os.path.join(base_dir, "..", "imgui-cpp", "imgui.h"), pxd_format) | ||
click.echo(template.render(parser=parser)) | ||
|
||
|
||
@cli.command() | ||
def py(): | ||
template = env.get_template(os.path.join(base_dir, "flags.py.jinja2")) | ||
parser = EnumParser(os.path.join(base_dir, "..", "imgui-cpp", "imgui.h"), py_format) | ||
click.echo(template.render(parser=parser)) | ||
|
||
|
||
@cli.command() | ||
def pyx(): | ||
template = env.get_template(os.path.join(base_dir, "core.pyx.jinja2")) | ||
parser = EnumParser(os.path.join(base_dir, "..", "imgui-cpp", "imgui.h"), pyx_format) | ||
click.echo(template.render(parser=parser)) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from imgui import core | ||
|
||
# ==== Condition enum redefines ==== | ||
{{ parser.fields_of("ImGuiCond_") }} | ||
|
||
# ==== Style var enum redefines ==== | ||
{{ parser.fields_of("ImGuiStyleVar_", prefix="STYLE_") }} | ||
|
||
# ==== Key map enum redefines ==== | ||
{{ parser.fields_of("ImGuiKey_", prefix="KEY_") }} | ||
|
||
# ==== Window flags enum redefines ==== | ||
{{ parser.fields_of("ImGuiWindowFlags_", prefix="WINDOW_") }} | ||
|
||
# ==== TreeNode flags enum redefines ==== | ||
{{ parser.fields_of("ImGuiTreeNodeFlags_", prefix="TREE_NODE_") }} | ||
|
||
# ==== Selectable flags enum redefines ==== | ||
{{ parser.fields_of("ImGuiSelectableFlags_", prefix="SELECTABLE_") }} | ||
|
||
# ==== Combo flags enum redefines ==== | ||
{{ parser.fields_of("ImGuiComboFlags_", prefix="COMBO_") }} | ||
|
||
# === Focus flag enum redefines ==== | ||
{{ parser.fields_of("ImGuiFocusedFlags_", prefix="FOCUS_") }} | ||
|
||
# === Hovered flag enum redefines ==== | ||
{{ parser.fields_of("ImGuiHoveredFlags_", prefix="HOVERED_") }} | ||
|
||
# === Drag Drop flag enum redefines ==== | ||
{{ parser.fields_of("ImGuiDragDropFlags_", prefix="DRAG_DROP_") }} | ||
|
||
# === Cardinal Direction enum redefines ==== | ||
{{ parser.fields_of("ImGuiDir_", prefix="DIRECTION_") }} | ||
|
||
# ==== Mouse Cursors ==== | ||
{{ parser.fields_of("ImGuiMouseCursor_", prefix="MOUSE_CURSOR_") }} | ||
|
||
# ==== Color identifiers for styling ==== | ||
{{ parser.fields_of("ImGuiCol_", prefix="COLOR_") }} | ||
|
||
# ==== Text input flags ==== | ||
{{ parser.fields_of("ImGuiInputTextFlags_", prefix="INPUT_TEXT") }} | ||
|
||
# ==== Config Flags ==== | ||
{{ parser.fields_of("ImGuiConfigFlags_", prefix="CONFIG_") }} | ||
|
||
# ==== Backend Flags ==== | ||
{{ parser.fields_of("ImGuiBackendFlags_", prefix="BACKEND_") }} |