Guide to Pyjs and Pyjsdl

These notes provide instructions on the use of Pyjs with Pyjsdl, which were tested on Linux and Win7 systems.

Installation of Pyjs 0.8.1-dev is required, currently available from Pyjs Github repository. Check instruction on Pyjs Github site.

The tools required for installation are pip and git, install tools if necessary from package manager (Linux) or follow install instructions on tools Webpage (Win7).
Linux:
sudo apt-get install python-pip
sudo apt-get install git

Command to install Pyjs with pip:
Linux system install:
sudo pip install git+https://github.com/pyjs/pyjs.git#egg=pyjs
Linux local install:
pip install git+https://github.com/pyjs/pyjs.git#egg=pyjs –user
Win7:
pip install git+https://github.com/pyjs/pyjs.git#egg=pyjs

With Pyjs installed, pyjsbuild had error ‘pkg_resources.DistributionNotFound: six’, resolved after Pyjs install by upgrading Six dependency:
pip show six (upgrade version 1.3 to 1.8)
Linux:
sudo pip install six –upgrade
Win7:
easy_install –upgrade six

Command to show information of Pyjs installed by pip:
pip show pyjs
>
Linux information:
/local/lib/python2.7/site-packages/
Win7 information:
Location: \python27\lib\site-packages

pyjsbuild and pyjscompressor:
Linux:
/local/bin/
Win7:
\python27\scripts
Refer to these scripts with system path, instances below are in Linux.

To get HTML5 Canvas to work with IE9+, modify Pyjs as described in pyjsdl/guide.txt:
Use files in pyjs_changes.zip/git-140806 to modify or overwrite the following files:
Linux change:
/local/lib/python2.7/site-packages/pyjs/browser.py
/local/lib/python2.7/site-packages/pyjs/boilerplate/home.nocache.html
Win7 change:
\python27\lib\site-packages\pyjs\browser.py
\python27\lib\site-packages\pyjs\boilerplate\home.nocache.html

Use pyjsbuild to compile, check ‘pyjsbuild –help’ for command options. Use compile options -S (strict mode), -O (optimise mode), and -d (debug). Use of –dynamic-link option links JavaScript files in lib folder, decreasing size of browser specific HTML files and permitting shared lib folder with multiple demo apps. Use the -o option to build to separate output folder for different option set. To test installed Pyjs, compile an app from Pyjs examples, which can be downloaded from Pyjs Github repository. Not all examples work, but tested the following:

Helloworld App
change to folder /examples/helloworld
/local/bin/pyjsbuild -S Hello.py –dynamic-link -o output

GWTCanvas App
change to folder /examples/gwtcanvas
/local/bin/pyjsbuild -S GWTCanvasDemo.py –dynamic-link -o output

Compile a Pyjsdl demo with Pyjs and Pyjsdl, download demo app and unpack. Download Pyjsdl and unpack, placing Pyjsdl folder on the path or in the demo app folder. Compile the script with the command:
/local/bin/pyjsbuild -O serpentduel.py –dynamic-link -o output
Following build, place data folder containing images in output folder.
Tested by opening app.html in Firefox, IE, and Chrome.
To open local files, launch Chrome with the option –allow-file-access-from-files
Can use a local server, such as SimpleHTTPServer with command:
python -m SimpleHTTPServer 8000
Server root folder is where command was run, use browser at http://localhost:8000 to browse to HTML file to load.

Use pyjscompressor to compress JavaScript in output folder with command:
python /local/bin/pyjscompressor output
Pyjscompressor uses Closure Compiler, can download latest release and use:
python /local/bin/pyjscompressor output -c /compiler.jar
Pyjscompressor did not work in Pyjs build 140806, with ‘ImportError: No module named contrib.pyjscompressor’, due to missing files apparently left out during installation. Resolved by downloading Pyjs from Pyjs Github repository, and copy missing files from /pyjs/contrib/ to /local/lib/python2.7/site-packages/pyjs/contrib/ (Linux) or \python27\lib\site-packages\pyjs\contrib\ (Win7).

Following compilation with pyjsbuild and optional compression with pyjscompressor, the output folder containing the app can be deployed to a Web server.

This entry was posted in Programming and tagged , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.