Wednesday, March 07, 2007

From GWT to pyGWT (aka pyjamas)

I'm not sure how I stumbled across pyjamas (but it might have something to do with taking the day off to look after my kids) and it is definitely unclear how I will every use this but--it is basically a Python version of Google Web Toolkit where by you define and implement your UI's in Python (or Java in the case of GWT) which in turn gets translated into JavaScript and HTML which will ultimately be processed by the browser and would then be integrated into the web application [framework] or whatever.

For example, here is the UI for email application built with pyjamas. The directory consists of
franz-macbook:~/Documents/dev/playin/pyjamas-0.1/examples/mail mdfranz$ ls
AboutDialog.py Mail.html MailItem.py Mailboxes.py TopPanel.py
Contacts.py Mail.py MailItems.py Shortcuts.py build.sh
Logger.py MailDetail.py MailList.py Tasks.py output

And you run the build.sh script to start the conversion from Python to Javascript (this is calling the master Builder.py script on your python app, in this case Mail.py)
franz-macbook:~/Documents/dev/playin/pyjamas-0.1/examples/mail mdfranz$ ./build.sh
Building 'Mail.py' to output directory 'output'
Copying: public directory
Copying: Mail.html
Copying: pygwt.js
Copying: Images
Creating: Mail.nocache.html
Creating: IE6.cache.html
Importing pyjslib
Importing Mail
Importing Shortcuts
Importing Tasks
Importing ui
Importing pygwt
Importing DeferredCommand
Importing Timer
Importing History
Importing DOM
Importing Mailboxes
Importing Contacts
Importing Logger
Importing TopPanel
Importing AboutDialog
Importing Window
Importing MailList
Importing MailItems
Importing MailItem
Importing MailDetail
Creating: Opera.cache.html
Creating: OldMoz.cache.html
Creating: Safari.cache.html
Creating: Mozilla.cache.html
Done. You can run your app by opening 'output/Mail.html' in a browser
franz-macbook:~/Documents/dev/playin/pyjamas-0.1/examples/mail mdfranz$
Which then creates the following files in the output directory:
franz-macbook:~/Documents/dev/playin/pyjamas-0.1/examples/mail/output mdfranz$ ls
IE6.cache.html Mozilla.cache.html Safari.cache.html tree_open.gif
Mail.html OldMoz.cache.html pygwt.js tree_white.gif
Mail.nocache.html Opera.cache.html tree_closed.gif
As you can see different versions of HTML/Javascript are generated for respective browsers. And what you can't see (because blogger doesn't handle raw HTML very well) is the at the pyqwt.js is what kicks things off.

If this doesn't make sense there is interesting podcast by the Google GWT folks that explains the background on how they problems of JavaScript development (lack of good tools, reliance on browser hacks, browser detection, etc.) led them to come up with the solution to do development in Java and then translate the code into JavaScript.

No comments: