Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using pure python backend with test_engine #149

Open
csuckow opened this issue Dec 6, 2023 · 6 comments
Open

Using pure python backend with test_engine #149

csuckow opened this issue Dec 6, 2023 · 6 comments
Labels
faq A frequent issue, remaining opened to facilitate discoverability wontfix This will not be worked on

Comments

@csuckow
Copy link

csuckow commented Dec 6, 2023

Hello!
I am tinkering with the recent example for glfw and trying to integrate the test_engine by following the instructions here and here.
I was trying to click the button from the example window via test engine, but ran into some difficulties. When calling imgui.test_engine.start, the application freezes.
Is there something obvious that I'm missing?

(...)
def main():
    imgui.create_context()
    # initializing test_engine
    test_engine = imgui.test_engine.create_context()
    test_click_button = imgui.test_engine.register_test(test_engine, "Demo Tests", "click button")
    def test_open_popup_func(ctx: imgui.test_engine.TestContext) -> None:
        ctx.set_ref("Custom window")
        ctx.item_click("**/Hello")
    test_click_button.test_func = test_open_popup_func
    #imgui.test_engine.start(test_engine, imgui.get_current_context())   <---- the application freezes
    (...)
@pthom
Copy link
Owner

pthom commented Dec 6, 2023

Hello,

Integrating ImGui TestEngine directly from python, and without using HelloImGui and ImmApp is very difficult.

ImGui Test Engine uses two different threads (one for the main gui, and one for the scenario runner). Your python code will be called from two separate threads, and this breaks the GIL!

HelloImGui and ImmApp handle this well by transferring the GIL between threads (from C++). Doing this from pure python seems difficult.

@pthom pthom added the wontfix This will not be worked on label Dec 30, 2023
@dcnieho
Copy link
Contributor

dcnieho commented Jan 16, 2024

I ran into this too, #166. Two thoughts:

  1. Can you document this, perhaps in the docs that come up for imgui.test_engine.create_context() and imgui.test_engine.start()?
  2. If i understand correctly, runner_params.use_imgui_test_engine can only be set before the start of the app. Can you make it such that on each iteration your display functions check if its true, and if its true but there is not test engine context yet, make, register and start it?

Regarding the second: just an idea, no idea 1. how needed it is, 2. how useful it is.

pthom added a commit that referenced this issue Jan 16, 2024
@pthom
Copy link
Owner

pthom commented Jan 16, 2024

Can you document this, perhaps in the docs that come up for imgui.test_engine.create_context() and imgui.test_engine.start()?

Yes, see 20eecc0

If i understand correctly, runner_params.use_imgui_test_engine can only be set before the start of the app. Can you make it such that on each iteration your display functions check if its true, and if its true but there is not test engine context yet, make, register and start it?

I see no real use case for this.

However, I added the possibility to call register_test several times during the app lifetime.

745ded6

@pthom pthom changed the title Using example_python_backend_glfw3 with test_engine Using pure python backend with test_engine Jan 16, 2024
@dcnieho
Copy link
Contributor

dcnieho commented Jan 16, 2024

Ok, thanks for those additions!

So the logic would be that, until the patch upstream is in, you'd have to decide whether the test engine should be started or not before run()ing the app. I have not seen any performance issue connected to this, so guess its ok.

@pthom
Copy link
Owner

pthom commented Jan 16, 2024

The patch is already upstream

@dcnieho
Copy link
Contributor

dcnieho commented Jan 16, 2024

Ah super! Nice work!

@pthom pthom added the faq A frequent issue, remaining opened to facilitate discoverability label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
faq A frequent issue, remaining opened to facilitate discoverability wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants