mirror of
https://github.com/pyscript/pyscript.git
synced 2022-05-01 19:47:48 +03:00
Add code for a Freedom Units demo app.
This commit is contained in:
73
pyscriptjs/examples/toga/README.md
Normal file
73
pyscriptjs/examples/toga/README.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# Freedom Units!
|
||||
|
||||
This is a demo Toga app implementing a Fahrenheit to Celsius converter.
|
||||
|
||||
## Initial setup
|
||||
|
||||
1. Create and activate a virtual environment:
|
||||
|
||||
$ python -m venv venv
|
||||
$ . ./venv/bin/activate
|
||||
|
||||
2. Install the demo requirements:
|
||||
|
||||
$ pip install -r requirements.txt
|
||||
|
||||
### Development details
|
||||
|
||||
This demo bakes a pre-compiled version of pyscript into the `server/pyscript`
|
||||
directory.
|
||||
|
||||
It also includes an experimental version of toga-core, toga-web and toga-flask,
|
||||
packaged as wheels in the `server/wheels` directory.
|
||||
|
||||
If any changes are made to the Toga sources or to PyScript, these vendored
|
||||
resources will need to be updated.
|
||||
|
||||
## Web app
|
||||
|
||||
The web app is a demo Flask server, serving a web app version of Toga at the
|
||||
root URL. To run the web demo server:
|
||||
|
||||
$ cd server
|
||||
$ PYTHONPATH=../freedom/src python -m demo
|
||||
|
||||
then point your browser at http://localhost:8081/
|
||||
|
||||
Enter a value in the "farenheit" input, and click the "calculate" button.
|
||||
|
||||
It may take a few seconds for this button to become live; look for the
|
||||
"Collecting nodes..." entry in the console log.
|
||||
|
||||
## Desktop app
|
||||
|
||||
To run this app in development mode:
|
||||
|
||||
$ briefcase dev
|
||||
|
||||
To build and run an app bundle:
|
||||
|
||||
$ briefcase run
|
||||
|
||||
If you're on an M1 macOS, this will raise an error on first run; if you get this error, run:
|
||||
|
||||
$ briefcase package -p app --adhoc-sign
|
||||
|
||||
then re-run `briefcase run`
|
||||
|
||||
## iOS app
|
||||
|
||||
To run this in the iOS simulator, run:
|
||||
|
||||
$ briefcase run iOS
|
||||
|
||||
To run this in the Android simulator, run:
|
||||
|
||||
$ briefcase run android
|
||||
|
||||
Note that these builds have extensive requirements that must be installed -
|
||||
Xcode for iOS, and the Android SDKs for Android. These are multiple gigabyte
|
||||
downloads. Briefcase will detect when these tools aren't available, and either
|
||||
prompt you to download them, or perform a download for you. As a result, your
|
||||
first build may take up to 20 minutes to complete, depending on the speed of
|
||||
your conection.
|
||||
BIN
pyscriptjs/examples/toga/freedom/base-wheel.zip
Normal file
BIN
pyscriptjs/examples/toga/freedom/base-wheel.zip
Normal file
Binary file not shown.
7
pyscriptjs/examples/toga/freedom/fake-briefcase.sh
Executable file
7
pyscriptjs/examples/toga/freedom/fake-briefcase.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir -p ../server/static/wheels
|
||||
cd src
|
||||
unzip ../base-wheel.zip
|
||||
zip ../../server/static/wheels/freedom-0.0.1-py3-none-any.whl -r freedom*
|
||||
rm -rf freedom-0.0.1.dist-info
|
||||
49
pyscriptjs/examples/toga/freedom/pyproject.toml
Normal file
49
pyscriptjs/examples/toga/freedom/pyproject.toml
Normal file
@@ -0,0 +1,49 @@
|
||||
[build-system]
|
||||
requires = ["briefcase"]
|
||||
|
||||
[tool.briefcase]
|
||||
project_name = "Freedom Units"
|
||||
bundle = "org.beeware"
|
||||
version = "0.0.1"
|
||||
url = "https://beeware.org"
|
||||
license = "BSD license"
|
||||
author = 'Tiberius Yak'
|
||||
author_email = "tiberius@beeware.org"
|
||||
|
||||
[tool.briefcase.app.freedom]
|
||||
formal_name = "Freedom Units"
|
||||
description = "A testing app"
|
||||
sources = ['src/freedom']
|
||||
requires = [
|
||||
'../server/static/wheels/toga_core-0.3.0.dev33-py3-none-any.whl',
|
||||
'../server/static/wheels/travertino-0.1.3-py3-none-any.whl',
|
||||
]
|
||||
|
||||
|
||||
[tool.briefcase.app.freedom.macOS]
|
||||
requires = [
|
||||
'git+https://github.com/beeware/toga.git#egg=toga-cocoa&subdirectory=src/cocoa',
|
||||
'std-nslog>=1.0.0',
|
||||
]
|
||||
|
||||
[tool.briefcase.app.freedom.linux]
|
||||
requires = [
|
||||
'git+https://github.com/beeware/toga.git#egg=toga-gtk&subdirectory=src/gtk',
|
||||
]
|
||||
|
||||
[tool.briefcase.app.freedom.windows]
|
||||
requires = [
|
||||
'git+https://github.com/beeware/toga.git#egg=toga-winforms&subdirectory=src/winforms',
|
||||
]
|
||||
|
||||
# Mobile deployments
|
||||
[tool.briefcase.app.freedom.iOS]
|
||||
requires = [
|
||||
'git+https://github.com/beeware/toga.git#egg=toga-iOS&subdirectory=src/iOS',
|
||||
'std-nslog>=1.0.0',
|
||||
]
|
||||
|
||||
[tool.briefcase.app.freedom.android]
|
||||
requires = [
|
||||
'git+https://github.com/beeware/toga.git#egg=toga-android&subdirectory=src/android',
|
||||
]
|
||||
6
pyscriptjs/examples/toga/freedom/src/freedom/__main__.py
Normal file
6
pyscriptjs/examples/toga/freedom/src/freedom/__main__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from freedom.app import main
|
||||
|
||||
print("IN FREEDOM", main)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main().main_loop()
|
||||
61
pyscriptjs/examples/toga/freedom/src/freedom/app.py
Normal file
61
pyscriptjs/examples/toga/freedom/src/freedom/app.py
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
import toga
|
||||
from toga.style.pack import LEFT, RIGHT, COLUMN, ROW, Pack
|
||||
|
||||
|
||||
class FreedomApp(toga.App):
|
||||
def calculate(self, widget):
|
||||
try:
|
||||
self.c_input.value = (float(self.f_input.value) - 32.0) * 5.0 / 9.0
|
||||
except ValueError:
|
||||
self.c_input.value = '???'
|
||||
|
||||
def startup(self):
|
||||
self.main_window = toga.MainWindow(title=self.name)
|
||||
|
||||
c_box = toga.Box()
|
||||
f_box = toga.Box()
|
||||
box = toga.Box()
|
||||
|
||||
self.c_input = toga.TextInput(id="c_input", readonly=True)
|
||||
self.f_input = toga.TextInput(id="f_input")
|
||||
|
||||
c_label = toga.Label('Celsius', style=Pack(text_align=LEFT))
|
||||
f_label = toga.Label('Fahrenheit', style=Pack(text_align=LEFT))
|
||||
join_label = toga.Label('is equivalent to', style=Pack(text_align=RIGHT))
|
||||
|
||||
button = toga.Button('Calculate', id="calculate", on_press=self.calculate)
|
||||
|
||||
f_box.add(self.f_input)
|
||||
f_box.add(f_label)
|
||||
|
||||
c_box.add(join_label)
|
||||
c_box.add(self.c_input)
|
||||
c_box.add(c_label)
|
||||
|
||||
box.add(f_box)
|
||||
box.add(c_box)
|
||||
box.add(button)
|
||||
|
||||
box.style.update(direction=COLUMN, padding_top=10)
|
||||
f_box.style.update(direction=ROW, padding=5)
|
||||
c_box.style.update(direction=ROW, padding=5)
|
||||
|
||||
self.c_input.style.update(flex=1)
|
||||
self.f_input.style.update(flex=1, padding_left=160)
|
||||
c_label.style.update(width=100, padding_left=10)
|
||||
f_label.style.update(width=100, padding_left=10)
|
||||
join_label.style.update(width=150, padding_right=10)
|
||||
|
||||
button.style.update(padding=15, flex=1)
|
||||
|
||||
self.main_window.content = box
|
||||
self.main_window.show()
|
||||
|
||||
|
||||
def main():
|
||||
return FreedomApp('Freedom Units', 'org.beeware.freedom')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main().main_loop()
|
||||
9
pyscriptjs/examples/toga/requirements.txt
Normal file
9
pyscriptjs/examples/toga/requirements.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
setuptools
|
||||
wheel
|
||||
check-manifest
|
||||
briefcase
|
||||
flask==2.1.1
|
||||
server/static/wheels/toga_core-0.3.0.dev33-py3-none-any.whl
|
||||
server/static/wheels/toga_flask-0.3.0.dev33-py3-none-any.whl
|
||||
server/static/wheels/toga_web-0.3.0.dev33-py3-none-any.whl
|
||||
server/static/wheels/travertino-0.1.3-py3-none-any.whl
|
||||
Reference in New Issue
Block a user