From c5108ac2e5de363a6b6c4d117c5521bf65d84dda Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Mon, 2 Dec 2024 09:08:50 -0500 Subject: [PATCH] Ensure that wgpu is compatible both with imgui 1.6.0 and older (#649) * Ensure that wgpu is compatible both with imgui 1.6.0 and older * Use try execpt. Release pin --- pyproject.toml | 2 +- wgpu/utils/imgui/imgui_renderer.py | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1be8dc0e..6e8a9345 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ dependencies = ["cffi>=1.15.0", "rubicon-objc>=0.4.1; sys_platform == 'darwin'"] # For users jupyter = ["jupyter_rfb>=0.4.2"] glfw = ["glfw>=1.9"] -imgui = ["imgui-bundle>=1.6.0"] +imgui = ["imgui-bundle>=1.2.1"] # For devs / ci build = ["build", "hatchling", "requests", "twine"] codegen = ["pytest", "numpy", "ruff"] diff --git a/wgpu/utils/imgui/imgui_renderer.py b/wgpu/utils/imgui/imgui_renderer.py index 2332b50a..053af617 100644 --- a/wgpu/utils/imgui/imgui_renderer.py +++ b/wgpu/utils/imgui/imgui_renderer.py @@ -43,12 +43,26 @@ class ImguiRenderer: "Tab": imgui.Key.tab, } - KEY_MAP_MOD = { - "Shift": imgui.Key.mod_shift, - "Control": imgui.Key.mod_ctrl, - "Alt": imgui.Key.mod_alt, - "Meta": imgui.Key.mod_super, - } + # imgui changed its API between 1.5.2 and 1.6.0 + # But as of Dec 1, 2024, it is too early for us to force + # users to use one specific version. + # So we will support both versions for now with this small shim + try: + # Version 1.6.0 and above + KEY_MAP_MOD = { + "Shift": imgui.Key.mod_shift, + "Control": imgui.Key.mod_ctrl, + "Alt": imgui.Key.mod_alt, + "Meta": imgui.Key.mod_super, + } + except AttributeError: + # Version 1.2.1 to 1.5.2 + KEY_MAP_MOD = { + "Shift": imgui.Key.im_gui_mod_shift, + "Control": imgui.Key.im_gui_mod_ctrl, + "Alt": imgui.Key.im_gui_mod_alt, + "Meta": imgui.Key.im_gui_mod_super, + } def __init__( self, device, canvas: wgpu.gui.WgpuCanvasBase, render_target_format=None