[IronPython] Python in the Browser updates

Michael Foord fuzzyman at voidspace.org.uk
Thu Jun 19 12:12:24 CEST 2008

Jonathan Slenders wrote:
> You're right there. Copying is no problem, but pasting is. I don't 
> know how often you paste Python code in an interactive terminal, but 
> you should do it literally line by line because of the extra empty 
> line required in the console to close a definition. So, I don't think 
> it's really that important.

I'm forever pasting into consoles... But that aside, both you and Jimmy 
make some very good suggestions.

> If you're interested. The link below is a Vi prototype in the browser 
> written in Javascript. (I hope, you know the basics of Vi, to test it 
> :) ) 

Yep - it feels very broken, which has always been my experience when 
working with Vi... :-)

> From what I remember, it doesn't use a text area, just HTML markup. 
> (It does syncs the content to a text area however, for submitting the 
> form.)
> http://gpl.internetconnection.net/vi/
> Jonathan
> 2008/6/19 Michael Foord <fuzzyman at voidspace.org.uk 
> <mailto:fuzzyman at voidspace.org.uk>>:
>     Hello all,
>     Thanks Jonathan. The approach you suggest has several great
>     advantages. The disadvantages are that you lose the ability to
>     copy and paste (I think most browsers forbid you from manipulating
>     the clipboard from Javascript unless the user has fiddled with
>     some obscure settings).
>     For the first release I'll stick with a textarea but I'll
>     prototype your suggestion for the next release and see what I think.
>     Michael Foord
>     Jonathan Slenders wrote:
>         2008/6/18 Michael Foord <fuzzyman at voidspace.org.uk
>         <mailto:fuzzyman at voidspace.org.uk>
>         <mailto:fuzzyman at voidspace.org.uk
>         <mailto:fuzzyman at voidspace.org.uk>>>:
>            Jimmy Schementi wrote:
>                Michael, question for you:
>                    On every keypress Javascript calls into IronPython (via
>                    the C#!).
>                How come you used C# to handle the onkeypress event? This
>                should do it in Python:
>            Did you look at the code to see why? I'd be really
>         interested to
>            know if I can do what I'm doing from Python inside Silverlight,
>            but I doubt it. There's not much code in total, so it should be
>            easy to follow.
>            I actually handle the onkeypress event from Javascript
>            (onkeypress.js). This calls into 'getSelection'
>         (cursor_pos.js) to
>            work out the current selection in the textarea. Naturally
>         this is
>            easy to do in Firefox / Safari and scarily awful in IE. :-)
>            Having worked these out (and shortcut a few specific
>         scenarios -
>            like ctrl-A, ctrl-Z and ctrl-C), the Javascript then calls into
>            IronPython with the selection start, selection end, and the
>            character that was pressed. I use C# to expose a scriptable
>         type
>            that Javascript can call.
>            I use attaching events from Python to provide the sample code.
>            There are three links above the console and Python handles the
>            'onclick' event to swap the examples around.
>         I think Jimmy is right here. And the parts you did in
>         javascript, could also be done in Silverlight. Some
>         suggestions how I would do this:
>         - instead of a text area, I'd use a html <div> , with CSS
>         "overflow: auto;" for the scrollbars.
>         - insert a <p> tag for each line into the <div>.
>         - capture the body.onkeypress events for input
>         - keep a textinput buffer in IronPython, but show the last
>         line by copying it on each keypress to the last <p>
>         - The cursor could be <span>, styled in CSS to show a pinking
>         cursor.
>         - handle the left/right arrows to shift the cursor
>         - handle the up/down arrows to replace the last <p> with the
>         second last executed command
>         - on a "enter" press, process that line.
>         - when using a <div>, it's even very easy to do syntax
>         highlighting on the fly. Surround known keywords by a <span
>         class="keyword"> and style them.
>         That shouldn't be too hard to do. But you should decide
>         whether it's necessary to have this all in IronPython.
>         Probably, it's the cleanest way to do it.
>         Jonathan
>         ------------------------------------------------------------------------
>         _______________________________________________
>         Users mailing list
>         Users at lists.ironpython.com <mailto:Users at lists.ironpython.com>
>         http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>     _______________________________________________
>     Users mailing list
>     Users at lists.ironpython.com <mailto:Users at lists.ironpython.com>
>     http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> ------------------------------------------------------------------------
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

More information about the Ironpython-users mailing list