Пример #1
0
    def draw(self):
        imgui.new_frame()

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

        imgui.begin("Example: drag and drop")

        imgui.button('source')
        if imgui.begin_drag_drop_source():
            imgui.set_drag_drop_payload('itemtype', b'payload')
            imgui.button('dragged source')
            imgui.end_drag_drop_source()

        imgui.button('dest')
        if imgui.begin_drag_drop_target():
            payload = imgui.accept_drag_drop_payload('itemtype')
            if payload is not None:
                print('Received:', payload)
            imgui.end_drag_drop_target()

        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Пример #2
0
def drag_drop_target(tag, value, widget):
    """ Drag-and-Drop Target Widget.

    This widget is used in conjunction with `concur.widgets.drag_drop_source`. On widget drop,
    an event is generated which contains the payload from source, and the value from targed,
    and is shaped like this: `(tag, (source_payload, value))`.

    Args:
        tag: Drag-and-Drop event tag. Must match the tag in `drag_drop_source`.
        value: Value added to the event.
        widget: Widget which accepts the drag-and-drop event.
    """
    while True:
        try:
            imgui.begin_group()
            next(widget)
        except StopIteration as e:
            return e.value
        finally:
            imgui.end_group()
        if imgui.begin_drag_drop_target():
            payload = imgui.accept_drag_drop_payload(tag)
            imgui.end_drag_drop_target()
            if payload is not None:
                return tag, (pickle.loads(payload), value)
        yield
Пример #3
0
 def end_input(self):
     if imgui.begin_drag_drop_target():
         payload = imgui.accept_drag_drop_payload('itemtype')
         if payload is not None:
             payload = self.page.end_dnd()
             print('Received:', payload)
             self.page.connect(payload, self.input)
         imgui.end_drag_drop_target()
Пример #4
0
    def draw(self):
        imgui.begin("Example: drag and drop")

        imgui.button('source')
        if imgui.begin_drag_drop_source():
            imgui.set_drag_drop_payload('itemtype', b'payload')
            imgui.button('dragged source')
            imgui.end_drag_drop_source()

        imgui.button('dest')
        if imgui.begin_drag_drop_target():
            payload = imgui.accept_drag_drop_payload('itemtype')
            if payload is not None:
                print('Received:', payload)
            imgui.end_drag_drop_target()

        imgui.end()
Пример #5
0
                if rov_pins[motor][2]:
                    imgui.text(motor + ": GPIO #" + str(rov_pins[motor][0]) +
                               ", BCM #" + str(rov_pins[motor][1]) +
                               " (Hardware PWM)")
                else:
                    imgui.text(motor + ": GPIO #" + str(rov_pins[motor][0]) +
                               ", BCM #" + str(rov_pins[motor][1]))

                if imgui.begin_drag_drop_target():
                    data = imgui.accept_drag_drop_payload("pin")

                    if data:
                        rov_pins[motor] = literal_eval(data.decode())
                        changed = True

                    imgui.end_drag_drop_target()
            else:
                imgui.text(motor + ": No assigned pin")

                if imgui.begin_drag_drop_target():
                    data = imgui.accept_drag_drop_payload("pin")

                    if data:
                        rov_pins[motor] = literal_eval(data.decode())
                        changed = True

                    imgui.end_drag_drop_target()

        if changed:
            assemble_controller()
