Ara-imgui 3.0.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ara_imgui/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ from . import flags, imgui
2
+ from .app import App
3
+ from .theme import IMGUI_THEMES, Theme, themes
4
+
5
+ __all__ = ['App', 'flags', 'imgui', 'Theme', 'themes', 'IMGUI_THEMES']
ara_imgui/_binding.py ADDED
@@ -0,0 +1,345 @@
1
+ """ctypes loader for the native ``ara_imgui`` library.
2
+
3
+ This module is the only place that knows how the shared library is found and
4
+ how its C entry points are declared. It uses :mod:`ctypes` from the standard
5
+ library exclusively: importing ``ara_imgui`` must never require a compiled
6
+ extension or a third-party pip package.
7
+
8
+ The library is loaded lazily, on the first call into it, so that tools which
9
+ only inspect the Python API keep working on machines where the native part has
10
+ not been built yet.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import ctypes
16
+ import os
17
+ import sys
18
+ from pathlib import Path
19
+ from typing import Any
20
+
21
+ from ._generated import functions as _c_functions
22
+ from ._generated import structs as _structs
23
+
24
+ __all__ = [
25
+ "FUNCTIONS",
26
+ "CFunction",
27
+ "ImVec2",
28
+ "ImVec4",
29
+ "NativeError",
30
+ "NativeLibraryNotFound",
31
+ "clear_error",
32
+ "create_context",
33
+ "destroy_context",
34
+ "draw_list_count",
35
+ "function",
36
+ "get_draw_data",
37
+ "get_frame_count",
38
+ "get_io",
39
+ "get_main_viewport",
40
+ "is_available",
41
+ "is_item_edited",
42
+ "last_error",
43
+ "library_path",
44
+ "new_frame",
45
+ "new_frame_headless",
46
+ "render",
47
+ "render_frame",
48
+ "version",
49
+ ]
50
+
51
+ #: The generated C function table: exported symbol -> ctypes signature.
52
+ FUNCTIONS = _c_functions.FUNCTIONS
53
+ CFunction = _c_functions.CFunction
54
+
55
+ ImVec2 = _structs.ImVec2
56
+ ImVec4 = _structs.ImVec4
57
+ ImGuiIO = _structs.ImGuiIO
58
+ ImGuiViewport = _structs.ImGuiViewport
59
+ ImDrawData = _structs.ImDrawData
60
+
61
+
62
+ #: Environment variable that overrides the library search path. It is meant
63
+ #: for development (e.g. pointing at a build directory) and for CI.
64
+ LIBRARY_PATH_ENV = "ARA_IMGUI_NATIVE_LIBRARY"
65
+
66
+ _LIBRARY_FILE_NAMES = {
67
+ "win32": "ara_imgui.dll",
68
+ "darwin": "ara_imgui.dylib",
69
+ }
70
+ _DEFAULT_LIBRARY_FILE_NAME = "ara_imgui.so"
71
+
72
+
73
+ class NativeError(RuntimeError):
74
+ """A native call failed; the message comes from ``ara_last_error()``."""
75
+
76
+
77
+ class NativeLibraryNotFound(NativeError):
78
+ """The platform library is missing or cannot be loaded."""
79
+
80
+
81
+ def library_path() -> Path:
82
+ """Return the expected location of the native library.
83
+
84
+ ``ARA_IMGUI_NATIVE_LIBRARY`` takes precedence; otherwise the library is
85
+ looked up in the ``_native`` directory next to this module, where the CMake
86
+ build places it (and where the wheel ships it).
87
+ """
88
+ override = os.environ.get(LIBRARY_PATH_ENV)
89
+ if override:
90
+ return Path(override).expanduser()
91
+
92
+ file_name = _LIBRARY_FILE_NAMES.get(sys.platform, _DEFAULT_LIBRARY_FILE_NAME)
93
+ return Path(__file__).resolve().parent / "_native" / file_name
94
+
95
+
96
+ def is_available() -> bool:
97
+ """Return ``True`` when the native library file exists."""
98
+ return library_path().is_file()
99
+
100
+
101
+ _library: ctypes.CDLL | None = None
102
+
103
+ #: C signature of the per-frame callback owned by ``ara_run``.
104
+ FrameCallback = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p)
105
+
106
+
107
+ def _configure(lib: ctypes.CDLL) -> None:
108
+ """Apply every ctypes signature from the generated table.
109
+
110
+ The table is the single source of truth for the C ABI; declaring it here
111
+ (instead of hand-writing ``argtypes`` per call) keeps the Python side in
112
+ sync with the vendored cimgui headers. A symbol that the table promises
113
+ but the shared library does not export means the native build and the
114
+ generated files disagree, so loading fails with a precise message.
115
+ """
116
+ missing: list[str] = []
117
+ for entry in FUNCTIONS.values():
118
+ try:
119
+ native = getattr(lib, entry.name)
120
+ except AttributeError:
121
+ missing.append(entry.name)
122
+ continue
123
+ native.argtypes = list(entry.argtypes)
124
+ native.restype = entry.ret
125
+
126
+ if missing:
127
+ preview = ", ".join(missing[:8])
128
+ if len(missing) > 8:
129
+ preview += f", ... ({len(missing)} total)"
130
+ raise NativeLibraryNotFound(
131
+ "the native library does not export functions declared in "
132
+ f"_generated/functions.py: {preview}. Rebuild it with "
133
+ "'python tools/build_native.py'."
134
+ )
135
+
136
+ lib.ara_version.argtypes = []
137
+ lib.ara_version.restype = ctypes.c_char_p
138
+
139
+ lib.ara_last_error.argtypes = []
140
+ lib.ara_last_error.restype = ctypes.c_char_p
141
+
142
+ lib.ara_clear_error.argtypes = []
143
+ lib.ara_clear_error.restype = None
144
+
145
+ lib.ara_create_context.argtypes = []
146
+ lib.ara_create_context.restype = ctypes.c_void_p
147
+
148
+ lib.ara_destroy_context.argtypes = [ctypes.c_void_p]
149
+ lib.ara_destroy_context.restype = None
150
+
151
+ lib.ara_new_frame_headless.argtypes = [
152
+ ctypes.c_float,
153
+ ctypes.c_float,
154
+ ctypes.c_float,
155
+ ]
156
+ lib.ara_new_frame_headless.restype = ctypes.c_bool
157
+
158
+ lib.ara_render.argtypes = []
159
+ lib.ara_render.restype = ctypes.c_bool
160
+
161
+ lib.ara_draw_list_count.argtypes = []
162
+ lib.ara_draw_list_count.restype = ctypes.c_int
163
+
164
+ lib.ara_run.argtypes = [
165
+ ctypes.c_char_p,
166
+ ctypes.c_int,
167
+ ctypes.c_int,
168
+ ctypes.c_int,
169
+ ctypes.c_char_p,
170
+ ctypes.c_float,
171
+ ctypes.c_char_p,
172
+ FrameCallback,
173
+ ctypes.c_void_p,
174
+ ]
175
+ lib.ara_run.restype = ctypes.c_int
176
+
177
+
178
+ def _get_library() -> ctypes.CDLL:
179
+ global _library
180
+
181
+ if _library is not None:
182
+ return _library
183
+
184
+ path = library_path()
185
+ if not path.is_file():
186
+ raise NativeLibraryNotFound(
187
+ f"native library not found: {path}\n"
188
+ f"Build it with 'python tools/build_native.py', or set "
189
+ f"{LIBRARY_PATH_ENV} to an existing library."
190
+ )
191
+
192
+ try:
193
+ lib = ctypes.CDLL(str(path))
194
+ except OSError as exc:
195
+ raise NativeLibraryNotFound(
196
+ f"failed to load native library {path}: {exc}"
197
+ ) from exc
198
+
199
+ _configure(lib)
200
+ _library = lib
201
+ return lib
202
+
203
+
204
+ def _decode(value: bytes | None) -> str:
205
+ if not value:
206
+ return ""
207
+ return value.decode("utf-8", "replace")
208
+
209
+
210
+ def _last_error_message() -> str:
211
+ return _decode(_get_library().ara_last_error())
212
+
213
+
214
+ def _raise_native_error(fallback: str) -> None:
215
+ message = _last_error_message() or fallback
216
+ _get_library().ara_clear_error()
217
+ raise NativeError(message)
218
+
219
+
220
+ def version() -> str:
221
+ """Return the Dear ImGui version compiled into the library."""
222
+ return _decode(_get_library().ara_version())
223
+
224
+
225
+ def last_error() -> str:
226
+ """Return the message of the last native failure, or ``""``."""
227
+ return _last_error_message()
228
+
229
+
230
+ def clear_error() -> None:
231
+ """Drop the last native error message."""
232
+ _get_library().ara_clear_error()
233
+
234
+
235
+ def create_context() -> int:
236
+ """Create a Dear ImGui context and make it current.
237
+
238
+ The returned integer is an opaque ``ImGuiContext*``. Pass it to
239
+ :func:`destroy_context` when done.
240
+ """
241
+ lib = _get_library()
242
+ context = lib.ara_create_context()
243
+ if not context:
244
+ _raise_native_error("ara_create_context() failed")
245
+ return int(context)
246
+
247
+
248
+ def destroy_context(context: int | None) -> None:
249
+ """Destroy a context created by :func:`create_context`.
250
+
251
+ ``None`` is accepted and ignored.
252
+ """
253
+ if context is None:
254
+ return
255
+
256
+ lib = _get_library()
257
+ lib.ara_destroy_context(ctypes.c_void_p(context))
258
+ error = _decode(lib.ara_last_error())
259
+ if error:
260
+ lib.ara_clear_error()
261
+ raise NativeError(error)
262
+
263
+
264
+ def function(name: str) -> Any:
265
+ """Return the configured ctypes function for an exported C symbol."""
266
+ return getattr(_get_library(), name)
267
+
268
+
269
+ def _struct_view(cls: type, pointer: int | None, caller: str) -> Any:
270
+ """Cast an opaque ``T*`` returned by cimgui to a ctypes struct view."""
271
+ if not pointer:
272
+ _raise_native_error(f"{caller}() returned null")
273
+ return ctypes.cast(ctypes.c_void_p(pointer), ctypes.POINTER(cls)).contents
274
+
275
+
276
+ def get_io() -> _structs.ImGuiIO:
277
+ """Return the current context's ``ImGuiIO`` as a mutable struct view."""
278
+ pointer = _get_library().igGetIO_Nil()
279
+ return _struct_view(_structs.ImGuiIO, pointer, "igGetIO_Nil")
280
+
281
+
282
+ def get_main_viewport() -> _structs.ImGuiViewport:
283
+ """Return the main viewport of the current context."""
284
+ pointer = _get_library().igGetMainViewport()
285
+ return _struct_view(_structs.ImGuiViewport, pointer, "igGetMainViewport")
286
+
287
+
288
+ def get_draw_data() -> _structs.ImDrawData | None:
289
+ """Return the last frame's ``ImDrawData``, or ``None`` before rendering."""
290
+ pointer = _get_library().igGetDrawData()
291
+ if not pointer:
292
+ return None
293
+ return _struct_view(_structs.ImDrawData, pointer, "igGetDrawData")
294
+
295
+
296
+ def get_frame_count() -> int:
297
+ """Return the number of frames submitted to the current context."""
298
+ return int(_get_library().igGetFrameCount())
299
+
300
+
301
+ def is_item_edited() -> bool:
302
+ """Return ``ImGui::IsItemEdited()`` for the last submitted item."""
303
+ return bool(_get_library().igIsItemEdited())
304
+
305
+
306
+ def new_frame() -> None:
307
+ """Start a new Dear ImGui frame (``ImGui::NewFrame``)."""
308
+ _get_library().igNewFrame()
309
+
310
+
311
+ def render_frame() -> None:
312
+ """Finish the frame and build draw data (``ImGui::Render``)."""
313
+ _get_library().igRender()
314
+
315
+
316
+ def new_frame_headless(
317
+ width: float,
318
+ height: float,
319
+ delta_time: float = 1.0 / 60.0,
320
+ ) -> None:
321
+ """Start a frame without a window, using a synthetic display size."""
322
+ lib = _get_library()
323
+ ok = lib.ara_new_frame_headless(
324
+ ctypes.c_float(width),
325
+ ctypes.c_float(height),
326
+ ctypes.c_float(delta_time),
327
+ )
328
+ if not ok:
329
+ _raise_native_error("ara_new_frame_headless() failed")
330
+
331
+
332
+ def render() -> None:
333
+ """Finish the current frame and build the draw data."""
334
+ lib = _get_library()
335
+ if not lib.ara_render():
336
+ _raise_native_error("ara_render() failed")
337
+
338
+
339
+ def draw_list_count() -> int:
340
+ """Return ``ImDrawData.CmdListsCount`` for the last rendered frame."""
341
+ lib = _get_library()
342
+ count = lib.ara_draw_list_count()
343
+ if count < 0:
344
+ _raise_native_error("ara_draw_list_count() failed")
345
+ return int(count)
ara_imgui/_enums.py ADDED
@@ -0,0 +1,141 @@
1
+ """Public flag enums with the ``imgui_bundle`` snake_case spellings.
2
+
3
+ The generated ``_generated/enums.py`` module mirrors cimgui and keeps the
4
+ original C member names (``ImGuiWindowFlags_NoTitleBar``). The public API uses
5
+ only the snake_case spellings, so ``_generated/public_enums.py`` declares every
6
+ public group with those members and this module re-exports the classes under
7
+ the short names used by ``ara_imgui.flags``. ``flags.window`` and
8
+ ``imgui.WindowFlags_`` therefore refer to the same public class.
9
+
10
+ C member names remain available only in the low-level ``_generated.enums``
11
+ module, not on the public classes.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import re
17
+
18
+ from ._generated import public_enums as _public_enums
19
+
20
+ __all__ = [
21
+ "GROUPS",
22
+ "BackendFlags_",
23
+ "ButtonFlags_",
24
+ "ChildFlags_",
25
+ "ColorEditFlags_",
26
+ "ComboFlags_",
27
+ "ConfigFlags_",
28
+ "DockNodeFlags_",
29
+ "DragDropFlags_",
30
+ "FocusedFlags_",
31
+ "FontAtlasFlags_",
32
+ "FontFlags_",
33
+ "HoveredFlags_",
34
+ "ImDrawFlags_",
35
+ "ImDrawListFlags_",
36
+ "InputFlags_",
37
+ "InputTextFlags_",
38
+ "ItemFlags_",
39
+ "ListClipperFlags_",
40
+ "MultiSelectFlags_",
41
+ "PopupFlags_",
42
+ "SelectableFlags_",
43
+ "SliderFlags_",
44
+ "TabBarFlags_",
45
+ "TabItemFlags_",
46
+ "TableColumnFlags_",
47
+ "TableFlags_",
48
+ "TableRowFlags_",
49
+ "TreeNodeFlags_",
50
+ "ViewportFlags_",
51
+ "WindowFlags_",
52
+ ]
53
+
54
+
55
+ def _snake_case(name: str) -> str:
56
+ """Convert a C enum member suffix to the ``imgui_bundle`` spelling."""
57
+ name = re.sub(r"(.)([A-Z][a-z]+)", r"\1_\2", name)
58
+ name = re.sub(r"([a-z0-9])([A-Z])", r"\1_\2", name)
59
+ return name.lower()
60
+
61
+
62
+ #: Public group name -> generated cimgui enum class. ``flags`` exposes the
63
+ #: public classes from ``_generated.public_enums`` under these group names.
64
+ GROUPS: dict[str, str] = {
65
+ # Windows and containers
66
+ "window": "ImGuiWindowFlags_",
67
+ "child": "ImGuiChildFlags_",
68
+ "popup": "ImGuiPopupFlags_",
69
+ # Widgets
70
+ "button": "ImGuiButtonFlags_",
71
+ "combo": "ImGuiComboFlags_",
72
+ "input": "ImGuiInputFlags_",
73
+ "input_text": "ImGuiInputTextFlags_",
74
+ "item": "ImGuiItemFlags_",
75
+ "list_clipper": "ImGuiListClipperFlags_",
76
+ "multi_select": "ImGuiMultiSelectFlags_",
77
+ "selectable": "ImGuiSelectableFlags_",
78
+ "slider": "ImGuiSliderFlags_",
79
+ "tree_node": "ImGuiTreeNodeFlags_",
80
+ # Tables and tabs
81
+ "table": "ImGuiTableFlags_",
82
+ "table_column": "ImGuiTableColumnFlags_",
83
+ "table_row": "ImGuiTableRowFlags_",
84
+ "tab_bar": "ImGuiTabBarFlags_",
85
+ "tab_item": "ImGuiTabItemFlags_",
86
+ # Interaction and state
87
+ "config": "ImGuiConfigFlags_",
88
+ "focused": "ImGuiFocusedFlags_",
89
+ "hovered": "ImGuiHoveredFlags_",
90
+ "drag_drop": "ImGuiDragDropFlags_",
91
+ "color_edit": "ImGuiColorEditFlags_",
92
+ "dock_node": "ImGuiDockNodeFlags_",
93
+ "viewport": "ImGuiViewportFlags_",
94
+ "backend": "ImGuiBackendFlags_",
95
+ # Drawing and fonts
96
+ "draw": "ImDrawFlags_",
97
+ "draw_list": "ImDrawListFlags_",
98
+ "font": "ImFontFlags_",
99
+ "font_atlas": "ImFontAtlasFlags_",
100
+ }
101
+
102
+ # Public names without the ``ImGui`` prefix where applicable, matching
103
+ # imgui_bundle's classes. The generated classes keep the C names (their
104
+ # ``__name__`` is ``ImGuiWindowFlags_``), so type checkers and ``repr`` show the
105
+ # familiar cimgui spelling.
106
+ WindowFlags_ = _public_enums.ImGuiWindowFlags_
107
+ ChildFlags_ = _public_enums.ImGuiChildFlags_
108
+ PopupFlags_ = _public_enums.ImGuiPopupFlags_
109
+ ButtonFlags_ = _public_enums.ImGuiButtonFlags_
110
+ ComboFlags_ = _public_enums.ImGuiComboFlags_
111
+ InputFlags_ = _public_enums.ImGuiInputFlags_
112
+ InputTextFlags_ = _public_enums.ImGuiInputTextFlags_
113
+ ItemFlags_ = _public_enums.ImGuiItemFlags_
114
+ ListClipperFlags_ = _public_enums.ImGuiListClipperFlags_
115
+ MultiSelectFlags_ = _public_enums.ImGuiMultiSelectFlags_
116
+ SelectableFlags_ = _public_enums.ImGuiSelectableFlags_
117
+ SliderFlags_ = _public_enums.ImGuiSliderFlags_
118
+ TreeNodeFlags_ = _public_enums.ImGuiTreeNodeFlags_
119
+ TableFlags_ = _public_enums.ImGuiTableFlags_
120
+ TableColumnFlags_ = _public_enums.ImGuiTableColumnFlags_
121
+ TableRowFlags_ = _public_enums.ImGuiTableRowFlags_
122
+ TabBarFlags_ = _public_enums.ImGuiTabBarFlags_
123
+ TabItemFlags_ = _public_enums.ImGuiTabItemFlags_
124
+ ConfigFlags_ = _public_enums.ImGuiConfigFlags_
125
+ FocusedFlags_ = _public_enums.ImGuiFocusedFlags_
126
+ HoveredFlags_ = _public_enums.ImGuiHoveredFlags_
127
+ DragDropFlags_ = _public_enums.ImGuiDragDropFlags_
128
+ ColorEditFlags_ = _public_enums.ImGuiColorEditFlags_
129
+ DockNodeFlags_ = _public_enums.ImGuiDockNodeFlags_
130
+ ViewportFlags_ = _public_enums.ImGuiViewportFlags_
131
+ BackendFlags_ = _public_enums.ImGuiBackendFlags_
132
+ ImDrawFlags_ = _public_enums.ImDrawFlags_
133
+ ImDrawListFlags_ = _public_enums.ImDrawListFlags_
134
+ FontFlags_ = _public_enums.ImFontFlags_
135
+ FontAtlasFlags_ = _public_enums.ImFontAtlasFlags_
136
+
137
+ # ``GROUP_CLASSES`` maps the public group names to the actual public classes
138
+ # used by ``flags`` and ``_raw``.
139
+ GROUP_CLASSES: dict[str, type] = {
140
+ name: getattr(_public_enums, class_name) for name, class_name in GROUPS.items()
141
+ }
@@ -0,0 +1,8 @@
1
+ """Generated by tools/generate_bindings.py from vendor/cimgui. DO NOT EDIT.
2
+
3
+ Low-level ctypes definitions for the native cimgui ABI.
4
+ """
5
+
6
+ from . import enums, functions, public_enums, structs
7
+
8
+ __all__ = ["enums", "functions", "public_enums", "structs"]