コード例 #1
0
ファイル: dnd.py プロジェクト: kfields/arcade-imgui
    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
ファイル: dnd.py プロジェクト: kfields/arcade-imgui
    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()
コード例 #3
0
def drag_drop_source(tag, payload, widget, dragged_widget=None, flags=0):
    """ Drag-and-Drop Source Widget.

    This widget is used in conjunction with `concur.widgets.drag_drop_target`.

    See the [https://github.com/potocpav/python-concur/blob/master/examples/extra/drag_and_drop.py](examples/extra/drag_and_drop.py)
    for an example.

    Args:
        tag: Drag-and-Drop event tag. Must match the tag in `drag_drop_target`.
        payload: Pickle-able value which is to be returned in the drag-and-drop event.
        widget: Widget which can be dragged.
        dragged_widget: Widget inside the tooltip which is displayed while dragging.
            Defaults to a `widget` copy.
        flags: Flags to modify dragging behavior.
            See [the pyimgui docs](https://pyimgui.readthedocs.io/en/latest/reference/imgui.html?highlight=WINDOW_MENU_BAR#imgui.DRAG_DROP_SOURCE_NO_PREVIEW_TOOLTIP)
            for the flag list.
    """
    while True:
        try:
            imgui.begin_group()
            next(widget)
        except StopIteration as e:
            return e.value
        finally:
            imgui.end_group()
        assert not (
            flags & imgui.DRAG_DROP_SOURCE_ALLOW_NULL_ID
        ), "`SourceAllowNullID` is automatically set - do not set it manually."
        if imgui.begin_drag_drop_source(
                flags | imgui.DRAG_DROP_SOURCE_ALLOW_NULL_ID):
            imgui.set_drag_drop_payload(tag, pickle.dumps(payload))
            try:
                next(dragged_widget if dragged_widget else widget)
            except StopIteration as e:
                assert ValueError(
                    "Drag and drop indicator widget (`dragged_widget`) fired an event. You can use `concur.forever` to supress widget events. If you have a legitimate use-case for this, please file an issue."
                )
            finally:
                imgui.end_drag_drop_source()
        yield
コード例 #4
0
                imgui.end_menu()
            imgui.end_main_menu_bar()

        #imgui.show_demo_window()

        imgui.begin("Available GPIO Pins")

        for pin in available_pins:
            if pin[2]:
                imgui.selectable("GPIO #" + str(pin[0]) + ", BCM #" +
                                 str(pin[1]) + " (Hardware PWM)")
            else:
                imgui.selectable("GPIO #" + str(pin[0]) + ", BCM #" +
                                 str(pin[1]))

            if imgui.begin_drag_drop_source():
                imgui.set_drag_drop_payload("pin", str(pin).encode())
                if pin[2]:
                    imgui.text("GPIO #" + str(pin[0]) + ", BCM #" +
                               str(pin[1]) + " (Hardware PWM)")
                else:
                    imgui.text("GPIO #" + str(pin[0]) + ", BCM #" +
                               str(pin[1]))
                imgui.end_drag_drop_source()

        imgui.end()

        imgui.begin("GPIO Pin Values")

        for pin in available_pins:
            if pin[2]:
コード例 #5
0
ファイル: ui.py プロジェクト: johanfforsberg/voxpaint
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
コード例 #6
0
ファイル: ui.py プロジェクト: johanfforsberg/voxpaint
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
コード例 #7
0
def frame_commands():
    io = imgui.get_io()

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

    with imgui.begin_main_menu_bar() as main_menu_bar:
        if main_menu_bar.opened:
            with imgui.begin_menu("File", True) as file_menu:
                if file_menu.opened:
                    clicked_quit, selected_quit = imgui.menu_item(
                        "Quit", "Ctrl+Q")
                    if clicked_quit:
                        sys.exit(0)

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

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

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

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

    if active["menu bar"]:
        try:
            flags = imgui.WINDOW_MENU_BAR
            with imgui.begin("Child Window - File Browser", flags=flags):
                with imgui.begin_menu_bar() as menu_bar:
                    if menu_bar.opened:
                        with imgui.begin_menu('File') as file_menu:
                            if file_menu.opened:
                                clicked, state = imgui.menu_item('Close')
                                if clicked:
                                    active["menu bar"] = False
                                    raise Exception
        except Exception:
            print("exception handled")

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

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

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

    if active["popup context window"]:
        with imgui.begin("Example: popup context window"):
            with imgui.begin_popup_context_window() as popup:
                if popup.opened:
                    imgui.selectable("Clear")

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

    if active["drag drop"]:
        with imgui.begin("Example: drag and drop"):
            imgui.button('source')
            with imgui.begin_drag_drop_source() as src:
                if src.dragging:
                    imgui.set_drag_drop_payload('itemtype', b'payload')
                    imgui.button('dragged source')
            imgui.button('dest')
            with imgui.begin_drag_drop_target() as dst:
                if dst.hovered:
                    payload = imgui.accept_drag_drop_payload('itemtype')
                    if payload is not None:
                        print('Received:', payload)

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

    if active["tab bar"]:
        with imgui.begin("Example Tab Bar"):
            with imgui.begin_tab_bar("MyTabBar") as tab_bar:
                if tab_bar.opened:
                    with imgui.begin_tab_item("Item 1") as item1:
                        if item1.opened:
                            imgui.text("Here is the tab content!")
                    with imgui.begin_tab_item("Item 2") as item2:
                        if item2.opened:
                            imgui.text("Another content...")
                    global opened_state
                    with imgui.begin_tab_item("Item 3",
                                              opened=opened_state) as item3:
                        opened_state = item3.opened
                        if item3.selected:
                            imgui.text("Hello Saylor!")

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

    if active["table"]:
        with imgui.begin("Example: table"):
            with imgui.begin_table("data", 2) as table:
                if table.opened:
                    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")
コード例 #8
0
ファイル: node.py プロジェクト: kfields/arcade-imgui
 def end_output(self):
     if imgui.begin_drag_drop_source():
         imgui.set_drag_drop_payload('itemtype', b'payload')
         self.page.start_dnd(self.output)
         imgui.button('dragged source')
         imgui.end_drag_drop_source()