Пример #6
0
def render_palette_popup(drawing: Drawing):

    global edit_color
    global color_editor_open

    palette = drawing.palette
    fg = palette.foreground
    bg = palette.background
    fg_color = palette.foreground_color
    bg_color = palette.background_color
    open_color_editor = False

    _, opened = imgui.begin("Color popup", True)

    imgui.begin_child("Colors", height=0)

    imgui.push_style_var(imgui.STYLE_ITEM_SPACING,
                         (0, 0))  # Make layout tighter
    width = int(imgui.get_window_content_region_width()) // 25

    for i, color in enumerate(palette.colors, 0):
        is_foreground = i == fg
        is_background = (i == bg) * 2
        selection = is_foreground | is_background
        if i in palette.overlay:
            color = as_float(palette.overlay[i])
        else:
            color = as_float(color)
        imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND,
                               *SELECTABLE_FRAME_COLORS[selection])
        if imgui.color_button(f"color {i}", *color[:3], 1, 0, 25, 25):
            # io = imgui.get_io()
            # if io.key_shift:
            #     if "spread_start" in temp_vars:
            #         temp_vars["spread_end"] = i
            #     else:
            #         temp_vars["spread_start"] = i
            # else:
            fg = i
        imgui.pop_style_color(1)

        if imgui.core.is_item_clicked(1):
            edit_color = i
            color_editor_open = True
            imgui.open_popup("Edit foreground color")
            # imgui.set_next_window_position(w - 115 - 120, 200)

        if imgui.core.is_item_clicked(2):
            # Detect right button clicks on the button
            bg = i

        if imgui.begin_drag_drop_source():
            imgui.set_drag_drop_payload('start_index',
                                        i.to_bytes(1, sys.byteorder))
            imgui.color_button(f"color {i}", *color[:3], 1, 0, 20, 20)
            imgui.end_drag_drop_source()
        if imgui.begin_drag_drop_target():
            start_index = imgui.accept_drag_drop_payload('start_index')
            if start_index is not None:
                start_index = int.from_bytes(start_index, sys.byteorder)
                io = imgui.get_io()
                image_only = io.key_shift
                # drawing.swap_colors(start_index, i, image_only=image_only)
                # palette.clear_overlay()
            imgui.end_drag_drop_target()

        # if imgui.is_item_hovered():
        #     io = imgui.get_io()
        #     delta = int(io.mouse_wheel)

        if i % width != width - 1:
            imgui.same_line()

    imgui.pop_style_var(1)
    #color_editor_open = render_color_editor_popup(drawing, edit_color, color_editor_open)

    imgui.end_child()
    imgui.end()

    palette.foreground = fg
    palette.background = bg

    return opened, open_color_editor
