[Web-SIG] JavaScript libraries
Donovan Preston
dp at ulaluma.com
Tue May 3 03:23:22 CEST 2005
On May 2, 2005, at 5:47 PM, Peter Hunt wrote:
> Hello everyone,
>
> A long time ago (before the advent of IronPython), I wrote a small
> Python module that compiled a python file to a JScript.NET file and
> compiled it. Seeing as JScript and JavaScript are very similar, I
> bet this could be very helpful. See http://subway.python-
> hosting.com/attachment/wiki/Py2Js/pyc.2.py for the code.
This is awesome, thank you for posting the link. I had planned on
doing something similar to this for a long time, for both JavaScript
and ActionScript (flash bytecode instead of text script). However
LivePage is just a hobby for me, so I never found time.
> I envision a world where we can write something like:
> <input type="button" onclick="server.onButtonClick()" />
>
> And it will do a server-side RPC to the onButtonClick() method,
> which could do something like this:
> def onButtonClick(ctx):
> ctx.document.writeln("Button clicked")
>
> ctx would serve as a magical proxy for method calls back to the
> client. This would allow seamless integration of JavaScript and
> Python without even writing a line of JS. What do you think?
Yep, this is almost exactly what LivePage looks like.
def onButtonClick(client):
client.sendScript("alert('hello world')")
class Foo(LivePage):
def render_clickable(self, ctx, _):
return ctx.tag(onclick=handler(onButtonClick))
docFactory = loaders.htmlstr('<input type="button"
nevow:render="clickable" />')
I think I like your proposed syntax, with a "server" object in
javascript; I'll mess around with adding support for something like
it to LivePage. I'm not sure I like the magical proxy server-side
interface too much. nevow.livepage.ClientHandle has a nice API which
provides convenient methods for mutating the client side dom:
set - replace an old node's contents with some new contents
append - append a new node as a child of an old one
prepend - prepend a new node as the first child of an old one
alert - show the user an alert
call - call a client side javascript function with some arguments
sendScript - send arbitrary javascript for execution
Donovan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/web-sig/attachments/20050502/96ade40c/attachment.html
More information about the Web-SIG
mailing list