8000 Add code for a Freedom Units demo app. · Positive-Conative/pyscript@7ce66b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ce66b5

Browse files
committed
Add code for a Freedom Units demo app.
1 parent 6525faf commit 7ce66b5

File tree

8 files changed

+205
-0
lines changed

8 files changed

+205
-0
lines changed

pyscriptjs/examples/toga/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Freedom Units!
2+
3+
This is a demo Toga app implementing a Fahrenheit to Celsius converter.
4+
5+
## Initial setup
6+
7+
1. Create and activate a virtual environment:
8+
9+
$ python -m venv venv
10+
$ . ./venv/bin/activate
11+
12+
2. Install the demo requirements:
13+
14+
$ pip install -r requirements.txt
15+
16+
### Development details
17+
18+
This demo bakes a pre-compiled version of pyscript into the `server/pyscript`
19+
directory.
20+
21+
It also includes an experimental version of toga-core, toga-web and toga-flask,
22+
packaged as wheels in the `server/wheels` directory.
23+
24+
If any changes are made to the Toga sources or to PyScript, these vendored
25+
resources will need to be updated.
26+
27+
## Web app
28+
29+
The web app is a demo Flask server, serving a web app version of Toga at the
30+
root URL. To run the web demo server:
31+
32+
$ cd server
33+
$ PYTHONPATH=../freedom/src python -m demo
34+
35+
then point your browser at http://localhost:8081/
36+
37+
Enter a value in the "farenheit" input, and click the "calculate" button.
38+
39+
It may take a few seconds for this button to become live; look for the
40+
"Collecting nodes..." entry in the console log.
41+
42+
## Desktop app
43+
44+
To run this app in development mode:
45+
46+
$ briefcase dev
47+
48+
To build and run an app bundle:
49+
50+
$ briefcase run
51+
52+
If you're on an M1 macOS, this will raise an error on first run; if you get this error, run:
53+
54+
$ briefcase package -p app --adhoc-sign
55+
56+
then re-run `briefcase run`
57+
58+
## iOS app
59+
60+
To run this in the iOS simulator, run:
61+
62+
$ briefcase run iOS
63+
64+
To run this in the Android simulator, run:
65+
66+
$ briefcase run android
67+
68+
Note that these builds have extensive requirements that must be installed -
69+
Xcode for iOS, and the Android SDKs for Android. These are multiple gigabyte
70+
downloads. Briefcase will detect when these tools aren't available, and either
71+
prompt you to download them, or perform a download for you. As a result, your
72+
first build may take up to 20 minutes to complete, depending on the speed of
73+
your conection.
2.42 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
mkdir -p ../server/static/wheels
4+
cd src
5+
unzip ../base-wheel.zip
6+
zip ../../server/static/wheels/freedom-0.0.1-py3-none-any.whl -r freedom*
7+
rm -rf freedom-0.0.1.dist-info
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[build-system]
2+
requires = ["briefcase"]
3+
4+
[tool.briefcase]
5+
project_name = "Freedom Units"
6+
bundle = "org.beeware"
7+
version = "0.0.1"
8+
url = "https://beeware.org"
9+
license = "BSD license"
10+
author = 'Tiberius Yak'
11+
author_email = "tiberius@beeware.org"
12+
13+
[tool.briefcase.app.freedom]
14+
formal_name = "Freedom Units"
15+
description = "A testing app"
16+
sources = ['src/freedom']
17+
requires = [
18+
'../server/static/wheels/toga_core-0.3.0.dev33-py3-none-any.whl',
19+
'../server/static/wheels/travertino-0.1.3-py3-none-any.whl',
20+
]
21+
22+
23+
[tool.briefcase.app.freedom.macOS]
24+
requires = [
25+
'git+https://github.com/beeware/toga.git#egg=toga-cocoa&subdirectory=src/cocoa',
26+
'std-nslog>=1.0.0',
27+
]
28+
29+
[tool.briefcase.app.freedom.linux]
30+
requires = [
31+
'git+https://github.com/beeware/toga.git#egg=toga-gtk&subdirectory=src/gtk',
32+
]
33+
34+
[tool.briefcase.app.freedom.windows]
35+
requires = [
36+
'git+https://github.com/beeware/toga.git#egg=toga-winforms&subdirectory=src/winforms',
37+
]
38+
39+
# Mobile deployments
40+
[tool.briefcase.app.freedom.iOS]
41+
requires = [
42+
'git+https://github.com/beeware/toga.git#egg=toga-iOS&subdirectory=src/iOS',
43+
'std-nslog>=1.0.0',
44+
]
45+
46+
[tool.briefcase.app.freedom.android]
47+
requires = [
48+
'git+https://github.com/beeware/toga.git#egg=toga-android&subdirectory=src/android',
49+
]

pyscriptjs/examples/toga/freedom/src/freedom/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from freedom.app import main
2+
3+
print("IN FREEDOM", main)
4+
5+
if __name__ == '__main__':
6+
main().main_loop()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
import toga
3+
from toga.style.pack import LEFT, RIGHT, COLUMN, ROW, Pack
4+
5+
6+
class FreedomApp(toga.App):
7+
def calculate(self, widget):
8+
try:
9+
self.c_input.value = (float(self.f_input.value) - 32.0) * 5.0 / 9.0
10+
except ValueError:
11+
self.c_input.value = '???'
12+
13+
def startup(self):
14+
self.main_window = toga.MainWindow(title=self.name)
15+
16+
c_box = toga.Box()
17+
f_box = toga.Box()
18+
box = toga.Box()
19+
20+
self.c_input = toga.TextInput(id="c_input", readonly=True)
21+
self.f_input = toga.TextInput(id="f_input")
22+
23+
c_label = toga.Label('Celsius', style=Pack(text_align=LEFT))
24+
f_label = toga.Label('Fahrenheit', style=Pack(text_align=LEFT))
25+
join_label = toga.Label('is equivalent to', style=Pack(text_align=RIGHT))
26+
27+
button = toga.Button('Calculate', id="calculate", on_press=self.calculate)
28+
29+
f_box.add(self.f_input)
30+
f_box.add(f_label)
31+
32+
c_box.add(join_label)
33+
c_box.add(self.c_input)
34+
c_box.add(c_label)
35+
36+
box.add(f_box)
37+
box.add(c_box)
38+
box.add(button)
39+
40+
box.style.update(direction=COLUMN, padding_top=10)
41+
f_box.style.update(direction=ROW, padding=5)
42+
c_box.style.update(direction=ROW, padding=5)
43+
44+
self.c_input.style.update(flex=1)
45+
self.f_input.style.update(flex=1, padding_left=160)
46+
c_label.style.update(width=100, padding_left=10)
47+
f_label.style.update(width=100, padding_left=10)
48+
join_label.style.update(width=150, padding_right=10)
49+
50+
button.style.update(padding=15, flex=1)
51+
52+
self.main_window.content = box
53+
self.main_window.show()
54+
55+
56+
def main():
57+
return FreedomApp('Freedom Units', 'org.beeware.freedom')
58+
59+
60+
if __name__ == '__main__':
61+
main().main_loop()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
setuptools
2+
wheel
3+
check-manifest
4+
briefcase
5+
flask==2.1.1
6+
server/static/wheels/toga_core-0.3.0.dev33-py3-none-any.whl
7+
server/static/wheels/toga_flask-0.3.0.dev33-py3-none-any.whl
8+
server/static/wheels/toga_web-0.3.0.dev33-py3-none-any.whl
9+
server/static/wheels/travertino-0.1.3-py3-none-any.whl

0 commit comments

Comments
 (0)
0