Exemple #1
0
def main():
    window, gl_context = impl_pysdl2_init()
    impl = SDL2Impl(window)

    opened = True

    running = True
    event = SDL_Event()
    while running:
        while SDL_PollEvent(ctypes.byref(event)) != 0:
            if event.type == SDL_QUIT:
                running = False
                break
            impl.process_event(event)
        impl.process_inputs()

        imgui.new_frame()

        if imgui.begin_main_menu_bar():
            if imgui.begin_menu("File", True):
                clicked_quit, selected_quit = imgui.menu_item(
                    "Quit", 'Cmd+Q', False, True)
                if clicked_quit:
                    exit(1)
                imgui.end_menu()
            imgui.end_main_menu_bar()

        imgui.show_user_guide()
        imgui.show_test_window()

        if opened:
            expanded, opened = imgui.begin("fooo", True)
            imgui.text("Bar")
            imgui.text_colored("Eggs", 0.2, 1., 0.)
            imgui.end()

        with imgui.styled(imgui.STYLE_ALPHA, 1):
            imgui.show_metrics_window()

        gl.glClearColor(114 / 255., 144 / 255., 154 / 255., 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        imgui.render()

        SDL_GL_SwapWindow(window)

    impl.shutdown()
    SDL_GL_DeleteContext(gl_context)
    SDL_DestroyWindow(window)
    SDL_Quit()
Exemple #2
0
def main():
    window = impl_glfw_init()
    impl = GlfwImpl(window)

    opened = True

    while not glfw.window_should_close(window):
        glfw.poll_events()
        impl.process_inputs()

        imgui.new_frame()

        if imgui.begin_main_menu_bar():
            if imgui.begin_menu("File", True):
                clicked_quit, selected_quit = imgui.menu_item("Quit", 'Cmd+Q', False, True)
                if clicked_quit:
                    exit(1)
                imgui.end_menu()
            imgui.end_main_menu_bar()

        imgui.show_user_guide()
        imgui.show_test_window()

        if opened:
            expanded, opened = imgui.begin("fooo", True)
            imgui.text("Bar")
            imgui.text_colored("Eggs", 0.2, 1., 0.)
            imgui.end()

        with imgui.styled(imgui.STYLE_ALPHA, 1):
            imgui.show_metrics_window()

        gl.glClearColor(114 / 255., 144 / 255., 154 / 255., 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        imgui.render()
        glfw.swap_buffers(window)

    impl.shutdown()
    imgui.shutdown()
    glfw.terminate()
Exemple #3
0
    def on_draw(self):
        arcade.start_render()

        imgui.new_frame()

        if self.window.view_metrics:
            self.window.view_metrics = imgui.show_metrics_window(closable=True)

        self.draw_mainmenu()
        self.draw_navbar()

        imgui.set_next_window_position(288, 32, imgui.ONCE)
        imgui.set_next_window_size(512, 512, imgui.ONCE)

        self.draw()

        imgui.end_frame()
Exemple #4
0
 def _render(self):
     if not imgui.show_metrics_window(True): windowClosed.send(self)
Exemple #5
0
def main():
    width, height = 1280, 720
    window_name = "minimal ImGui/GLFW3 example"

    if not glfw.init():
        print("Could not initialize OpenGL context")
        exit(1)

    # OS X supports only forward-compatible core profiles from 3.2
    glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
    glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
    glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

    glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, gl.GL_TRUE)

    # Create a windowed mode window and its OpenGL context
    window = glfw.create_window(int(width), int(height), window_name, None,
                                None)
    glfw.make_context_current(window)

    if not window:
        glfw.terminate()
        print("Could not initialize Window")
        exit(1)

    imgui_ctx = GlfwImpl(window)
    imgui_ctx.enable()

    opened = True

    style = imgui.GuiStyle()

    while not glfw.window_should_close(window):
        glfw.poll_events()
        imgui_ctx.new_frame()

        imgui.show_user_guide()
        imgui.show_test_window()

        if opened:
            expanded, opened = imgui.begin("fooo", True)
            imgui.text("Bar")
            imgui.text_colored("Eggs", 0.2, 1., 0.)
            imgui.end()

        with imgui.styled(imgui.STYLE_ALPHA, 1):
            imgui.show_metrics_window()

        imgui.show_style_editor(style)

        # note: this is redundant
        width, height = glfw.get_framebuffer_size(window)
        gl.glViewport(0, 0, int(width / 2), int(height))

        gl.glClearColor(114 / 255., 144 / 255., 154 / 255., 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        imgui.render()
        glfw.swap_buffers(window)

    glfw.terminate()
Exemple #6
0
async def draw() -> Eff[[ACTIONS], None]:
    global state

    im.show_metrics_window()
    im.show_test_window()

    # ------------------------
    # t_flags = 0
    # t_flags = (
    # 	  im.WINDOW_NO_TITLE_BAR
    # 	| im.WINDOW_NO_MOVE
    # 	| im.WINDOW_NO_RESIZE
    # 	| im.WINDOW_NO_COLLAPSE
    # 	| im.WINDOW_NO_FOCUS_ON_APPEARING
    # 	| im.WINDOW_NO_BRING_TO_FRONT_ON_FOCUS
    # )
    # with window(name="test", flags=t_flags):
    # 	im.button("bloop")
    # 	pos = util.point_offset(im.get_window_position(), im.Vec2(40, 80))
    # 	im.set_next_window_position(pos.x, pos.y)
    # 	with window(name="a window"):
    # 		im.text("I'm a window")

    # 	top_left = im.get_item_rect_min()
    # 	size = im.get_item_rect_size()
    # 	bottom_right = util.point_offset(top_left, size)
    # 	im.text('TL: '+str(top_left))
    # 	im.text('BR: '+str(bottom_right))
    # 	util.add_rect(im.get_window_draw_list(), util.Rect(top_left, bottom_right), (1.,1.,1.,1.))

    debug_log("test_drew", False)
    with window("test") as (expanded, _):
        only_draw_if(expanded)

        debug_log("test_drew", True)  # only_draw_if didn't abort, overwrite
        US = ui['settings']

        opts = ['first', 'second', 'third']
        default_state = ('no_selection', None)

        US.setdefault('selectable_state', default_state)
        US.setdefault('selectable_added', [])
        if not im.is_window_focused():
            US['selectable_state'] = default_state

        changed, selection_changed, selectable_state = double_click_listbox(
            US['selectable_state'], opts)
        if changed:
            US['selectable_state'] = selectable_state

        o_ix = selectable_state[1]
        im.text_colored(
            "[ {!s:<10} ] {}".format(opts[o_ix] if o_ix is not None else "---",
                                     "(!)" if selection_changed else ""),
            *(0.3, 0.8, 0.5))
        im.text("")
        im.text("{!r:<5} {!r:<5} {}".format(changed, selection_changed,
                                            selectable_state))

        if selectable_state[0] == 'double_clicked':
            US['selectable_added'].append(opts[selectable_state[1]])
        im.text(str(US['selectable_added']))

        c = im.is_mouse_clicked()
        dc = im.is_mouse_double_clicked()
        im.text("{!r:<5} {!r:<5} {!r:<5}".format(c, dc, c and dc))
        im.text("focused: " + repr(im.is_window_focused()))

    with window(name="signals"):
        if im.button("load example"):
            await emit(FileAction.Load(filename=example_file_path))

        if len(state.data.signals) > 0:

            def right_pad(s: str, limit: int) -> str:
                n_spaces = max(0, limit - len(s))
                return s + (' ' * n_spaces)

            for sig_id, sig_name in sorted(state.data.signal_names.items(),
                                           key=lambda pair: pair[1]):
                im.text_colored(right_pad(sig_name, 5), 0.2, 0.8, 1)
                im.same_line()
                signal = state.data.signals[sig_id]
                im.text(str(signal))
        else:
            im.text("No signals loaded")

    # -------------------------
    # with window(name="modules"):
    # 	modules = sorted(
    #		rlu.all_modules(dir=pathlib.Path.cwd()),
    #		key=lambda mod: (getattr(mod, '__reload_incarnation__', -1), mod.__name__)
    #	)
    # 	for mod in modules:
    # 		incarnation_text = str(getattr(mod, '__reload_incarnation__', '-'))
    # 		im.text("{mod}[{inc}]".format(mod=mod.__name__, inc=incarnation_text))

    with window(name="settings"):
        ui_settings = ui['settings']
        changed, move = im.checkbox("move plots",
                                    ui_settings['plot_window_movable'])
        if changed:
            ui_settings['plot_window_movable'] = move

        # im.same_line()
        changed, option = str_combo(
            "resample", ui_settings['plot_resample_function'],
            ['numpy_interp', 'scipy_zoom', 'crude_downsample'])
        if changed:
            ui_settings['plot_resample_function'] = option

        # im.same_line()
        changed, option = str_combo("plots", ui_settings['plot_draw_function'],
                                    ['imgui', 'manual'])
        if changed:
            ui_settings['plot_draw_function'] = option

        changed, val = im.slider_float('filter_slider_power',
                                       ui_settings['filter_slider_power'],
                                       min_value=1.,
                                       max_value=5.,
                                       power=1.0)
        if changed:
            ui_settings['filter_slider_power'] = val

        if im.button("reload"):
            await emit(AppRunnerAction.Reload())

        # im.same_line()
        # im.button("bla bla bla")

        # im.same_line()
        # im.button("ple ple ple")

        im.text("state | ")

        im.same_line()
        if im.button("dump##state"):
            await emit(AppStateAction.SaveState)

        im.same_line()
        if im.button("load##state"):
            await emit(AppStateAction.LoadState)

        im.same_line()
        if im.button("reset##state"):
            await emit(AppStateAction.ResetState)

        im.text("history | ")

        im.same_line()
        if im.button("dump##history"):
            await emit(AppStateAction.SaveUserActionHistory)

        im.same_line()
        if im.button("load##history"):
            await emit(AppStateAction.LoadUserActionHistory)

        im.same_line()
        if im.button("reset##history"):
            await emit(AppStateAction.ResetUserActionHistory)

        im.same_line()
        if im.button("run##history"):
            await emit(AppStateAction.RunHistory)

    # TODO: Window positions can theoretically be accessed
    # after being drawn using internal APIs.
    # See:
    #	imgui_internal.h > ImGuiWindow (search "struct IMGUI_API ImGuiWindow")
    #	imgui.cpp        > ImGui::GetCurrentContext()
    #
    # (sort-of pseudocode example)
    #
    # foo_id = None
    #
    # with window("foo"):
    # 	foo_id = GetCurrentWindow().ID
    # 	...
    #
    # ...
    #
    # with window("accessing other windows"):
    # 	windows = imgui.GetCurrentContext().Windows
    # 	foo_win = windows[ windows.find(lambda win: win.ID = foo_id) ]
    # 	im.text( "pos:{}, size:{}".format(foo_win.Pos, foo_win.Size) )

    # ----------------------------
    # await ng.graph_window(state.graph)

    prev_color_window_background = im.get_style().color(
        im.COLOR_WINDOW_BACKGROUND)

    im.set_next_window_position(0, 100)
    with color({im.COLOR_WINDOW_BACKGROUND: (0., 0., 0., 0.05)}), \
      window(name="nodes",
       flags = (
          im.WINDOW_NO_TITLE_BAR
        # | im.WINDOW_NO_MOVE
        # | im.WINDOW_NO_RESIZE
        | im.WINDOW_NO_COLLAPSE
        | im.WINDOW_NO_FOCUS_ON_APPEARING
        | im.WINDOW_NO_BRING_TO_FRONT_ON_FOCUS
       )
      ):
        box_positions = {}
        inputs = ng.get_inputs(state.graph, state.data.box_outputs)

        with color({im.COLOR_WINDOW_BACKGROUND: prev_color_window_background}):

            # source boxes
            for (id_, box_state) in state.source_boxes.items():
                pos = await signal_source_window(box_state, state.data.signals,
                                                 state.data.signal_names)
                box_positions[id_] = pos

            # filter boxes
            for (id_, box_state) in state.filter_boxes.items():
                pos = await filter_box_window(box_state,
                                              ui_settings=ui_settings)
                box_positions[id_] = pos

            # signal plot 1
            for (id_, box_state) in state.plots.items():
                pos = await signal_plot_window(box_state,
                                               inputs[id_],
                                               ui_settings=ui_settings)
                box_positions[id_] = pos

        # connections between boxes
        link_selection = state.link_selection

        prev_cursor_screen_pos = im.get_cursor_screen_position()

        # get slot coords and draw slots
        with color({im.COLOR_CHECK_MARK: (0, 0, 0, 100 / 255)}):
            draw_list = im.get_window_draw_list()
            SPACING = 20.
            slot_center_positions = {}

            for (id_, position) in box_positions.items():
                node = state.graph.nodes[id_]

                left_x = position.top_left.x
                right_x = position.bottom_right.x
                top_y = position.top_left.y

                for slot_ix in range(node.n_inputs):
                    pos = im.Vec2(left_x - 20 - 3,
                                  top_y + 30 + slot_ix * SPACING)
                    im.set_cursor_screen_position(pos)

                    slot = ng.InputSlotId(id_, slot_ix)
                    was_selected = (slot == link_selection.dst_slot)

                    changed, selected = im.checkbox(
                        "##in{}{}".format(id_, slot_ix), was_selected)
                    if changed:
                        await emit(LinkSelectionAction.ClickInput(slot))

                    center_pos = util.rect_center(
                        util.get_item_rect())  # bounding rect of prev widget
                    slot_center_positions[('in', id_, slot_ix)] = center_pos

                for slot_ix in range(node.n_outputs):
                    pos = im.Vec2(right_x + 3, top_y + 30 + slot_ix * SPACING)
                    im.set_cursor_screen_position(pos)

                    slot = ng.OutputSlotId(id_, slot_ix)
                    was_selected = (slot == link_selection.src_slot)

                    changed, selected = im.checkbox(
                        "##out{}{}".format(id_, slot_ix), was_selected)
                    if changed:
                        await emit(LinkSelectionAction.ClickOutput(slot))

                    center_pos = util.rect_center(
                        util.get_item_rect())  # bounding rect of prev widget
                    slot_center_positions[('out', id_, slot_ix)] = center_pos

        # end drawing slots

        # draw links
        for (src, dst) in state.graph.links:
            src_pos = slot_center_positions[('out', src.node_id, src.ix)]
            dst_pos = slot_center_positions[('in', dst.node_id, dst.ix)]
            draw_list.add_line(*src_pos,
                               *dst_pos,
                               col=im.get_color_u32_rgba(0.5, 0.5, 0.5, 1.),
                               thickness=2.)

        im.set_cursor_screen_position(prev_cursor_screen_pos)
    # end nodes window

    im.show_style_editor()