Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@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),
]
@idom.element(state="tag")
async def simple_stateful_element(self, tag):
return idom.vdom(tag)
@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"])
@idom.element
def non_coroutine_func(self):
pass
@idom.element
async def Inner(self):
return idom.html.div()
@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
@idom.element(state="element, alternate")
async def UseAlternateUntilShown(self, alternate, element, show=False):
if show:
return element
else:
return alternate
@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)
@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),
]