webkitpony Documentation

Similar documents
django-xross Documentation

django-session-security Documentation

django-openid Documentation

Reminders. Full Django products are due next Thursday! CS370, Günay (Emory) Spring / 6

django-baton Documentation

Networking & The Web. HCID 520 User Interface Software & Technology

Django-CSP Documentation

django-baton Documentation

Django Leaflet Documentation

CIW 1D CIW JavaScript Specialist.

pyramid_assetmutator Documentation

.. Documentation. Release 0.4 beta. Author

django-ajax-form-mixin Documentation

Client Side JavaScript and AJAX

Using Development Tools to Examine Webpages

AngularJS Fundamentals

Standard 1 The student will author web pages using the HyperText Markup Language (HTML)

Diving into Big Data Workshop

django-avatar Documentation

welcome to BOILERCAMP HOW TO WEB DEV

Django File Picker Documentation

COURSE OUTLINE MOC 20480: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

Django PAM Documentation

Django urls Django Girls Tutorial

django-report-tools Documentation

JavaScript Specialist v2.0 Exam 1D0-735

Django-Select2 Documentation. Nirupam Biswas

Django: Views, Templates, and Sessions

Copyright Descriptor Systems, Course materials may not be reproduced in whole or in part without prior written consent of Joel Barnum

Human-Computer Interaction Design

Jquery Ajax Json Php Mysql Data Entry Example

micawber Documentation

Events & Callbacks (ESaaS 6.5)! 2013 Armando Fox & David Patterson, all rights reserved

Django_template3d Documentation

The course also includes an overview of some of the most popular frameworks that you will most likely encounter in your real work environments.

SAURASHTRA UNIVERSITY

Json Parse Error - No Json Object Could Be Decoded Django Rest Framework

django-inplaceedit Documentation

Course Details. Skills Gained. Who Can Benefit. Prerequisites. View Online URL:

Django File Picker Documentation

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

django-dajaxice Documentation

DJOAuth2 Documentation

Prototype jquery. To and from JavaScript libraries. Remy Sharp (remysharp.com)

django-avatar Documentation

Building a Django Twilio Programmable Chat Application

Django Part II SPARCS 11 undead. Greatly Inspired by SPARCS 10 hodduc

DESIGN AND IMPLEMENTATION OF SAGE DISPLAY CONTROLLER PROJECT

Jquery.ajax Call Returns Status Code Of 200 But Fires Jquery Error

Accelerating Information Technology Innovation

Contents. Demos folder: Demos\14-Ajax. 1. Overview of Ajax. 2. Using Ajax directly. 3. jquery and Ajax. 4. Consuming RESTful services

a Very Short Introduction to AngularJS

kiss.py Documentation

,

Wakanda Architecture. Wakanda is made up of three main components: Wakanda Server Wakanda Studio Wakanda Client Framework

.. Documentation. Release Author

Creating Extensions for Safari

CSE 115. Introduction to Computer Science I

Networking & The Web. HCID 520 User Interface Software & Technology

Grading Rubric Homework 1

Socrates Documentation

Django Graphos Documentation

jquery Tutorial for Beginners: Nothing But the Goods

Django Dynamic Fields Documentation

Easy-select2 Documentation

CSE 115. Introduction to Computer Science I

DATABASE SYSTEMS. Introduction to web programming. Database Systems Course, 2016

django-conduit Documentation

Modern and Responsive Mobile-enabled Web Applications

20486-Developing ASP.NET MVC 4 Web Applications

Decibel Insight Implementation Guide v4.1.6

Django IPRestrict Documentation

MIT AITI Python Software Development Lab DJ1:

Brief Intro to Firebug Sukwon Oh CSC309, Summer 2015

Why attend a Lianja training course? Course overview. Course Details

React.js. a crash course. Jake Zimmerman January 29th, 2016

termite Release 0.0.2

I, J, K. Eclipse, 156

LECTURE 14. Web Frameworks

Getting started with Convertigo Mobilizer

Consent Management Platform (CMP) Full Documentation

CSC 309 The Big Picture

BEFORE CLASS. If you haven t already installed the Firebug extension for Firefox, download it now from

