Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 62 lines (40 sloc) 2.539 kB
8cf9856 @xtfxme test
xtfxme authored
1 Overview
2 ========
3
4 Like GWT, Pyjs translates a Python application and libraries (including UI widgets and DOM classes) into a Javascript application and libraries, and packages it all up:
5
6 [[assets/images/overview.png]]
7
8 [[/assets/images/overview.png]]
9
10 .. image:: ../../raw/HEAD/assets/images/overview.png
11 :align: center
12 :alt: Overview of Pyjs' components
13
14 .. image:: assets/images/overview.png
15 :align: center
16 :alt: Overview of Pyjs' components
17
18 .. image:: /assets/images/overview.png
19 :align: center
20 :alt: Overview of Pyjs' components
21
22 1. **pyjs** translates Python code to Javascript by walking the Python abstract syntax tree and generating Javascript.
23
24 2. **pyjslib** takes care of Python types that require a custom Javascript implementation for pyjs to work. For example, even though Python lists are similar to Javascript arrays, Python lists are converted to custom objects that implement methods such as ``append``.
25
26 3. **UI widgets and a DOM library** are provided as a convenience. They are written in Python and, like everything else, they are translated to Javascript for deployment. These are based on those in GWT.
27
28 4. **build** manages the overall translation of individual components and creates a set of ``.html`` and ``.js`` files that can be served up by a Web server.
29
30 Hello World
31 -----------
32
33 The omnipresent hello world example, let's call it 'Hello Pyjs'::
34
35 from pyjamas.ui.RootPanel import RootPanel
36 from pyjamas.ui.Label import Label
37
38 l = Label('Hello Pyjs')
39 RootPanel().add(l)
40
41 Now run ``pyjsbuild hello.py`` to generate a plain JavaScript application: pyjs creates an ``./output`` folder containing all files you need to move to your webspace later. Of course you can test locally,
42 too.
43
44 Add 3 additional lines in total and your application can run with both
45 Pyjs (i.e. plain Javascript) *and* Pyjs Desktop:
46
47 .. parsed-literal::
48
49 **import pyjd** # this is dummy in pyjs
50 from pyjamas.ui.RootPanel import RootPanel
51 from pyjamas.ui.Label import Label
52
53 **pyjd.setup('public/hello.html')**
54 l = Label('Hello Pyjs')
55 RootPanel().add(l)
56 **pyjd.run()**
57
58 Execute ``pyjd hello.py``, or ``python hello.py``, to run the very same application native on Python, giving you a Python stack trace on errors. Pyjs Desktop gives you much more control making testing and debugging
59 a piece of a cake. Note the ``hello.html`` file referenced above: this is a container for your application generated by Pyjs that you can adjust to your needs.
60
61 Ready for more? [[Let's get started|GettingHelp]]!
Something went wrong with that request. Please try again.