def test_set_current_context_destroyed(no_context):
    ctx = imgui.create_context()
    assert ctx is not None

    imgui.destroy_context(ctx)

    imgui.set_current_context(ctx)
    assert imgui.get_current_context() is None
示例#2
0
 def __init__(self):
     if not imgui.get_current_context():
         raise RuntimeError(
             "No valid ImGui context. Use imgui.create_context() first and/or "
             "imgui.set_current_context().")
     self.io = imgui.get_io()
     self._font_texture = None
     self.editableFigure = None
     self.camera = None
     self.showcase = None
     self._create_device_objects()
     self.refresh_font_texture()
示例#3
0
    def __init__(self):
        if not imgui.get_current_context():
            raise RuntimeError(
                "No valid ImGui context. Use imgui.create_context() first and/or "
                "imgui.set_current_context().")
        self.io = imgui.get_io()

        self._font_texture = None

        self.io.delta_time = 1.0 / 60.0

        self._create_device_objects()
        self.refresh_font_texture()
示例#4
0
def main(widget,
         name="Concur",
         width=640,
         height=480,
         fps=60,
         save_screencast=None,
         screencast_fps=60,
         menu_bar=False,
         maximized=False):
    """ Create a GLFW window, spin up the main loop, and display a given widget inside.

    To create a maximized window, pass width and height larger than the screen.

    Args:
        widget: The widget to display inside the window. When the widget returns, the application exits.
        name: Window name, displayed in the title bar and other OS outputs.
        width: Desired window width.
        height: Desired window height.
        fps: Maximum number of frames per second
        save_screencast: Capture and save the UI into a specified video file (experimental). Main window shouldn't
            be resized while the application is running when using this option.
        screencast_fps: Save the screencast video with a given FPS.
        menu_bar: Reserve space for `concur.widgets.main_menu_bar` at the top of the window.
        maximized: Create a maximized window.
    """
    if imgui.get_current_context() is None:
        imgui.create_context()

    # Set config flags
    imgui.get_io(
    ).config_flags |= imgui.CONFIG_DOCKING_ENABLE  # | imgui.CONFIG_VIEWPORTS_ENABLE

    window = create_window(name, width, height, maximized=maximized)
    impl = PatchedGlfwRenderer(window)

    win_w, win_h = glfw.get_window_size(window)
    fb_w, fb_h = glfw.get_framebuffer_size(window)
    font_scaling_factor = max(float(fb_w) / win_w, float(fb_h) / win_h)
    imgui.get_io().font_global_scale /= font_scaling_factor
    impl.refresh_font_texture(
    )  # Refresh the font texture in case user changed it

    # Using this feels significantly choppier than sleeping manually. TODO: investigate & fix
    # glfw.swap_interval(-1)
    if save_screencast:
        import imageio
        width, height = glfw.get_framebuffer_size(window)
        offscreen_fb = create_offscreen_fb(width, height)
        writer = imageio.get_writer(save_screencast,
                                    mode='I',
                                    fps=screencast_fps)

    try:
        while not glfw.window_should_close(window):
            t0 = time.perf_counter()
            glfw.poll_events()
            impl.process_inputs()

            imgui.new_frame()

            create_window_dock(window, menu_bar=menu_bar)
            begin_maximized_window("Default##Concur",
                                   window,
                                   menu_bar=menu_bar)

            try:
                next(widget)
            except StopIteration:
                break
            finally:
                imgui.end()
                imgui.render()

                gl.glClearColor(0.5, 0.5, 0.5, 1)
                gl.glClear(gl.GL_COLOR_BUFFER_BIT)

                if save_screencast:
                    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, offscreen_fb)
                    impl.render(imgui.get_draw_data())
                    image = get_fb_data(offscreen_fb, width, height)
                    writer.append_data(image)
                gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0)

                impl.render(imgui.get_draw_data())
                glfw.swap_buffers(window)

            t1 = time.perf_counter()
            if t1 - t0 < 1 / fps:
                time.sleep(1 / fps - (t1 - t0))
    finally:
        impl.shutdown()
        imgui.destroy_context(imgui.get_current_context())
        glfw.terminate()
        if save_screencast:
            writer.close()
示例#5
0
def main(widget_gen,
         name="Concur Puppet",
         width=640,
         height=480,
         save_screencast=None,
         return_sshot=False,
         headless=False,
         fps=60):
    """ Create a GLFW window, spin up the main loop, and display a given widget inside.

    The resulting window is not hooked up to the user input. Instead, input is handled
    by a PuppetRenderer instance.

    `widget_gen` takes as an argument a `PuppetRenderer` instance, and returns a widget.
    `fps` optionally limits FPS (if None, FPS is unlimited)
    """
    imgui.create_context()

    # Set config flags
    imgui.get_io(
    ).config_flags |= imgui.CONFIG_DOCKING_ENABLE | imgui.CONFIG_VIEWPORTS_ENABLE

    window = create_window(name, width, height, visible=not headless)
    impl = PuppetRenderer(window)
    widget = widget_gen(impl)
    offscreen_fb = create_offscreen_fb(width, height)

    if save_screencast:
        import imageio
        writer = imageio.get_writer(save_screencast, mode='I', fps=60)

    try:
        while not glfw.window_should_close(window):
            t0 = time.perf_counter()
            glfw.poll_events()
            impl.process_inputs()

            imgui.new_frame()

            create_window_dock(window)
            begin_maximized_window("Default##Concur", window)

            try:
                next(widget)
            except StopIteration:
                break
            finally:
                imgui.end()

                gl.glClearColor(0.5, 0.5, 0.5, 1)
                gl.glClear(gl.GL_COLOR_BUFFER_BIT)
                imgui.render()

                if save_screencast:
                    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, offscreen_fb)
                    impl.render(imgui.get_draw_data())
                    image = get_fb_data(offscreen_fb, width, height)
                    writer.append_data(image)
                gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0)

                impl.render(imgui.get_draw_data())
                glfw.swap_buffers(window)

            t1 = time.perf_counter()
            if fps is not None and t1 - t0 < 1 / fps:
                time.sleep(1 / fps - (t1 - t0))

        if return_sshot:
            gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, offscreen_fb)
            impl.render(imgui.get_draw_data())
            image = get_fb_data(offscreen_fb, width, height)
            ret = image
        else:
            ret = None

    finally:
        impl.shutdown()
        imgui.destroy_context(imgui.get_current_context())
        glfw.terminate()
        if save_screencast:
            writer.close()

    return ret
def no_context():
    ctx = imgui.get_current_context()
    if ctx is not None:
        imgui.destroy_context(ctx)
def test_create_context_ctx_object_identity(no_context):
    ctx = imgui.create_context()
    assert ctx is not None
    assert ctx == imgui.get_current_context()
def test_create_context_no_context(no_context):
    ctx = imgui.create_context()
    assert ctx is not None
    assert imgui.get_current_context() is not None
def test_get_current_context_no_context(no_context):
    assert imgui.get_current_context() is None