Stepic Plugins Documentation

Week 13 Thursday (with Page 5 corrections)

djangotribune Documentation

Chapter 1 Introduction to Dreamweaver CS3 1. About Dreamweaver CS3 Interface...4. Creating New Webpages...10

Javascript. Many examples from Kyle Simpson: Scope and Closures

Tizen Web Runtime. Ming Jin, Samsung Electronics. (May 8, 2012)

Python-Django-DevOps Documentation

Django Map Widgets Documentation

classjs Documentation

django-revproxy Documentation

AngularJS Intro Homework

Javascript Performance in the Browser. Charlie Fiskeaux II User Interface Engineer

Client-side Debugging. Gary Bettencourt

CSCE 120: Learning To Code

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains an Individual and Group component

A Sample Approach to your Project

IBM. BPM Blueprint; IBM WebSphere Lombardi Edition V7.1, Application Development

Transcription:

webkitpony Documentation Release 0.1 Toni Michel May 24, 2014

Contents 1 Motivation 3 2 Goal 5 3 Understanding webkitpony 7 3.1 Understanding webkitpony........................................ 7 3.2 The webview object........................................... 10 3.3 The webkitpony.js............................................ 10 3.4 The settings module........................................... 11 4 Getting started 13 4.1 Install webkitpony............................................ 13 4.2 Tutorial.................................................. 13 5 Indices and tables 15 i

ii

