Exemplo n.º 1
0
def app(image_path, output_path):
    view = c.Image(Image.open(image_path))
    autosave = True
    try:
        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
Exemplo n.º 2
0
def computation():
    def draw(i, tf):
        return c.orr([
            c.draw.circle(0, 0, 1, 'red', tf=tf),
            c.draw.text(f"iter: {i}", 0, 0, 'black', tf=tf),
        ])

    for i in range(2000000):
        yield c.partial(draw, i)
    print("Computation done.")
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def hello_world():
    show_demo_window = True
    demo_state = DemoState()
    show_another_window = False
    float = 0.0
    counter = 0
    while True:
        tag, value = yield from c.orr([
            c.window(
                "Hello, world!",
                c.orr([
                    c.text("This is some useful text."),
                    c.checkbox("Demo Window", show_demo_window),
                    c.checkbox("Another Window", show_another_window),
                    c.slider_float("Float", float, 0, 1),
                    # Not implemented: background color chooser
                    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
Exemplo n.º 5
0
def app():
    view = c.Frame((0, 0), (512, 512), keep_aspect=True)
    arr = np.array(Image.open("examples/lenna.png"))
    tex = c.integrations.opengl.texture(arr)

    while True:
        tag, value = yield from c.orr([
            c.window(
                "Graph",
                c.frame("Frame",
                        view,
                        content_gen=c.partial(graph, tex, arr.shape[0],
                                              arr.shape[1]))),
            c.window("Controls", c.button("Reset View")),
        ])
        if tag == "Frame":
            view = value
        elif tag == "Reset View":
            view.reset_view()
        yield