I announced XUL support for Python at ETech to cheers, and now Mark Hammond has begun delivering the goods. See the DOM_AGNOSTIC_BRANCH for his work to enable Python (and other languages, but Python for sure, and other languages need their own champions to do some work) to be used when writing trusted XUL applications and extensions.
One of Mark’s first testcases, slightly abridged:
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="main-window" orient="vertical"> <script language="python"> <![CDATA[ import xpcom for attr in "document parent top scrollbars name textZoom scrollX scrollY".split(): try: val = getattr(this, attr) except (xpcom.Exception, AttributeError), exc: print "FAILED to get attribute %s: %s" % (attr, exc) else: print attr, "is", val print "Scrollbar visible =", this.scrollbars.visible promptService = xpcom.components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(xpcom.components.interfaces.nsIPromptService) promptService.alert(this.window, "title", "Hello from Python"); ]]> </script> </window>
A more recent example showing how to mix scripting languages:
// Some XUL that uses the default scripting language, JS: <hbox id="language_box"> <button id="but_js" label="click for js" oncommand="dump('hello from jsn');"/> </hbox> // A XUL overlay that uses Python by default: <overlay ... scripttype="application/x-python"> <hbox id="language_box"> <button id="but_python" label="click for Python" oncommand="print 'hello from Python'"/> </hbox> </overlay>
Python for XUL will be available in the Mozilla 1.9 milestone time frame, when the DOM_AGNOSTIC_BRANCH is landed some time this calendar year for sure, but then only in alpha releases and trunk nightly builds. The next major Firefox release based on the 1.9 milestone (Firefox 1.5 is based on the Mozilla 1.8 milestone) will include Mark’s work — but not a C-Python environment by default.
How Windows end users, and others who may not have Python installed already, will get it along with XUL that requires it, remains a problem to be solved. We have net stub installer technology, and now with Firefox 1.5, a patch-based incremental update system. I predict this problem will be solved quickly as great Python-based XUL extensions to Firefox, and new XUL applications built on Firefox or XULRunner, emerge and gain users.
Given evolving JS, why Python? Simple: different programming languages, of different ages, have their strengths, and one of the greatest strength of any solid language is its community. We want to support Python as well as JS for XUL scripting in order to engage a large, creative community of hackers that is mostly disjoint from the web-standards-savvy XUL hackers who are already engaged with Mozilla and Firefox.
We aim to broaden the appeal of our platform in several ways, and supporting Python for XUL is one achievable way to do that, thanks to Mark’s work back in the days when he was employed by Active State, and now that we have him engaged again for the Mozilla Foundation.