-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Cat facts</title> | ||
|
||
<!-- Recommended meta tags --> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
|
||
<!-- PyScript --> | ||
<link rel="stylesheet" href="https://pyscript.net/releases/2024.4.1/core.css"> | ||
<script type="module" src="https://pyscript.net/releases/2024.4.1/core.js"></script> | ||
|
||
<!-- App CSS Styles --> | ||
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/paper.min.css"> | ||
</head> | ||
<body> | ||
<script type="mpy" src="./main.py" config="./pyscript.toml" async></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
""" | ||
Example application that uses a Task to get cat facts. | ||
""" | ||
import invent | ||
from invent.ui import * | ||
|
||
URL = "https://catfact.ninja/" | ||
|
||
|
||
# Datastore ############################################################################ | ||
|
||
invent.datastore["catfact"] = "" | ||
|
||
# Code ################################################################################# | ||
|
||
|
||
|
||
# Channels ############################################################################# | ||
|
||
|
||
invent.subscribe(navigate, to_channel="navigate", when_subject=["press"]) | ||
invent.subscribe(make_honk, to_channel="honk", when_subject=["press", "touch"]) | ||
invent.subscribe(make_oink, to_channel="oink", when_subject=["press", "touch"]) | ||
|
||
|
||
# User Interface ####################################################################### | ||
|
||
|
||
app = App( | ||
name="CatFacts!", | ||
content=[ | ||
Page( | ||
name="Facts", | ||
content=[ | ||
Column( | ||
content=[ | ||
Image( | ||
image=invent.media.images.goose.png, | ||
channel="honk", | ||
position="MIDDLE-CENTER", | ||
), | ||
Row( | ||
position="CENTER", | ||
content=[ | ||
Button( | ||
name="button honk", | ||
label="HONK!", | ||
channel="honk", | ||
position="FILL", | ||
), | ||
Button( | ||
name="to_percy", | ||
label="Visit Percy", | ||
channel="navigate", | ||
position="FILL", | ||
), | ||
], | ||
), | ||
Button( | ||
name="to_code", | ||
label="Get Facts", | ||
channel="get_cat_facts", | ||
position="FILL", | ||
), | ||
TextBox( | ||
name="a_cat_fact", | ||
text=from_datastore("cat_fact"), | ||
position="MIDDLE-CENTER", | ||
), | ||
] | ||
), | ||
], | ||
), | ||
Page( | ||
name="Percy", | ||
content=[ | ||
Column( | ||
content=[ | ||
Image( | ||
image=invent.media.images.pig.png, | ||
channel="oink", | ||
position="MIDDLE-CENTER", | ||
), | ||
Row( | ||
position="CENTER", | ||
content=[ | ||
Button( | ||
name="button oink", | ||
label="OINK!!", | ||
channel="oink", | ||
), | ||
Button( | ||
name="to_lucy", | ||
label="Visit Lucy", | ||
channel="navigate", | ||
position="FILL", | ||
), | ||
TextBox( | ||
name="number_of_oinks", | ||
text=from_datastore("number_of_oinks"), | ||
position="MIDDLE-CENTER", | ||
), | ||
], | ||
), | ||
Row( | ||
id="pigs", | ||
position="CENTER", | ||
content=from_datastore( | ||
"number_of_oinks", with_function=make_pigs | ||
), | ||
), | ||
Button( | ||
name="to_code", | ||
label="Show Code", | ||
channel="navigate", | ||
position="FILL", | ||
), | ||
], | ||
), | ||
], | ||
), | ||
], | ||
) | ||
|
||
|
||
# Add a page that shows the code! ###################################################### | ||
|
||
|
||
app.content.append( | ||
Page( | ||
name="Code", | ||
content=[ | ||
Row( | ||
content=[ | ||
Button( | ||
name="to_lucy", | ||
label="Visit Lucy", | ||
channel="navigate", | ||
position="FILL", | ||
), | ||
Button( | ||
name="to_percy", | ||
label="Visit Percy", | ||
channel="navigate", | ||
position="FILL", | ||
), | ||
] | ||
), | ||
Code(code=export.as_pyscript_app(app)[1]), | ||
], | ||
) | ||
) | ||
|
||
|
||
# GO! ################################################################################## | ||
|
||
|
||
invent.go() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[files] | ||
# | ||
# invent. | ||
# | ||
"/static/invent.zip" = "./*" |