WKApp - A modern HTML5 UI framework for building iOS apps with Pythonista 3 and WebKit
Project description
pythonista-wkapp
WKApp - A modern HTML5 UI framework for building iOS apps with Pythonista 3 and WebKit
WKApp is a modern, lightweight and minimal application framework for developing Python applications with desktop-class HTML 5 based user interfaces on Apple iOS devices in the Pythonista 3 IDE for iOS.
It is a comprehensive and fully featured alternative to Pythonista's native app ui library, allowing user interfaces to be created with standard web technologies. Using powerful Python templating for dynamic HTML5/CSS/JavaScript views rendering with Mako, simple instanced view state binding supporting auto-wiring GET/POST values and two way Python/JavaScript interop via JSON over thread-safe message handlers.
Creating user interfaces for Python Apps in Pythonista becomes as simple as adding new .html view template files into your project. Which are then served locally from a Bottle.py HTTP/WSGI server and shown in a native WKWebView browser component. WKApp supports creating user interfaces with anything supported by modern web browsers using HTML5, CSS, JavaScript or even WebAssembly and browser based 2D/3D graphics!
Getting started
Pip is the recommended installation method for WKApp.
Install StaSh for Pythonista 3 using the installation instructions from its README first.
Then install the pythonista-wkapp module with pip.
pip install pythonista-wkapp
Alternatively you can also clone or download a zip of this repository and copy/extract the project files into site-packages/wkapp.
To create an app, simply add a folder somewhere containing an app.py file as follows.
from wkapp import *
app = WKApp(__file__)
app.run()
Run this file and you should see a fullscreen browser control and the main view index.html placeholder page shown. You can then start making your own views straight away!
To replace the initial main view / index.html placeholder page:
- Create a
viewsfolder in the same folder as yourapp.pyfile. - Create a file
views/index.html. - Then add your html and setup a
view_classmixin definition like as below.- An instance of this class will be maintained with your view which can be used to store state, bind/manipulate elements, provide functions to be called from Javascript and evaluate Javascript from Python in the view to inspect and alter the DOM or backend state.
A simple views/index.html view example:
<%!
class ViewClass:
def on_init(self):
self.name = ''
def view_action(self, text,*args):
print(text,args)
self.element('header').set('text',f'hello javascript! text was {text} args were {args}')
view_class = ViewClass
%>
<!-- inherit from the view.html template to render the views content inside the apps customisable base layout and structure -->
<%inherit file="view.html"/>
<!-- Your page content goes here -->
<script type="text/javascript">
function invoke_view_action() {
view.invoke('view_action', 'hello python!',
{pass:'any',json:['compatible'], args:{ints:1}, floats:0.5},
['lists',{},1,2.2],
'strings',
'numbers',1,1.5
);
}
</script>
<button onclick="invoke_view_action()">Call Python</button>
<button onclick="app.exit()">Exit Application</button>
<div>
<h1 id="header">Hello World!</h1>
<form method="POST">
<label>Enter your name:</label>
<input name="name" type="text" value="${view.name}" />
<br />
<input type="submit" value="Submit" />
</form>
% if view.name != '':
<h2> Hello ${view.name}! </h2>
% endif
</div>
Note: Code above is one file, it is just shown in two parts here for code highlighting purposes.
Dependencies
WKApp requires the Pythonista 3 app on iOS to run but otherwise uses a minimal set of dependencies:
- Bottle.py 0.13.4
- Mako 1.13.10
- pythonista-wkwebview 1.2 (Bundled)
- 1.2 is an extended version for WKApp, updated with fixes and new features for using the native WKWebView from UIKit on iOS. Including a WKURLSchemeHandler implementation allowing creating custom url schemes with a single handler in a subclass, simplified javascript handlers threading concerns with a Dispatcher, arbitrary arguments passing from javascript to python via json.
- 1.1 Gist (@sbbosco)
- 1.0 Github (@mikaelho)
Bundled Web frontend libraries:
The base app html template bundles with it Bootstrap and JQuery to offer a way to just start developing apps rapidly right away straight out of the box.
However if you prefer other frameworks the base/app.html template can also be customised.
Simply create a copy of views/base/app.html from the repository and add it to your views folder in the same structure views/base/app.html.
Any base template file may be replaced in this same way.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pythonista_wkapp-0.1.2.tar.gz.
File metadata
- Download URL: pythonista_wkapp-0.1.2.tar.gz
- Upload date:
- Size: 120.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e577bb46b182fe784348f24a1c84709d30a377e758cd3096493e8f54bd084da1
|
|
| MD5 |
eaa653291ee65aa24e60cd9845e53bda
|
|
| BLAKE2b-256 |
b937a0ebef190f084ee8a4db7f932844e5e5cae266bdeda846a4a2c758ff0797
|
Provenance
The following attestation bundles were made for pythonista_wkapp-0.1.2.tar.gz:
Publisher:
python-package.yml on M4nw3l/pythonista-wkapp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pythonista_wkapp-0.1.2.tar.gz -
Subject digest:
e577bb46b182fe784348f24a1c84709d30a377e758cd3096493e8f54bd084da1 - Sigstore transparency entry: 984508059
- Sigstore integration time:
-
Permalink:
M4nw3l/pythonista-wkapp@c35fad25cc5a86934ae8eb79dbda7f2bf6f4d25a -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/M4nw3l
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@c35fad25cc5a86934ae8eb79dbda7f2bf6f4d25a -
Trigger Event:
push
-
Statement type:
File details
Details for the file pythonista_wkapp-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pythonista_wkapp-0.1.2-py3-none-any.whl
- Upload date:
- Size: 134.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ae2fb6db255912ddd8c2d25992d9f436247c1ddd14996d189c04aa3340e0f02
|
|
| MD5 |
e2e56448175cf70e50e3f47537887a19
|
|
| BLAKE2b-256 |
30c11aec7f1ac66ad36fdc9719988de3ac83a0cbd46d9075511837ba8cd959a5
|
Provenance
The following attestation bundles were made for pythonista_wkapp-0.1.2-py3-none-any.whl:
Publisher:
python-package.yml on M4nw3l/pythonista-wkapp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pythonista_wkapp-0.1.2-py3-none-any.whl -
Subject digest:
0ae2fb6db255912ddd8c2d25992d9f436247c1ddd14996d189c04aa3340e0f02 - Sigstore transparency entry: 984508062
- Sigstore integration time:
-
Permalink:
M4nw3l/pythonista-wkapp@c35fad25cc5a86934ae8eb79dbda7f2bf6f4d25a -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/M4nw3l
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-package.yml@c35fad25cc5a86934ae8eb79dbda7f2bf6f4d25a -
Trigger Event:
push
-
Statement type: