Python for XUL scripting

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:

id="main-window" orient="vertical">
<script language="python">
import xpcom
for attr in "document parent top scrollbars name textZoom scrollX scrollY".split():
val = getattr(this, attr)
except (xpcom.Exception, AttributeError), exc:
print "FAILED to get attribute %s: %s" % (attr, exc)
print attr, "is", val
print "Scrollbar visible =", this.scrollbars.visible
promptService = xpcom.components.classes[";1"]
promptService.alert(this.window, "title", "Hello from Python");

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');"/>
// 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'"/>

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.

Here is a good place to say that while I’ve been helping Firefox 1.5 quite a bit lately, and not working enough on JavaScript futures (about which I hoped to blog last month), I am finally clearing much of my schedule to work with colleagues in ECMA TG1, and with Mozilla hackers, to specify and implement a new version of the language. Since JS is not going away, and our demands on it grow daily, it should evolve.

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.


13 Replies to “Python for XUL scripting”

  1. Seeing that language attribute on the script element really bothers me.
    Fortunately, it’s been fixed already. From bug 255942:
    “Dropped support for language=”python” – now only type=”application/x-python” is used (that is the mine-type registered by that language’s module – it could be anything)”

  2. Hi Brendan,
    when will the python scripting land in Xulrunner nightlies?
    Or where can i download a build with python support in it?

  3. Python is my favorite programming language, so I hope that this will be available soo in the standard release of Mozilla/Firefox.

  4. A couple of updates:
    * the attribute named “scripttype” in the example I showed has been renamed “script-type”.
    * We’re shooting to land markh’s branch (a new one, cut from recent trunk) by 1 November.

  5. I’d love for the python language to come preinstalled on windows.. perhaps if the folks from sun would get involved… I love the python language, and the community that has evolved aroundit; I have learned so much with it so fast. Glad to hear you are working with it, js has enough folks working with it already 😉

Comments are closed.