Пример #7
0
def render_palette(drawing: Drawing):

    global color_editor_open  # Need a persistent way to keep track of the popup being closed...
    global current_color_page

    palette = drawing.palette
    fg = palette.foreground
    bg = palette.background
    fg_color = palette.foreground_color
    bg_color = palette.background_color

    imgui.begin_child("Palette", border=False, height=460)
    # Edit foreground color
    if imgui.color_button(f"Foreground (#{fg})", *as_float(fg_color), 0, 30,
                          30):
        io = imgui.get_io()
        w, h = io.display_size
        imgui.open_popup("Edit foreground color")
        imgui.set_next_window_position(w - 115 - 120, 200)
        color_editor_open = True
    if imgui.begin_popup("Edit foreground color",
                         flags=(imgui.WINDOW_NO_MOVE
                                | imgui.WINDOW_NO_SCROLL_WITH_MOUSE)):
        done, cancelled, new_color = render_color_editor(
            palette.colors[fg], fg_color)
        if done and new_color != fg_color:
            drawing.change_colors(fg, new_color)
            palette.clear_overlay()
        elif cancelled:
            palette.clear_overlay()
        else:
            palette.set_overlay(fg, new_color)
        imgui.end_popup()
    elif color_editor_open:
        # The popup was closed by clicking outside, keeping the change (same as OK)
        drawing.change_colors(fg, fg_color)
        palette.clear_overlay()
        color_editor_open = False

    imgui.same_line()

    imgui.color_button(f"Background (#{bg})", *as_float(bg_color), 0, 30, 30)

    max_pages = len(palette.colors) // 64 - 1
    imgui.push_item_width(100)
    _, current_color_page = imgui.slider_int("Page",
                                             current_color_page,
                                             min_value=0,
                                             max_value=max_pages)
    start_color = 64 * current_color_page

    imgui.begin_child("Colors", border=False)
    imgui.push_style_var(imgui.STYLE_ITEM_SPACING,
                         (0, 0))  # Make layout tighter
    width = int(imgui.get_window_content_region_width()) // 20

    imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND, 0, 0, 0)

    colors = palette.colors

    # Order the colors by column instead of by row (which is the order we draw them)
    for i, c in enumerate(
            chain.from_iterable(
                zip(range(0, 16), range(16, 32), range(32, 48), range(48,
                                                                      64)))):
        color = colors[start_color + c]
        is_foreground = c == fg
        is_background = (c == bg) * 2
        selection = is_foreground | is_background
        color = as_float(color)

        if color[3] == 0 or selection:
            x, y = imgui.get_cursor_screen_pos()

        if imgui.color_button(f"color {i}", *color[:3], 1, 0, 25, 25):
            # io = imgui.get_io()
            # if io.key_shift:
            #     if "spread_start" in temp_vars:
            #         temp_vars["spread_end"] = i
            #     else:
            #         temp_vars["spread_start"] = i
            # else:
            fg = c

        if i % width != width - 1:
            imgui.same_line()

        draw_list = imgui.get_window_draw_list()
        if color[3] == 0:
            # Mark transparent color
            draw_list.add_line(x + 1, y + 1, x + 24, y + 24,
                               imgui.get_color_u32_rgba(0, 0, 0, 1), 1)
            draw_list.add_line(x + 1, y + 2, x + 23, y + 24,
                               imgui.get_color_u32_rgba(1, 1, 1, 1), 1)

        if is_foreground:
            # Mark foregroupd color
            draw_list.add_rect_filled(x + 2, y + 2, x + 10, y + 10,
                                      imgui.get_color_u32_rgba(1, 1, 1, 1))
            draw_list.add_rect(x + 2, y + 2, x + 10, y + 10,
                               imgui.get_color_u32_rgba(0, 0, 0, 1))
        if is_background:
            # Mark background color
            draw_list.add_rect_filled(x + 15, y + 2, x + 23, y + 10,
                                      imgui.get_color_u32_rgba(0, 0, 0, 1))
            draw_list.add_rect(x + 15, y + 2, x + 23, y + 10,
                               imgui.get_color_u32_rgba(1, 1, 1, 1))

        if imgui.core.is_item_clicked(2):
            # Right button sets background
            bg = c

        # Drag and drop (currently does not accomplish anything though)
        if imgui.begin_drag_drop_source():
            imgui.set_drag_drop_payload('start_index',
                                        c.to_bytes(1, sys.byteorder))
            imgui.color_button(f"color {c}", *color[:3], 1, 0, 20, 20)
            imgui.end_drag_drop_source()
        if imgui.begin_drag_drop_target():
            start_index = imgui.accept_drag_drop_payload('start_index')
            if start_index is not None:
                start_index = int.from_bytes(start_index, sys.byteorder)
                io = imgui.get_io()
                image_only = io.key_shift
                drawing.swap_colors(start_index, c, image_only=image_only)
                palette.clear_overlay()
            imgui.end_drag_drop_target()

    imgui.pop_style_color(1)
    imgui.pop_style_var(1)
    imgui.end_child()

    imgui.end_child()

    if imgui.is_item_hovered():
        io = imgui.get_io()
        delta = int(io.mouse_wheel)
        current_color_page = min(max(current_color_page - delta, 0), max_pages)

    palette.foreground = fg
    palette.background = bg
