11# Part of ImGui Bundle - MIT License - Copyright (c) 2022-2026 Pascal Thomet - https://github.com/pthom/imgui_bundle
22import os
3+ import sys
34
45# Workaround for PyOpenGL 3.1.6+ on Wayland: GLFW uses X11/XWayland, but PyOpenGL
56# assumes Wayland EGL and fails to find the GL context. Force X11 backend.
910 os .environ ["PYOPENGL_PLATFORM" ] = "x11"
1011from imgui_bundle ._imgui_bundle import __bundle_submodules_available__ , __bundle_submodules_disabled__ , __bundle_pyodide__ # type: ignore
1112from imgui_bundle ._imgui_bundle import __version__ , __build_number__ , compilation_time
13+ from types import ModuleType
1214from typing import Union , Tuple , List , overload
1315
14- def has_submodule (submodule_name ) :
16+ def has_submodule (submodule_name : str ) -> bool :
1517 return submodule_name in __bundle_submodules_available__
1618
1719
20+ def _publish (name : str , module : ModuleType ) -> None :
21+ """Expose a native submodule under `imgui_bundle.<name>` in sys.modules.
22+
23+ Enables `from imgui_bundle.<name> import ...` in addition to the
24+ existing `from imgui_bundle import <name>`. Without this, the native
25+ module's fully-qualified name stays `imgui_bundle._imgui_bundle.<name>`,
26+ which is what `sys.modules` keys on — the public path isn't registered.
27+ """
28+ sys .modules [f"imgui_bundle.{ name } " ] = module
29+
30+
1831def info () -> str :
1932 """Return information about imgui_bundle: version, compilation time, and available submodules.
2033
@@ -71,6 +84,11 @@ def _is_pydantic_v2_available() -> bool:
7184#
7285if has_submodule ("imgui" ):
7386 from imgui_bundle ._imgui_bundle import imgui as imgui
87+ _publish ("imgui" , imgui )
88+ _publish ("imgui.internal" , imgui .internal )
89+ _publish ("imgui.backends" , imgui .backends )
90+ if has_submodule ("imgui.test_engine" ):
91+ _publish ("imgui.test_engine" , imgui .test_engine )
7492 from imgui_bundle ._imgui_bundle .imgui import ImVec2 , ImVec4 , ImColor , FLT_MIN , FLT_MAX # noqa: F401
7593 from imgui_bundle .im_col32 import IM_COL32 # noqa: F401, E402
7694 from imgui_bundle import imgui_ctx as imgui_ctx # noqa: E402
@@ -141,9 +159,11 @@ def em_to_vec2(x, y=None) -> ImVec2:
141159
142160if has_submodule ("hello_imgui" ):
143161 from imgui_bundle ._imgui_bundle import hello_imgui as hello_imgui
162+ _publish ("hello_imgui" , hello_imgui )
144163 __all__ .extend (["hello_imgui" ])
145164if has_submodule ("implot" ):
146165 from imgui_bundle ._imgui_bundle import implot as implot
166+ _publish ("implot" , implot )
147167 __all__ .extend (["implot" ])
148168 # Flag types for ImPlot
149169 implot .LineFlags = int # see implot.LineFlags_
@@ -155,25 +175,32 @@ def em_to_vec2(x, y=None) -> ImVec2:
155175 implot .HistogramFlags = int # see implot.HistogramFlags_
156176if has_submodule ("implot3d" ):
157177 from imgui_bundle ._imgui_bundle import implot3d as implot3d
178+ _publish ("implot3d" , implot3d )
158179 __all__ .extend (["implot3d" ])
159180if has_submodule ("imgui_color_text_edit" ):
160181 from imgui_bundle ._imgui_bundle import imgui_color_text_edit as imgui_color_text_edit
182+ _publish ("imgui_color_text_edit" , imgui_color_text_edit )
161183 __all__ .extend (["imgui_color_text_edit" ])
162184if has_submodule ("imgui_node_editor" ):
163185 from imgui_bundle ._imgui_bundle import imgui_node_editor as imgui_node_editor
186+ _publish ("imgui_node_editor" , imgui_node_editor )
164187 from imgui_bundle import imgui_node_editor_ctx as imgui_node_editor_ctx # noqa: E402
165188 __all__ .extend (["imgui_node_editor" , "imgui_node_editor_ctx" ])
166189if has_submodule ("imgui_knobs" ):
167190 from imgui_bundle ._imgui_bundle import imgui_knobs as imgui_knobs
191+ _publish ("imgui_knobs" , imgui_knobs )
168192 __all__ .extend (["imgui_knobs" ])
169193if has_submodule ("im_file_dialog" ):
170194 from imgui_bundle ._imgui_bundle import im_file_dialog as im_file_dialog
195+ _publish ("im_file_dialog" , im_file_dialog )
171196 __all__ .extend (["im_file_dialog" ])
172197if has_submodule ("imspinner" ):
173198 from imgui_bundle ._imgui_bundle import imspinner as imspinner
199+ _publish ("imspinner" , imspinner )
174200 __all__ .extend (["imspinner" ])
175201if has_submodule ("imgui_md" ):
176202 from imgui_bundle ._imgui_bundle import imgui_md as imgui_md
203+ _publish ("imgui_md" , imgui_md )
177204 __all__ .extend (["imgui_md" ])
178205
179206 # Register a hook so that initialize_markdown() automatically sets up URL image download support
@@ -185,36 +212,47 @@ def _on_initialize_markdown(options):
185212 imgui_md ._set_on_initialize_markdown_callback (_on_initialize_markdown )
186213if has_submodule ("immvision" ):
187214 from imgui_bundle ._imgui_bundle import immvision as immvision
215+ _publish ("immvision" , immvision )
188216 __all__ .extend (["immvision" ])
189217if has_submodule ("imguizmo" ):
190218 from imgui_bundle ._imgui_bundle import imguizmo as imguizmo
219+ _publish ("imguizmo" , imguizmo )
191220 __all__ .extend (["imguizmo" ])
192221if has_submodule ("imgui_tex_inspect" ):
193222 from imgui_bundle ._imgui_bundle import imgui_tex_inspect as imgui_tex_inspect
223+ _publish ("imgui_tex_inspect" , imgui_tex_inspect )
194224 __all__ .extend (["imgui_tex_inspect" ])
195225if has_submodule ("imgui_toggle" ):
196226 from imgui_bundle ._imgui_bundle import imgui_toggle as imgui_toggle
227+ _publish ("imgui_toggle" , imgui_toggle )
197228 __all__ .extend (["imgui_toggle" ])
198229if has_submodule ("portable_file_dialogs" ):
199230 from imgui_bundle ._imgui_bundle import portable_file_dialogs as portable_file_dialogs
231+ _publish ("portable_file_dialogs" , portable_file_dialogs )
200232 __all__ .extend (["portable_file_dialogs" ])
201233if has_submodule ("imgui_command_palette" ):
202234 from imgui_bundle ._imgui_bundle import imgui_command_palette as imgui_command_palette
235+ _publish ("imgui_command_palette" , imgui_command_palette )
203236 __all__ .extend (["imgui_command_palette" ])
204237if has_submodule ("imcoolbar" ):
205238 from imgui_bundle ._imgui_bundle import im_cool_bar as im_cool_bar
239+ _publish ("im_cool_bar" , im_cool_bar )
206240 __all__ .extend (["im_cool_bar" ])
207241if has_submodule ("nanovg" ):
208242 from imgui_bundle ._imgui_bundle import nanovg as nanovg
243+ _publish ("nanovg" , nanovg )
209244 __all__ .extend (["nanovg" ])
210245if has_submodule ("im_anim" ):
211246 from imgui_bundle ._imgui_bundle import im_anim as im_anim
247+ _publish ("im_anim" , im_anim )
212248 __all__ .extend (["im_anim" ])
213249if has_submodule ("imgui_explorer" ):
214250 from imgui_bundle ._imgui_bundle import imgui_explorer as imgui_explorer
251+ _publish ("imgui_explorer" , imgui_explorer )
215252 __all__ .extend (["imgui_explorer" ])
216253if has_submodule ("imgui_microtex" ):
217254 from imgui_bundle ._imgui_bundle import imgui_microtex as imgui_microtex
255+ _publish ("imgui_microtex" , imgui_microtex )
218256 __all__ .extend (["imgui_microtex" ])
219257
220258if has_submodule ("immapp_cpp" ): # immapp is a Python wrapper around immapp_cpp
@@ -275,7 +313,7 @@ def _on_initialize_markdown(options):
275313 hello_imgui .override_assets_folder (THIS_DIR + "/assets" )
276314
277315
278- def register_demos_assets_folder ():
316+ def register_demos_assets_folder () -> None :
279317 """Add demos_assets/ to hello_imgui assets search path.
280318 Call this from demos that need additional images (house.jpg, bear_transparent.png, etc.)
281319 beyond the default assets (world.png, fonts)."""
0 commit comments