building webapp-like desktop applications in python webkitpony is a micro framework to build dektop applications with web technologies on the basis of the python binding of the webkit rendering engine (http://code.google.com/p/pywebkitgtk/). The project is hosted on github: https://github.com/tonimichel/webkitpony Artwork by IYOMI Contents 1

2 Contents

CHAPTER 1 Motivation Building desktop applications with standard toolkits like GTK works fine - but tweaking the UI beyond the boundaries of window managers is exhausting. In contrast, building a web ui with HTML, Javascript and CSS is quite flexible. Acctually, the motivation behind webkitpony was to stay in a djangonaut-familiar environment when it comes to build desktop applications. As the basic technology (the webkit rendering engine) was given - it was about playing around and creating a simple-to-use django-like development process. The result was webkitpony. At schnapptack, we use this approach for building desktop applications or solutions that explicitely need a non-browser client. Often we also combine having native logic and remote logic from a web application. 3

4 Chapter 1. Motivation

CHAPTER 2 Goal The goal of webkitpony is to provide an alternative to standard desktop application development approaches. It especially targets on developers familiar with django. However, the framework is so simple, that even non-django programmers will get the point fastly. 5

6 Chapter 2. Goal

CHAPTER 3 Understanding webkitpony 3.1 Understanding webkitpony 3.1.1 Project structure A webitpony project follows a certain structure. The following figure shows the example project _ponyfarm_: Let s start with a brief overview: urls.py: contains a list of tuples, each matching a regular expression (representing a url) to a view function. views.py: contains the view functions referenced in the urls.py module. settings.py: contains your project s settings like e.g. whether to enable the webkit inspector or not. ride.py: the starting point for riding your pony: python ride.py. templates: contains your templates with jinja2 template syntax available. static: contains the static files of your project like css and javascript. Those who are familiar with django might already have become an idea of the webkitpony principle. 3.1.2 HTML - Python Interaction To understand webkitpony, it is important to understand the communication between the web ui and the python code: 7

On the left-hand side we have the webkit (represented as a webview object), which we ll call UI. On the right-hand side we have the python application. Whenever a link is clicked, the url of that link, namely the href attribute is sent to the webkitpony url dispatcher, which looks up the url patterns and triggers the view, passing the webview and url parameters if specified. 3.1.3 A full example As we saw in the figure before, the html contains a button calculate. Note that all links are prefixed with action: which is used to distinguish between referencing urls and files. <body> <a id="calculate" href="action:/calculate/1/">calculate</a> </body> The urls.py module defines a variable urlpatterns. It consists of tuples matching urls to callback functions, which we call views. Each tuple is a regular expression (describing a url) and a view (being invoked if the regex matches). In case a regex contains a grouped expression, its value is passed as parameter to the view function. urlpatterns = ( (r ^calculate/(?p<id>[0-9]+)/$, views.calculate) ) The views.py module defines the view function previously registered on the calculate url. The first paramter is always the webview object representing the webkit. Further parameters depend on the pattern. In this example id is 8 Chapter 3. Understanding webkitpony

passed. def calculate(webview, id): # do some stuff return webview.render( myapplication/myview.html, { this : is, the : template context }) }) As you might notice, this principle is similar to django except, that the view takes a webview object instead of request and returns webview.render instead of a HttpResponse. Again the webview.render is comparable to django.shortcuts.render. It takes a template and a template context. The templates themselfs build upon jinja2. 3.1.4 Passing data from HTML to Python Sometimes we want to send some form data from the UI to our python-side application. As we are not in the web, we do not have POST or GET. So, we need a way to pass data from html to the application. For this purpose webkitpony provides a Javascript connector enabling an Ajax-like JSON communicaton between javascript and python code. Consider the following example: <body> <form id="myform"> <input type="text" value="" name="first_name"> <input type="submit" value="save"> </form> <script> var form = $( #myform ) form.submit(function() { var data = {} form.find( input[type="text"] ).each(function() { var field = $(this) data[field.attr( name )] = field.val() }) webkitpony.send( /calculate/1/, {data: data}, function(response) { console.log( We sent + data + and received + response) }) return false }) </script> </body> To send the form to the application we bind a submit event, construct our json-serializable data object and invoke webkitpony.send(url, data, callback). Similarily to a non-javascript link click, the url is routed through our project s urls.py invoking the matching view function: def calculate(webview, id): result = backend.perform_calculation(webview.data) return webview.json_response({ result : result}) 3.1. Understanding webkitpony 9

The view function unpacks the data from the webview object (similiarily to request.post). Instead of returning webview.render webview.json_response(result) is returned which does not re-rendered the webview. Instead json is passed back to webkitpony.send which finally executes the callback function. Of course, we can also use webkitpony.send for links: <body> <a id="mylink">calculate</a> <script> $( #mylink ).click(function() { webkitpony.send( /calculate/1/, {data: some data }, function(response) { console.log( We sent + data + and received + response) }) return false }) </script> </body> This might be useful to build Javascript applications without reload. 3.2 The webview object The webview object is comparable with the request and response objects of a django request/response cycle and is always passed as first parameter to any view. The public interface provides the following methods and attributes: webview.render(template, context) Renders the webview. Parameter template is a string specifying the path to your template relative to your project s template dir. Parameter context is a dictionary applied as template context. Templates build upon jinja2. webview.json_response(data) Usefull in combination with the client-side webkitpony.send(url, data, callback) from webkitpony.js. Takes a single parameter data which must be a json-serializable data structure, e.g. a dict. Triggers the callback method of the foregoing webkitpony.send passing data as response. webview.data Comparable with request.post. Provides the python deserialized dictionary of the foregoing webkitpony.send code. 3.3 The webkitpony.js The webkitpony.js contains Javascript utils to enable the communication between the UI and the python-side of your application. At the moment webkitpony.js requires jquery, which is inlcuded in the download package. For now webkitpony.js provides a single method: webkitpony.send(url, data, callback) Parameter url is the url being processed by the pony s url dispatcher. data is a json-serializable object which is sent to the application being available in our views via webview.data. callback is a simple function taking a single parameter response. response contains the data sent back by the application. 10 Chapter 3. Understanding webkitpony

3.4 The settings module settings.debug Boolean indicating whether debug or development mode is enabled. If so, the webkit dom inspector and Javascript console as well as the right click context menu of webkit is availbale. settings.witdh The default width when the pony is started. settings.height The default height when the pony is started. settings.resizable Boolean indicating whether the window is resizable or not. settings.urlconf Specifies the project s urlconf module. 3.4. The settings module 11

12 Chapter 3. Understanding webkitpony

CHAPTER 4 Getting started 4.1 Install webkitpony 4.2 Tutorial 13

14 Chapter 4. Getting started

CHAPTER 5 Indices and tables genindex modindex search 15