Esempio n. 1
0
    def __init__(self):
        super().__init__()
        self.state = State()
        self.style_choices = {
            "Dark": imgui.style_colors_dark,
            "Classic": imgui.style_colors_classic,
            "Light": imgui.style_colors_light
        }
        self.style = "Classic"
        self.username = ""
        self.password = ""
        self.glyph_ranges = None
        self.is_logged_in = False
        self.flag_quit = False
        self.language = "default"

        if not self.is_logged_in:
            self.__initialize_custom_font()
            c.main(widget=self.__handle_auth(),
                   name="Authentication",
                   width=257,
                   height=166)

        if self.is_logged_in:
            self.__initialize_custom_font()
            c.main(widget=self.run_application(),
                   name="Application",
                   width=1024,
                   height=768,
                   menu_bar=True)
Esempio n. 2
0
                c.nothing(),
                c.text_tooltip("Text tooltip", c.text("world!")),
                c.text_tooltip("Orr tooltip", c.orr([
                    c.text_tooltip("Button tooltip", c.button("Button1")),
                    c.button("Button2"),
                    ])),
                c.orr([
                    c.button("Button3"),
                    c.button("Button4"),
                    ]),
                c.text("Finish line."),
                ]),
            c.draggable("Drag", c.orr([c.button("Draggable Button"), c.forever(c.button, "Another")])),
            c.input_text("Hello", "world!", 123),
            c.collapsing_header("Image", c.orr([
                c.tooltip(c.orr([c.text("Hello!"), c.image("", im1, width=300, height=200), c.event(("Key", "Tooltip value"))]), c.image("Im1", im1, width=30, height=20)),
                c.image("Im2", im2, width=30, height=20),
                ])),
            c.input_text("Hello", "world!", 123),
            c.key_press("Key", glfw.KEY_SPACE),
            ])
        if k == "Im1":
            im1 = v
        if k == "Im2":
            im2 = v
        print(k, v)
        yield

if __name__ == "__main__":
    c.main(app(), "Counter")
Esempio n. 3
0
#!/usr/bin/env python3

import concur as c


def app():
    while True:
        key, value = yield from c.orr([
            c.main_menu_bar(c.orr([
                c.menu("File", c.orr([
                    c.menu_item("New", "Ctrl+N"),
                    c.menu_item("Open...", "Ctrl+O"),
                    c.separator(),
                    c.menu_item("Quit", "Ctrl+Q"),
                    ])),
                ])),
            c.text("Try Ctrl+Q."),
            c.key_press("Quit", ord('Q'), ctrl=True),
            ])
        print(key, value)
        if key == "Quit":
            return
        yield


if __name__ == "__main__":
    c.main(app(), "Main Menu Bar", menu_bar=True)
Esempio n. 4
0
font_name = "DejaVuSansCode_0.ttf"
font_name_2 = "Hack Regular Nerd Font Complete Mono Windows Compatible.ttf"
font_file = str(Path(__file__).parent / "src" / "resources" / font_name)
font_file_2 = str(Path(__file__).parent / "src" / "resources" / font_name_2)
imgui.create_context()
io = imgui.get_io()
font = io.fonts.add_font_from_file_ttf(
    font_file, 30,
    io.fonts.custom_glyph_ranges([
        0x0020,
        0x00FF,
        0x2000,
        0x206F,
        0x3000,
        0x30FF,
        0x31F0,
        0x31FF,
        0xFF00,
        0xFFEF,
        0x4e00,
        0x9FAF,
    ]))
io.fonts.add_font_from_file_ttf(font_file_2,
                                30,
                                io.fonts.custom_glyph_ranges(
                                    [0x1f600, 0x1f800]),
                                merge=True)

c.main(c.text("hello \U0001f600 汉字"))
Esempio n. 5
0
#!/usr/bin/env python3
"""Simple table example using the columns API."""

import concur as c


def app():
    return c.columns([
        [c.text("Hello,"), c.button("Click me")],
        [c.text("columns!"), c.button("Or me")],
        [c.text("columns!"), c.button("Or me")],
        [c.text("columns!"), c.button("Or me")],
        [c.text("columns!"), c.button("Or me")],
    ], "start", True)


