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="https://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.
13 Replies to “Python for XUL scripting”
This is awsome, I can’t wait to integrate this with my remote XUL python framework nufox: https://trac.nunatak.com.au/projects/nufox
Python + moz has a bright future indeed.
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)”
when will the python scripting land in Xulrunner nightlies?
Or where can i download a build with python support in it?
I would also be interested in the date this feature will be out.
Python is my favorite programming language, so I hope that this will be available soo in the standard release of Mozilla/Firefox.
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.
Thanks for the updates they work great.
Very interesting, I loke your example of the mixed scripting.
Thanks for the info!
Thanks for the updates Brendan they work great!!
Very interesting, only in mozilla not correct
view many sites
example : https://games-all.com/
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 😉
Many thanks for the updates Brendan, they work so great.
welcome to http://www.1hc.biz
Comments are closed.