How to use the idom.Var function in idom

To help you get started, we’ve selected a few idom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rmorshea / idom / tests / test_core / test_hooks.py View on Github external
def test_simple_input(driver, display):
    message_var = idom.Var(None)

    @idom.element
    async def Input(message=None):
        message, set_message = idom.hooks.use_state(message)
        message_var.set(message)

        async def on_change(event):
            if event["value"] == "this is a test":
                set_message(event["value"])

        if message is None:
            return idom.html.input({"id": "input", "onChange": on_change})
        else:
            return idom.html.p({"id": "complete"}, ["Complete"])

    display(Input)
github rmorshea / idom / tests / test_tools.py View on Github external
def test_var_set():
    v = idom.Var(None)
    old_1 = v.set("new_1")
    assert old_1 is None
    old_2 = v.set("new_2")
    assert old_2 == "new_1"
github rmorshea / idom / tests / test_widgets / test_jupyter.py View on Github external
def test_same_origin_jupyter_display(driver, driver_wait, mount, server_url):
    clicked = idom.Var(False)

    @idom.element
    async def SimpleButton(self):
        @idom.event
        async def on_click(event):
            clicked.set(True)

        return idom.html.button(
            {"id": "simple-button", "onClick": on_click}, "click me same origin"
        )

    mount(SimpleButton)
    driver.get(f"{server_url}/__test_jupyter_widget_client__")

    client_button = driver.find_element_by_id("simple-button")
    client_button.click()
github rmorshea / idom / tests / test_widgets / test_html.py View on Github external
def test_input_callback(driver, driver_wait, display):
    inp_var = idom.Var(None)
    inp = idom.widgets.Input(inp_var.set, "text", "initial-value", {"id": "inp"})

    display(inp)

    client_inp = driver.find_element_by_id("inp")
    assert client_inp.get_attribute("value") == "initial-value"

    client_inp.clear()
    send_keys(client_inp, "new-value-1")
    driver_wait.until(lambda dvr: inp_var.value == "new-value-1")

    client_inp.clear()
    send_keys(client_inp, "new-value-2")
    driver_wait.until(lambda dvr: client_inp.get_attribute("value") == "new-value-2")
github rmorshea / idom / tests / test_widgets / test_html.py View on Github external
def test_input_ignore_empty(driver, driver_wait, display):
    # ignore empty since that's an invalid float
    inp_ingore_var = idom.Var("1")
    inp_not_ignore_var = idom.Var("1")

    @idom.element
    async def InputWrapper():
        return idom.html.div(
            idom.widgets.Input(
                inp_ingore_var.set,
                "number",
                inp_ingore_var.value,
                {"id": "inp-ignore"},
                ignore_empty=True,
            ),
            idom.widgets.Input(
                inp_not_ignore_var.set,
                "number",
                inp_not_ignore_var.value,
github rmorshea / idom / docs / source / widgets / matplotlib_animation.py View on Github external
def linked_inputs(label, value, *types, **attributes):
    var = idom.Var(value)

    inputs = []
    for tp in types:
        inp = idom.Input(tp, value, attributes, cast=float)

        @inp.events.on("change")
        async def on_change(event, inp=inp):
            for i in inputs:
                i.update(inp.value)
            var.set(inp.value)

        inputs.append(inp)

    fs = idom.html.fieldset(
        {"class": "linked-inputs"},
        [idom.html.legend({"style": {"font-size": "medium"}}, label)],
github rmorshea / idom / docs / source / widgets / snake.py View on Github external
def __init__(self, grid_size, block_size):
        self.snake = []
        self.grid = Grid(grid_size, block_size)
        self.new_direction = idom.Var(Directions.ArrowRight)
        self.old_direction = idom.Var(Directions.ArrowRight)
        self.food = idom.Var(None)
        self.won = idom.Var(False)
        self.lost = idom.Var(False)
github rmorshea / idom / docs / source / widgets / snake.py View on Github external
def __init__(self, grid_size, block_size):
        self.snake = []
        self.grid = Grid(grid_size, block_size)
        self.new_direction = idom.Var(Directions.ArrowRight)
        self.old_direction = idom.Var(Directions.ArrowRight)
        self.food = idom.Var(None)
        self.won = idom.Var(False)
        self.lost = idom.Var(False)