[IPython-dev] custom web notebook cells

Nicholas Bollweg nick.bollweg at gmail.com
Mon Dec 17 19:58:04 EST 2012

Hm... that's pretty cool... how would we know what to work on? I dislike
putting non-python placeholders in the code itself (if that's what you
meant), as, as usual, we'd like the thing to work outside of the web
notebook... even be able to edit it after the fact (and lose the blockly
editability). I was already planning to do something hash-based to make
sure you don't inadvertently destroy stuff.

    # blockly foo
    def foo(bar):
        baz = None
        return baz
    # endblockly foo

A quick thing to remember here is that part of the goodness of blockly is
the type checking; crucial for visual feedback so that you don't try to add
a string to an integer, even though python would happily oblige you! So
this would yield:

    # blockly foo(int bar): str baz
    def foo(bar):
        baz = None
        return baz
    # endblockly foo

Doing comment-based stuff would be rough, as we'd have to write some
tab-completion that knew how to work on fancy comments. Using a de facto
standard like javadoc/rst would be an option, I suppose.

Keeping that in mind, I am thinking to a) keep tab completion and b) keep
the blockly goodness, we'll need to help blockly out. Maybe something like:

    @blockly("foo", args={"bar": int}, _return={"baz": str})
    def foo(bar):
        return baz

Disadvantage here is that the @blockly, which does nothing outside of the
notebook, would be embedded in the code, which is lame.

Additionally, the output cell element gets obliterated every time, so the
decorator approach might be weird... although, as long as you are ONLY
editing a function (and the code doesn't do anything else), it could work.
Actually, I don't know if the display would work correctly.

Also, doing OO with Blockly is not really supported right now: it doesn't
really support the name-based accessing of an object's members, so the leap
could be hard here (assuming the decorator) for an instance method:

    @blockly("__init__", args={"bar": int}, _self={"bar": int})
    class Foo(object):
        def __init__(self, bar):
            self.bar = bar

Which would create a variable Block named, literally, "self.bar" that you
could set stuff to and access. However, at present, it would be hard to
have more than one blockly editor per CodeCell.

Rambling now: need to write code. My next plan was to just try to get some
variables into scope, as the definition of functions, etc. might be "Day 2"
of "Learning Python Visually," but I'll keep some of these things in mind!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20121217/3485e1e1/attachment.html>

More information about the IPython-dev mailing list