This notebook demonstrates using the %jigsaw magic in IPython.
Dependencies:
Jigsaw is a combination of Google's Blockly drag-and-drop interface in the browser with Python. With Jigsaw, you can:
To use in IPython, you need to add the metakernel magics for IPython:
from metakernel import register_ipython_magics
register_ipython_magics()
Next, let's define some Python things:
x = 42
def myfunc(a, b):
return a + b
Now, we create a Jigsaw workspace named "workspace1". This will create two files in this subdirectory:
Once you have the Jigsaw workspace showing, then you can start dragging blocks around:
%jigsaw Python --workspace workspace1
In the above example, I pulled a print block from the Text category on the left, and a variable block from the Variables category. Snapping them together forms a valid program. I then clicked on the "Run" button to run the code. x got its value from the Python cell above.
Let's create another workspace:
%jigsaw Python --workspace workspace2
In the above example, I dragged the following blocks:
I had to click on the set block and create a new variable named "sqrt_two". I also had to click on the math constant block to change pi to sqrt(2).
If you click on the "Generate Python Code" it will create a new cell below:
import math
print((myfunc(5, 6)))
sqrt_two = math.sqrt(2)
If you enter the variable named "sqrt_two" in the following cell and run it, you get as output the result from running the Jigsaw blocks:
sqrt_two
1.4142135623730951
Try it out!