pyjamasandpyjamasdesktop

http://intranetsdoneright.blogspot.com/ edited this page Jan 21, 2012 · 6 revisions

Pyjamas and Pyjamas Desktop

This diagram explains the relationship between pyjamas and pyjamas desktop, showing how exactly the same application which conforms to the Pyjamas API can be used UNMODIFIED to run on both a web browser and also on the desktop.

         ------->  PYJD                    PYJS     <-----------
         |        desktop                web browser           |
         |            |                     |                  |
         |            ----------+------------                  |
         |                      |                              |
         |                      |                              |
      start app               HTTP Requests                    |
      on desktop            (GET, POST, AJAX, JSONRPC)         |
      with pyjd.py              |                              |
      loader                  Web Server                       |
      program                   |                              |
         |        Django / Pinax / Web2py / blah blah          |
         |                      |                              |
         ^          ------------+------------                  ^
         |          |           |           |                  |
         |       Views        Images   Static HTML <----- Pyjamas Compiler
         |       Forms        SWF      Static JS           pyjs.py
         |       JSONRPC etc. etc.                         build.py
         |                                                     |
         ^                                                     ^
         |                                                     |
         |                Python front-end                     |
         -------<----<----  Source Code        ----->---->------
                          (Conforms to Pyjamas API
                           uses ui.py, DOM.py etc.)
  • In order to run unmodified in both environments, the code MUST use the pyjamas API - ui.py, DOM.py etc.
  • In order to run on the web browser, the code MUST be passed through the Pyjamas compiler and turned into javascript.
  • In order to run on the desktop, the code SHOULD not be passed through the Pyjamas compiler, but is simply executed as-is, as python, using the pyjd libraries (which in turn rely on pywebkitgtk with the webkit-glib bindings).
  • A Web Server is STILL necessary - for both - in order to serve up images, SWF files etc.
  • In BOTH cases, it is necessary to use Window.open, HTTPRequest.py (or JSONService.py) to interact with the web server.
  • You MUST not utilise any "standard" python libraries especially networking ones inside a pyjamas-desktop application if you expect to be able to run it in a browser (through compiling to javascript) as well, because there is no hope - ever - of accessing "standard" python inside a browser restricted environment, across multiple browser platforms.
  • You MUST put such code - networking or database etc. - behind an HTTP-based interface (AJAX, HTTP GET/POST, JSONRPC etc.) running on the Web Server, even if that Web Server is running on the same desktop machine (on loopback 127.0.0.1).

See also