-
Notifications
You must be signed in to change notification settings - Fork 211
GettingStarted
Pyjs is slightly different from traditional Web development: it's more like Desktop application development. This guide should help you to get started quickly in developing your first application. You'll find references to API documentation, more tutorials and other guides in the Resources section below.
Before you continue, be sure that you have these tools installed on your machine:
- python
- virtualenv - a python toolset that allows multiple python sandox installations
- pip - an alternative to the standard python installation tools
-
Get the source either the git (preferred) or snapshot:
git clone https://github.com/pyjs/pyjs.git
-
Change into the pyjs root directory
cd <pyjs dir>
-
Optional step to create your own virtual python sandbox for development purposes
virtualenv mypython
This will create a mypython directory and install sandboxed virtual python installation at
<pyjs root>/mypython
-
Install Pyjs-Tools, Pyjs-Pyjamas and all dependencies
<pyjs root>/mypython/bin/pip install <pyjs root>
OR the following if you want to develop and modify Pyjs-Compiler or Pyjs-Widgets themselves
<pyjs root>/mypython/bin/pip install -e <pyjs root>
- You are now ready to use Pyjs. Scripts for compiling python code to Javascript as well as compiling applications will be installed into the mypython sandbox
- <pyjs root>/mypython/bin/pyjscompile <pyjs root>/mypython/bin/pyjsbuild <pyjs root>/mypython/bin/pyjampiler
-
Go to the examples:
cd examples
Set examples modules:
python .
(or python __main__.py if you have python 2.5 or earlier)
If you've got apache running, add this to your default site config:
Alias /examples "REPLACE THIS/pyjamas/examples/"
<Directory "REPLACE THIS/pyjamas/examples/">
Options Indexes MultiViews FollowSymLinks +ExecCGI
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
AddHandler cgi-script .py
</Directory>
and point your browser to http://localhost/examples/
Checkout the /examples/helloworld/ helloworld example
Look at it /examples/helloworld/output/Hello.html in the browser
Look at the source code:
from pyjamas import Window
from pyjamas.ui import RootPanel, Button
def greet(sender):
Window.alert("Hello, AJAX!")
class Hello:
def onModuleLoad(self):
b = Button("Click me", greet)
RootPanel().add(b)
Play with the code on your local machine, use the build.sh script (or ../../bin/pyjsbuild <ModuleName>) to compile your python code to HTML and JavaScript, see what happens.
- Look at some more examples, in the
/examples/directory - Look at some more examples
- Did I say 'Look at some more examples'?
- Build your own from a copy from
helloworld
If you run into problems installing Pyjs (read: if you can't get the example applications running due to import errors) see the following articles:
- PyjamasUbuntu (if you run Ubuntu the XULrunner/hulahop dependencies may be broken)
- PyjamasAndPyjamasDesktop (Pyjs and Pyjs Desktop)
- InstallingPyjamasAndPyjamasDesktopForWindows (specific for Windows users)
- Pyjs API documentation (on the website)
- UI Hierarchy documentation (on the website)
- Pyjs Examples (lots of show cases!)
- UI controls showcase 1 (Showcase example)
- UI controls showcase 2 (Kitchensink example)
- Pyjs Book (bookreader application written in Pyjs)
-
/controls_tutorial.html- Writing Controls tutorial -
/controls_tutorial02.html- Event Handling tutorial -
/getting_started.html- Getting Started with Pyjs (Tutorial)