-
-
Save proItheus/cf9dd4aa85d78e76d91a300d396a5229 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import marimo | |
__generated_with = "0.1.60" | |
app = marimo.App() | |
@app.cell | |
def __(input, item_list, mo): | |
mo.vstack([input,item_list]) | |
return | |
@app.cell | |
def __(items): | |
items() | |
return | |
@app.cell | |
def __(datetime, dec_counter, del_item, inc_counter, items, mo): | |
item_list = mo.ui.batch( | |
mo.vstack( | |
[ | |
mo.hstack( | |
[ | |
f"{{del_{i}}}", | |
item.name, | |
item.count, | |
f"{{plus_{i}}}", | |
f"{{minus_{i}}}", | |
] | |
) | |
for i, item in enumerate(items()) | |
] | |
), | |
elements={ | |
k: v | |
for i in range(len(items())) | |
for k, v in ( | |
(f"del_{i}", mo.ui.button(value=i, label="🗑", on_click=del_item)), | |
( | |
f"plus_{i}", | |
mo.ui.button(value=i, label="+", on_click=inc_counter), | |
), | |
( | |
f"minus_{i}", | |
mo.ui.button(value=i, label="-", on_click=dec_counter), | |
), | |
) | |
}, | |
) | |
datetime.now().ctime() | |
return item_list, | |
@app.cell | |
def __(): | |
import marimo as mo | |
from dataclasses import dataclass | |
from copy import deepcopy | |
return dataclass, deepcopy, mo | |
@app.cell | |
def __(): | |
from datetime import datetime | |
return datetime, | |
@app.cell | |
def __(dataclass, mo): | |
@dataclass | |
class Item(): | |
name: str | |
count:int = 0 | |
items,set_items=mo.state([]) | |
items_mutated,set_items_mutated=mo.state(False) | |
return Item, items, items_mutated, set_items, set_items_mutated | |
@app.cell | |
def __(Item, mutate, set_items): | |
def new_item(name): | |
@mutate | |
def _new(l): | |
l.append(Item(name)) | |
set_items(_new) | |
return new_item, | |
@app.cell | |
def __(Item, mo): | |
it,setit=mo.state([Item('new')]) | |
return it, setit | |
@app.cell | |
def __(mo, new_item): | |
input=mo.ui.form(mo.ui.text(placeholder='enter the item name...'),on_change=new_item) | |
return input, | |
@app.cell | |
def __(): | |
def passarg(f): | |
def _f(arg): | |
f(arg) | |
return arg | |
return _f | |
return passarg, | |
@app.cell | |
def __(deepcopy): | |
def mutate(f): | |
def _f(obj): | |
obj_new=deepcopy(obj) | |
f(obj_new) | |
return obj_new | |
return _f | |
return mutate, | |
@app.cell | |
def __(mutate, passarg, set_items): | |
@passarg | |
def eqi(i): | |
@mutate | |
def _eq(l): | |
pass | |
set_items(_eq) | |
return eqi, | |
@app.cell | |
def __(mutate, passarg, set_items): | |
@passarg | |
def del_item(i): | |
print(f'{i=}') | |
@mutate | |
def _del(l): | |
del l[i] | |
set_items(_del) | |
return del_item, | |
@app.cell | |
def __(mutate, passarg, set_items): | |
@passarg | |
def inc_counter(i): | |
@mutate | |
def _inc(l): | |
l[i].count+=1 | |
set_items(_inc) | |
return inc_counter, | |
@app.cell | |
def __(mutate, passarg, set_items): | |
@passarg | |
def dec_counter(i): | |
@mutate | |
def _dec(l): | |
l[i].count-=1 | |
set_items(_dec) | |
return dec_counter, | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment