Activate your free membership today | Log-in

Tuesday, October 7th, 2008

Pyjamas: GWT for Python

Category: GWT, Python

Last week, we posted a story about deploying GWT to PHP back-ends. We’ve got another GWT-ish post this week: Pyjamas, a sort of GWT for Python.

The SourceForge project page has a brief overview and pointers to a tutorial, a widget showcase, and more.

Posted by Ben Galbraith at 8:00 am
2 Comments

+++--
3.8 rating from 17 votes

Friday, August 8th, 2008

JSBridge: Powering Mozilla with Python

Category: Python

JSBridge is an incredibly alpha, but interesting new project, lead by Mikeal Rogers, that bridges Python and JavaScript with respect to Mozilla. It uses mozrunner, the Python library that can power Mozilla applications (e.g. Firefox).

Once you fire up jsbridge MozRepl will kick into gear, and you will be able to interact across the bridge. “This includes JavaScript < -> Python object translations and a callback mechanism for Python responses to custom events fired in the javascript environment.”

Of course, this isn’t related to IronMonkey the project that allows you to write Python (and Ruby and …) on top of Tamarin.

Posted by Dion Almaer at 7:22 am
3 Comments

+++--
3.2 rating from 9 votes

Monday, August 4th, 2008

Django and ExtJS Grids with Filters

Category: Ext, Python

Are you an ExtJS and Django user? If so, you will want to check out this article by Matt of Tangible Worldwide on Using ExtJS's Grid Filtering with Django.

He goes into detail on how to tweak the grid filtering system that is aimed at PHP, and getting it to work in a way that allows you to write this Django code:

PYTHON:
  1.  
  2. # take a ContentType model name (say, from the URL)
  3. # and create a QuerySet
  4. ctype = ContentType.objects.get(model=ctype_model)
  5. model_class = ctype.model_class()
  6. obj_qs = model_class.objects.filter()
  7.  
  8. # 'q' is the set of POSTed filtering parameters
  9. filter_params = request.POST.get('q', '[]')
  10.  
  11. # decode the filtering parameters w/ simplejson
  12. filter_params = simplejson.loads(filter_params)
  13.  
  14. # apply the filtering params
  15. filtered_qs = get_queryset_from_ext_filters(obj_qs, filter_params)
  16.  

ExtJS 2.1 saw inclusion of the popular (at least in my world) user extension for AJAX filtering of data by grid columns. As useful as this is (provided you can abide by the GPL or paid licensing options), the filter parameters serialized as a PHP array, which is not particularly useful for other languages. With a quick modification to the grid filtering serialization method and a helper function for Django, we can rewire the system to send a JSON string that Django can use to directly apply filtering to a QuerySet. I've found that most clients love having this sort of command and flexibility over their data -- especially the kind that don't necessarily realize that this visualization and control exists. I like that. Additionally, the amount of work and code required is minimal, and the code both reusable and straight-forward. I like that, too.

There are 4 steps to this process:

  1. Modify the serialization method in GridFilters.js
  2. Set up the helper function that will process the QuerySet with the grid filter parameters
  3. Slightly customize your models (see below)
  4. Add (simple) helper code to your Ajax view

Posted by Dion Almaer at 10:38 am
Comment here

++++-
4.1 rating from 51 votes

Thursday, July 31st, 2008

JSON Pickle: Serialize your complex Python objects to JSON

Category: JSON, Python

John Paulett wanted to be able to define complex Python model objects, then seamlessly pass them into CouchDB and to client-side Javascript.

To make this happen for objects that are beyond primitive sets he created JSON Pickle which has been used on the Universal Feed Parser, and lets you do the following:

PYTHON:
  1.  
  2. >>> import jsonpickle
  3. >>> from jsonpickle.tests.classes import Thing
  4.  
  5. # Create an object.
  6. >>> obj = Thing('A String')
  7. >>> print obj.name
  8. A String
  9.  
  10. # Use jsonpickle to transform the object into a JSON string.
  11. >>> pickled = jsonpickle.dumps(obj)
  12. >>> print pickled
  13. {"child": null, "classname__": "Thing", "name": "A String", "classmodule__": "jsonpickle.tests.classes"}
  14.  
  15. # Use jsonpickle to recreate a Python object from a JSON string
  16. >>> unpickled = jsonpickle.loads(pickled)
  17. >>> print unpickled.name
  18. A String
  19.  

Posted by Dion Almaer at 7:50 am
1 Comment

+++--
3.5 rating from 22 votes

Monday, July 28th, 2008

Dojango: Two great tastes in one can!

Category: Dojo, Framework, Python

Dojango, a template Django application that includes full Dojo support baked in, has been released by Tobias Klipstein, Nikolai Onken, and Wolfram Kriesing.

  • It provides capabilities to easily switch between several Dojo versions and sources (e.g. aol, google, local)
  • Delivers helping utilities, that makes the development of rich internet applications in combination with dojo more comfortable.
  • It makes the building of your own packed Dojo release easier.
  • It includes a reusable django app that provides Dojo
  • It includes helper functions, i.e. JSON conversion

Posted by Dion Almaer at 10:22 am
1 Comment

+++--
3.5 rating from 42 votes

Monday, July 7th, 2008

LLVM and running C as well as Python in the browser

Category: JavaScript, Python

Dan Morrill doesn't like JavaScript 2. His reasoning is a little like the folks who don't want Java.Next to try to copy features from every other language, but to just be the best static language, and let other languages like Scala, Groovy, JRuby (and the hundreds of others like Fan) go in different directions on the same Java platform.

You could argue the same for the browser platform. Why push JavaScript 2 further than cleaning it up, and instead allow other languages to augment it.

This is where technology such as IronMonkey come in, as well as the work that Scott Peterson is doing, written up here:

Scott Petersen from Adobe gave a talk at Mozilla on a toolchain he’s been creating—soon to be open-sourced—that allows C code to be targeted to the Tamarin virtual machine. Aside from being a really interesting piece of technology, I thought its implications for the web were pretty impressive.

If I followed his presentation right, Petersen’s toolchain works something like this:

  1. A special version of the GNU C Compiler—possibly llvm-gcc—compiles C code into instructions for the Low Level Virtual Machine.
  2. The LLVM instructions are converted into opcodes for a custom Virtual Machine that runs in ActionScript, a variant of ECMAScript and sibling of JavaScript.
  3. The ActionScript is automatically compiled into Tamarin bytecode by Adobe Flash, which may be further compiled into native machine language by Tamarin’s Just-in-Time (JIT) compiler.

The toolchain includes lots of other details, such as a custom POSIX system call API and a C multimedia library that provides access to Flash. And there’s some things that Petersen had to add to Tamarin, such as a native byte array that maps directly to RAM, thereby allowing the VM’s “emulation” of memory to have only a minor overhead over the real thing.

The end result is the ability to run a wide variety of existing C code in Flash at acceptable speeds. Petersen demonstrated a version of Quake running in a Flash app, as well as a C-based Nintendo emulator running Zelda; both were eminently playable, and included sound effects and music.

Posted by Dion Almaer at 8:50 am
7 Comments

++++-
4.3 rating from 17 votes

Friday, January 12th, 2007

Creating a Flex application using the TurboGears framework

Category: Adobe, Python, Screencast

Screencasts are a nice way to learn certain things. Adobe has done a fun one, and got their own James Ward, and the knowledgeable Bruce Eckel together to write some code.

The coding session is the pair of them building a sample app from scratch using TurboGears on the backend, and Flex on the front end.

It is fun to see Bruce using plain old vi for his python hacking, and James gets to go into uber-IDE land with the Flex Builder (built on Eclipse).


Posted by Dion Almaer at 7:31 am
1 Comment

