glfw_utils.py 986 B

12345678910111213141516171819202122232425262728293031
  1. # Part of ImGui Bundle - MIT License - Copyright (c) 2022-2026 Pascal Thomet - https://github.com/pthom/imgui_bundle
  2. from typing import cast
  3. try:
  4. import glfw # pip install glfw
  5. def glfw_window_hello_imgui() -> glfw._GLFWwindow:
  6. """Return the main glfw window used by HelloImGui (when the backend is GLFW)
  7. You can use this window to set up additional GLFW callbacks.
  8. """
  9. import ctypes
  10. from imgui_bundle import hello_imgui
  11. window_address = hello_imgui.get_glfw_window_address()
  12. window_pointer = ctypes.cast(window_address, ctypes.POINTER(glfw._GLFWwindow))
  13. return cast(glfw._GLFWwindow, window_pointer)
  14. except (ImportError, ModuleNotFoundError):
  15. def glfw_window_hello_imgui() -> None: # type: ignore
  16. import sys
  17. print("""Please install glfw, so that glfw_window_hello_imgui works:
  18. pip install glfw""")
  19. sys.exit(1)
  20. pass
  21. # print("Warning: could not import glfw")