How to use the idom.element 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 / docs / source / widgets / snake.py View on Github external
@idom.element(state="grid_size, block_size")
async def GameView(self, grid_size, block_size):
    game = GameState(grid_size, block_size)

    grid_events = game.grid["eventHandlers"]

    @grid_events.on("KeyDown", prevent_default=True)
    async def direction_change(event):
        if hasattr(Directions, event["key"]):
            game.new_direction.set(Directions[event["key"]])

    game.snake.extend(
        [
            (grid_size // 2 - 1, grid_size // 2 - 3),
            (grid_size // 2 - 1, grid_size // 2 - 2),
            (grid_size // 2 - 1, grid_size // 2 - 1),
        ]
github rmorshea / idom / tests / test_core / test_element.py View on Github external
    @idom.element(state="tag")
    async def simple_stateful_element(self, tag):
        return idom.vdom(tag)
github rmorshea / idom / tests / test_core / test_events.py View on Github external
    @idom.element
    async def Button(self):
        async def on_click(event):
            clicked.set(True)
            self.update()

        if not clicked.get():
            return idom.html.button({"onClick": on_click, "id": "click"}, ["Click Me!"])
        else:
            return idom.html.p({"id": "complete"}, ["Complete"])
github rmorshea / idom / tests / test_core / test_element.py View on Github external
        @idom.element
        def non_coroutine_func(self):
            pass
github rmorshea / idom / tests / test_core / test_render.py View on Github external
    @idom.element
    async def Inner(self):
        return idom.html.div()
github rmorshea / idom / docs / source / widgets / matplotlib_animation.py View on Github external
@idom.element(run_in_executor=True)
async def Plot(self, x, y):
    fig, axes = plt.subplots()
    axes.plot(x, y)
    img = idom.Image("png")
    fig.savefig(img.io, format="png")
    plt.close(fig)
    return img
github rmorshea / idom / docs / source / widgets / _utils.py View on Github external
@idom.element(state="element, alternate")
async def UseAlternateUntilShown(self, alternate, element, show=False):
    if show:
        return element
    else:
        return alternate
github rmorshea / idom / docs / source / widgets / matplotlib_animation.py View on Github external
@idom.element
async def RandomWalk(self, timeout=20):
    start = time.time()

    x, y = [0] * 50, [0] * 50
    plot = Plot(x, y)

    mu_var, mu_inputs = linked_inputs(
        "Mean", 0, "number", "range", min=-1, max=1, step=0.01
    )
    sigma_var, sigma_inputs = linked_inputs(
        "Standard Deviation", 1, "number", "range", min=0, max=2, step=0.01
    )

    @self.animate(rate=0.5)
    async def walk(stop):
        x.pop(0)
github rmorshea / idom / docs / source / widgets / primary_secondary_buttons.py View on Github external
@idom.element
async def PrimarySecondaryButtons(self, message=None, event=None, info=None):
    async def on_click_primary(event, info):
        self.update("Primary Clicked:", event, info)

    async def on_click_secondary(event, info):
        self.update("Secondary Clicked:", event, info)

    return idom.html.div(
        [
            semantic_ui_style,
            Button({"primary": True, "onClick": on_click_primary}, ["Primary"]),
            Button({"secondary": True, "onClick": on_click_secondary}, ["Secondary"]),
            pre_seperated(message, event, info),
        ]