pyjamasandpyjamasdesktop 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              |                              |
      loader                  Web Server                       |
      program                   |                              |
         |        Django / Pinax / Web2py / blah blah          |
         |                      |                              |
         ^          ------------+------------                  ^
         |          |           |           |                  |
         |       Views        Images   Static HTML <----- Pyjamas Compiler
         |       Forms        SWF      Static JS 
         |       JSONRPC etc. etc.               
         |                                                     |
         ^                                                     ^
         |                                                     |
         |                Python front-end                     |
         -------<----<----  Source Code        ----->---->------
                          (Conforms to Pyjamas API
                           uses, etc.)
  • In order to run unmodified in both environments, the code MUST use the pyjamas API -, 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, (or 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

See also