Пример #8
0
def frame_commands():
    gl.glClearColor(0.1, 0.1, 0.1, 1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)

    io = imgui.get_io()

    if io.key_ctrl and io.keys_down[glfw.KEY_Q]:
        sys.exit(0)

    if imgui.begin_main_menu_bar():
        if imgui.begin_menu("File", True):
            clicked_quit, selected_quit = imgui.menu_item("Quit", "Ctrl+Q", False, True)

            if clicked_quit:
                sys.exit(0)

            imgui.end_menu()
        imgui.end_main_menu_bar()

    # turn windows on/off
    imgui.begin("Active examples")
    for label, enabled in active.copy().items():
        _, enabled = imgui.checkbox(label, enabled)
        active[label] = enabled
    imgui.end()

    if active["window"]:
        imgui.begin("Hello, Imgui!")
        imgui.text("Hello, World!")
        imgui.end()

    if active["child"]:
        imgui.begin("Example: child region")
        imgui.begin_child("region", 150, -50, border=True)
        imgui.text("inside region")
        imgui.end_child()
        imgui.text("outside region")
        imgui.end()

    if active["tooltip"]:
        imgui.begin("Example: tooltip")
        imgui.button("Click me!")
        if imgui.is_item_hovered():
            imgui.begin_tooltip()
            imgui.text("This button is clickable.")
            imgui.end_tooltip()
        imgui.end()

    if active["menu bar"]:
        try:
            flags = imgui.WINDOW_MENU_BAR
            imgui.begin("Child Window - File Browser", flags=flags)
            if imgui.begin_menu_bar():
                if imgui.begin_menu('File'):
                    clicked, state = imgui.menu_item('Close')
                    if clicked:
                        active["menu bar"] = False
                        raise Exception
                    imgui.end_menu()
                imgui.end_menu_bar()
            imgui.end()
        except Exception:
            print("exception caught, but too late!")

    if active["popup"]:
        imgui.begin("Example: simple popup")
        if imgui.button("select"):
            imgui.open_popup("select-popup")
        imgui.same_line()
        if imgui.begin_popup("select-popup"):
            imgui.text("Select one")
            imgui.separator()
            imgui.selectable("One")
            imgui.selectable("Two")
            imgui.selectable("Three")
            imgui.end_popup()
        imgui.end()

    if active["popup modal"]:
        imgui.begin("Example: simple popup modal")
        if imgui.button("Open Modal popup"):
            imgui.open_popup("select-popup-modal")
        imgui.same_line()
        if imgui.begin_popup_modal("select-popup-modal")[0]:
            imgui.text("Select an option:")
            imgui.separator()
            imgui.selectable("One")
            imgui.selectable("Two")
            imgui.selectable("Three")
            imgui.end_popup()
        imgui.end()

    if active["popup context item"]:
        imgui.begin("Example: popup context view")
        imgui.text("Right-click to set value.")
        if imgui.begin_popup_context_item("Item Context Menu"):
            imgui.selectable("Set to Zero")
            imgui.end_popup()
        imgui.end()

    if active["popup context window"]:
        imgui.begin("Example: popup context window")
        if imgui.begin_popup_context_window():
            imgui.selectable("Clear")
            imgui.end_popup()
        imgui.end()

    if active["popup context void"]:
        if imgui.begin_popup_context_void():
            imgui.selectable("Clear")
            imgui.end_popup()

    if active["drag drop"]:
        imgui.begin("Example: drag and drop")
        imgui.button('source')
        if imgui.begin_drag_drop_source():
            imgui.set_drag_drop_payload('itemtype', b'payload')
            imgui.button('dragged source')
            imgui.end_drag_drop_source()
        imgui.button('dest')
        if imgui.begin_drag_drop_target():
            payload = imgui.accept_drag_drop_payload('itemtype')
            if payload is not None:
                print('Received:', payload)
            imgui.end_drag_drop_target()
        imgui.end()

    if active["group"]:
        imgui.begin("Example: item groups")
        imgui.begin_group()
        imgui.text("First group (buttons):")
        imgui.button("Button A")
        imgui.button("Button B")
        imgui.end_group()
        imgui.same_line(spacing=50)
        imgui.begin_group()
        imgui.text("Second group (text and bullet texts):")
        imgui.bullet_text("Bullet A")
        imgui.bullet_text("Bullet B")
        imgui.end_group()
        imgui.end()

    if active["tab bar"]:
        imgui.begin("Example Tab Bar")
        if imgui.begin_tab_bar("MyTabBar"):
            if imgui.begin_tab_item("Item 1")[0]:
                imgui.text("Here is the tab content!")
                imgui.end_tab_item()
            if imgui.begin_tab_item("Item 2")[0]:
                imgui.text("Another content...")
                imgui.end_tab_item()
            global opened_state
            selected, opened_state = imgui.begin_tab_item("Item 3", opened=opened_state)
            if selected:
                imgui.text("Hello Saylor!")
                imgui.end_tab_item()
            imgui.end_tab_bar()
        imgui.end()

    if active["list box"]:
        imgui.begin("Example: custom listbox")
        if imgui.begin_list_box("List", 200, 100):
            imgui.selectable("Selected", True)
            imgui.selectable("Not Selected", False)
            imgui.end_list_box()
        imgui.end()

    if active["table"]:
        imgui.begin("Example: table")
        if imgui.begin_table("data", 2):
            imgui.table_next_column()
            imgui.table_header("A")
            imgui.table_next_column()
            imgui.table_header("B")

            imgui.table_next_row()
            imgui.table_next_column()
            imgui.text("123")

            imgui.table_next_column()
            imgui.text("456")

            imgui.table_next_row()
            imgui.table_next_column()
            imgui.text("789")

            imgui.table_next_column()
            imgui.text("111")

            imgui.table_next_row()
            imgui.table_next_column()
            imgui.text("222")

            imgui.table_next_column()
            imgui.text("333")
            imgui.end_table()
        imgui.end()