+++--
3.9 rating from 25 votes

Monday, November 6th, 2006

Pyjamas: Pythons answer to GWT

Category: GWT, Python

If you are a python coder who doesn't like JavaScript and wishes she could stay in python land more, maybe pyjamas is the framework for you.

It is an early stage port of sorts of GWT.

Given that a lot of python goes on at Google, they may be interested in this themselves, and it would be really nice if the underlying JavaScript was shared where it made sense:

  • Shared ugly browser handling fluff
  • Java oddity handling
  • Python oddity handling

Then other languages and platforms could come to the party and play too.

Pyjamas

Posted by Dion Almaer at 6:54 pm
9 Comments

++++-
4 rating from 28 votes

Monday, May 1st, 2006

MochiKit Releases Version 1.3

Category: JavaScript, Library, Python

mochi kit logo
MochiKit, "a lightweight JavaScript Library", has released version 1.3.1. The highlight of this release is MochiKit.Signal - a simple universal event handling system. Other features include additional examples, improved documentation, and changes and tweaks to Async, Base, Logging, and Dom and packages.

For the full list of changes, check the version history, or just download it and try it. Also, if you are coming to the Ajax Experience, don't miss Bob's Intro to MochiKit if you are interesed in this library.

Posted by Rob Sanheim at 10:38 pm
9 Comments

++++-
4.2 rating from 31 votes

Monday, February 20th, 2006

The Future of JavaScript: an Update from Brendan Eich

Category: Firefox, JavaScript, Programming, Python

Brendan Eich has posted a status update on some of the work going into the upcoming JavaScript 2, aka ECMAScript Edition 4 (ES4). One feature that should look familiar to Python hackers are generators and iterators, as seen in the following example taken from a console session:

JAVASCRIPT:
  1. js> function count(n) {
  2.     for (var i = 0; i <n; i++)
  3.         yield i;
  4. }
  5. js> g = count(10)
  6. [object Generator]
  7. js> g.next()
  8. 0
  9. js> g.next()
  10. 1
  11. js> two_to_nine = [i for i in g]
  12. 2,3,4,5,6,7,8,9
  13. js> squares_to_20 = [i * i for i in count(20)]
  14. 0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361

Why go with the Python style and syntax?

Given the years of development in Python and similarities to ECMAScript in application domains and programmer communities, we would rather follow than lead. By standing on Python’s shoulders we reuse developer knowledge as well as design and implementation experience. The trick then becomes not borrowing too much from Python, just enough to gain the essential benefits: structured value-generating continuations and a general iteration protocol.

Brendan also mentioned that support for XUL in Python is almost done, and should land back into the main Firefox codebase from the DOM_AGNOSTIC2_BRANCH soon.

The official spec that will lead the way is ECMA TG1, which is being worked on by Brendan along with colleagues from Mozilla, Adobe, and Microsoft. Lets hope Brendan's vision for JavaScript's future will become reality:

My gut says that we will successfully evolve JS into a much stronger language, with a better and more standard library ecosystem, for the next ten years of its life. I will wager that other browsers will follow the ES4 standard, possibly even in 2007.

Posted by Rob Sanheim at 7:00 am
33 Comments

++++-
4 rating from 111 votes

Tuesday, January 31st, 2006

Django adopts Dojo as Ajax framework

Category: Dojo, Programming, Python

django logo
Django, the Python "Web Framework for Perfectionists", is bundling Dojo for Ajax with its 0.92 release, due in out in a few weeks. The initial integration will use Dojo in the admin interface of Django, but the toolkit will be available for any part of a Django app.

It was recently announced that the Java framework WebWork 2.2 will be released with Dojo under the hood, so this looks like another vote of confidence from the open source community in Dojo's quality.

Thanks to Eugene, who also blogged about the announcement.

Posted by Rob Sanheim at 11:39 pm
13 Comments

++++-
4.1 rating from 57 votes