Beispiel #1
0
def test_checkbox(tester):
    res = yield from c.orr([
        tester.click_next(),
        c.checkbox("This", True),
    ])
    assert res == ("This", False)
    yield
    res = yield from c.orr([
        tester.click_next(),
        c.checkbox("That", False, tag="Tag"),
    ])
    assert res == ("Tag", True)
Beispiel #2
0
    def render(self):
        events = yield from c.window(
            title=self.name,
            widget=c.multi_orr([
                c.text("Style: "),
                c.orr_same_line([
                    c.radio_button(label, active=self.style == label)
                    for label in self.style_choices
                ]),
                c.spacing(),
                c.text("Username: "******"inject" ImGui calls into the rendering routine.
                # It may be better to abstract these `lift` calls out into a function (or not).
                # Note that Concur (and ImGui as a whole) are primarily made for debug interfaces, so custom styling like this is a bit clunky.
                # The calls used for sizing are [documented here](https://pyimgui.readthedocs.io/en/latest/reference/imgui.core.html).
                # You can do a whole lot of customization like this, I recommend skimming through the above link.
                c.lift(lambda: imgui.push_item_width(100)),
                c.input_text(name="",
                             value=self.username,
                             tag="Username",
                             buffer_length=10),
                c.text("Password: "******"",
                                    value=self.password,
                                    tag="Password"),
                c.lift(lambda: imgui.pop_item_width()),
                c.checkbox("Remember credentials", self.remember_credentials),
                c.spacing(),
                c.text("Input file: "),
                c.same_line(),
                c.text(self.filepath),
                c.button("Open"),
                self.custom_spacing(0, 20),
                c.separator(),
                c.button("Save"),
                c.same_line(),
                c.button("Reset"),
            ]))

        for tag, value in events:  # This is how event handling works with `multi_orr`
            if tag in self.style_choices:
                self.style = tag
                self.style_choices[tag]()
            elif tag == "Open":
                self.prompt_for_input_file()
            elif tag == "Username":
                self.username = value
            elif tag == "Password":
                self.password = value
            elif tag == "Remember credentials":
                self.remember_credentials = value
            elif tag == "Save":
                print("Saved")
            elif tag == "Reset":
                print("Resetted")

        return self
Beispiel #3
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
Beispiel #4
0
def app():
    view = c.Frame((-1, -1), (1, 1), keep_aspect=True)
    style = imgui.get_style()
    style.anti_aliased_lines = False

    while True:
        tag, value = yield from c.orr([
            c.window("Graph", c.frame("Frame", view, content_gen=graph)),
            c.window("Controls", c.checkbox("Antialiasing", style.anti_aliased_lines)),
            ])
        if tag == "Frame":
            view = value
        elif tag == "Antialiasing":
            style.anti_aliased_lines = value
        yield
Beispiel #5
0
def item(text, active):
    return c.orr_same_line(
        [c.button("-"), c.checkbox(text, active, tag="toggle")])
Beispiel #6
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