%! class IndexPlaceHolderView: def on_init(self): #print("View initialise") # automatically called once when the view is created and after view is assigned initial vars self.editor = self.element("editor") #def on_prepare(self): #print("View preparing") # automatically called before this view is served allowing state # to be modified before rendering the page template #def on_loading(self): #print("View loading") # automatically called just after view is served but before fully loaded by browser # can be used to start async tasks while loading ui etc #def on_loaded(self): #print("View loaded") # automatically called once view is fully loaded by browser control def test_action(self, text): print(text) def hello_world_action(self, text): print(text) cur = self.editor.get('text') print(cur) self.editor.set('text',cur + text) view_class = IndexPlaceHolderView %> <%inherit file="view.html"/>
WKApp is a modern, lightweight and minimal application framework for developing Python applications with desktop-class HTML 5 user interfaces on Apple iOS devices in the Pythonista 3 IDE. It provides a simple basis to start creating browser based applications in Pythonista quickly while offering wide customisability capable of developing from simple single page applications through to sophisticated multi-view mobile applications supporting anything you can do in HTML 5 with WebKit support including canvases, browser gaming, media playback, file editing and more. Use any Python libraries from the pip ecosysten that can be installed and supported by Pythonista. And/or use any WebKit/Safafi in browser compatible javascript for client side functionality too. Supporting bi-directional and asyncronous interop between both, Python and JavaScript can work together to produce compelling experiences. Handling styling of your application and concerns like device orientation, screen size and scaling in the same way as any other responsive website using css's powerful, mature and well known feature set. Web frontend libraries Bootstrap 5, for out of the box responsive styling, and JQuery, to ease, extend and perform DOM manipulation, are bundled to help streamline, and give options focused on rapidly developing apps, instead of getting lost down areas such as drawing an apps ui more traditionally for example. The whole of the included base app ui templates and static files are however also customiable and replacable too, so these may be overriden, removed or expanded with plugins etc depending on your applications requirements and needs.
Python Dependencies
Bundled Web frontend libraries:
First, create your app.py file, the bare minimum code to setup, run and display a WKApp is just three lines as follows. app.py ${codeblock(''' from wkapp import * app = WKApp(__file__) app.run() ''')}
When you run this file in Pythonista you should see this page! To create your own make a new file views/index.html, which will then replace this document as the placeholder being shown in your apps main view and re-run: ${codeblock(''' <%inherit file="view.html"/>
Views are served automatically without wire-up and can be navigated as normal web pages, just drop in html templates into the `./views` folder. ${codeblock(''' <%inherit file="view.html"/>
<%inherit file="view.html"/> ''')} Add python behavior to views with inline class mixins, manipulate elements, receive lifecycle events and hold custom page state. ${codeblock(''' <%! class IndexView: def on_init(self): self.editor = self.element('editor') def hello_world_action(self, text): print(text) cur = self.editor.get('text') print(cur) self.editor.set('text',cur + text) view_class = IndexView %> <%inherit file="view.html"/>