if __name__ == "__main__":
    c.main(app(), "Columns")
Esempio n. 6
0
        tag, value = yield from c.orr([
            c.orr_same_line(
                [c.button("All"),
                 c.button("Active"),
                 c.button("Completed")]),
            c.orr([
                c.tag_value(i, item(s, a)) for i, (s, a) in enumerate(todos)
                if a in disp
            ]),
            c.orr_same_line(
                [c.button("+"),
                 c.input_text("New Item", edited, 30)]),
        ])
        if tag == "New Item":
            edited = value
        elif tag == "+" and edited:
            todos.append((edited, False))
            edited = ""
        elif tag in ["All", "Active", "Completed"]:
            disp = dict(All=[True, False], Active=[False],
                        Completed=[True])[tag]
        elif tag == "-":
            del todos[value[0]]
        elif tag == "toggle":
            todos[value[0]] = todos[value[0]][0], value[1]
        yield


if __name__ == "__main__":
    c.main(app(), "Todo List")
Esempio n. 7
0
#!/usr/bin/env python3

import concur as c
import numpy as np


def graph(tf):
    x = np.linspace(-1, 1, 1000)
    y = np.sin(np.log2(np.abs(x)) * 10) * np.cos(np.log2(np.abs(x)) / 2)
    return c.draw.polyline(np.stack([x, y]).T, 'black', tf=tf)


def app():
    view = c.Frame((-1, 2), (1, -2), keep_aspect=False, fix_axis='y')
    while True:
        _, view = yield from c.frame("Frame", view, content_gen=graph)
        yield


if __name__ == "__main__":
    c.main(app(), "Plot")
Esempio n. 8
0
#!/usr/bin/env python3

import time
from concurrent.futures import ThreadPoolExecutor
import concur as c


executor = ThreadPoolExecutor()


def timer():
    yield from c.orr([c.text(""), c.button("Start timer")])
    yield
    future = executor.submit(lambda: time.sleep(3))
    yield from c.orr([c.text("waiting for 3s..."), c.button("Cancel"), c.Block(future)])


def app():
    return c.orr([c.forever(timer) for _ in range(3)])


if __name__ == "__main__":
    c.main(app(), "Timers")
Esempio n. 9
0
#!/usr/bin/env python3

import concur as c
import counters, hello_world, image, plot, style, timers, todo


def app():
    return c.orr([
        c.window(module.__name__, module.app()) for module in
        [counters, hello_world, image, plot, style, timers, todo]
    ])


if __name__ == "__main__":
    c.main(app(), "All Examples", 800, 600)
Esempio n. 10
0
#!/usr/bin/env python3

import concur as c
import numpy as np
from time import monotonic as t


def graph(tf):
    while True:
        ts = np.linspace(t(), t() + 1/2, 100)
        pts = np.stack([np.sin(ts * 4), np.cos(ts * 5)]).T
        yield from c.orr([
            c.draw.polyline(pts, 'blue', tf=tf),
            c.event(None), # refresh every frame
            ])
        yield


def app():
    view = c.Frame((-1.5, 1.5), (1.5, -1.5))
    while True:
        _, view = yield from c.frame("Frame", view, content_gen=graph)
        yield


if __name__ == "__main__":
    c.main(app(), "Plot", 400, 288)
Esempio n. 11
0
        r = csv.reader(open(output_path, 'r'))
        pts = [(int(x), int(y)) for x, y in r]
    except FileNotFoundError:
        pts = []
    while True:
        tag, value = yield from c.orr([
            c.orr_same_line([c.button("Save"), c.text(f"Click to (de)annotate. N: {len(pts)}"), c.checkbox("Autosave", autosave)]),
            c.image("Image", view, content_gen=c.partial(overlay, np.array(pts).reshape(-1, 2))),
            ])
        if tag == "Image":
            view = value
        elif tag == "Autosave":
            autosave = value
        elif tag == "Rem":
            pts.pop(value)
        elif tag == "Add":
            pts.append((int(value[0]), int(value[1])))
        if tag == "Save" or autosave and tag in ["Rem", "Add"]:
            with open(output_path, 'w') as f:
                csv.writer(f).writerows(pts)
        yield


if __name__ == "__main__":
    if len(sys.argv) not in [2,3]:
        print("Usage:")
        print("    annotator.py <image> [output.csv]")
    else:
        input_path, output_path = sys.argv[1], sys.argv[2] if len(sys.argv) == 3 else os.path.splitext(sys.argv[1])[0] + '.csv'
        c.main(app(input_path, output_path), "Annotator", 1280, 820)
Esempio n. 12
0
        event_gen(),
    ])
    if key == "Drag":
        lines[-1][1] += value
    elif key == "Down":
        lines.append([value, value.copy()])
    return "Draw", lines


def app():
    view = c.Image(Image.open("examples/lenna.png"))
    lines = []
    while True:
        tag, value = yield from c.orr([
            c.text("Create lines by dragging with the left mouse button."),
            c.image("Image",
                    view,
                    content_gen=c.partial(overlay, deepcopy(lines)),
                    drag_tag="Drag",
                    down_tag="Down"),
        ])
        if tag == "Image":
            view = value
        elif tag == "Draw":
            lines = value
        yield


if __name__ == "__main__":
    c.main(app(), "Image Events")
Esempio n. 13
0
#!/usr/bin/env python3
"""Demonstrate Drag and Drop."""

import concur as c


def app():
    while True:
        tag, value = yield from c.orr([
            c.text("Drag & drop example:"),
            c.drag_drop_source("Drag", 123, c.button("Hello, 123")),
            c.drag_drop_source("Drag", 456, c.text("Hello, 456")),
            c.drag_drop_target("Drag", 'abc', c.button("Drop here")),
            c.drag_drop_target("Drag", 'def', c.button("or here")),
        ])
        if tag == "Hello":
            print("Hello")
        elif tag == "Drag":
            print(value)
        yield


if __name__ == "__main__":
    c.main(app(), "Drag and Drop")
Esempio n. 14
0
#!/usr/bin/env python3

import concur as c


def app():
    return c.button("Close")


if __name__ == "__main__":
    c.main(app(), "Hello World")
Esempio n. 15
0
        c.draw.circle(70, 110, 20, 'yellow', 2, 16, tf=tf),
        c.draw.text("Overlay text", 120, 20, 'blue', tf=tf),
        c.draw.polyline([(50, 30), (90, 30), (70, 50)],
                        'yellow',
                        True,
                        2,
                        tf=tf),
        c.transform(120, 50, c.button("Rotate"), tf=tf),
    ])


def app():
    image = Image.open("examples/lenna.png")
    view = c.Image(image)
    while True:
        tag, value = yield from c.orr([
            c.text(
                "Drag using right mouse button,\nscroll using mouse wheel."),
            c.image("Image", view, content_gen=overlay),
        ])
        if tag == "Image":
            view = value
        elif tag == "Rotate":
            image = image.transpose(Image.ROTATE_270)
            view.change_image(image)
        yield


if __name__ == "__main__":
    c.main(app(), "Image Viewer")
Esempio n. 16
0
                    c.orr_same_line(
                        [c.button("Button"),
                         c.text(f"counter = {counter}")]),
                    # Not implemented: FPS counter
                ])),
            c.optional(
                show_another_window, lambda: c.window(
                    "Another Window",
                    c.orr([
                        c.text("Hello from another window!"),
                        c.button("Close Me"),
                    ]))),
            c.optional(show_demo_window, c.partial(demo_window, demo_state)),
        ])
        if tag == "Demo Window":
            show_demo_window = value
        elif tag == "Another Window":
            show_another_window = value
        elif tag == "Float":
            float = value
        elif tag == "Button":
            counter += 1

        elif tag == "Close Me":
            show_another_window = False
        yield


if __name__ == "__main__":
    c.main(hello_world(), "Concur Demo Application", 1200, 800)