Embedding GeoGebra files in IPython notebook

The following notebook is inspired by this ipython-asymptote notebook.

GeoGebra is an open source geometry software.

This page is a IPython notebook, which is essentially a python shell with a HTML-based UI backend. Instructions for downloading and installing the IPython notebook are located here. Notebooks offer a large array of features, such as being able to run commands and display output for programming languages outside of python, and makes developing scripts incrementally and saving intermediate output very easy. Since we can execute arbitrary HTML and JavaScript code in an IPython notebook, we have the capability to embed GeoGebra applets!

A given code cell can be run with the keys <Shift>+<Enter> or the $\blacktriangleright$ button. Commands entered into a IPython cell starting with percent signs ('%') indicate to IPython to use a IPython magic. The GeoGebra IPython magic is a IPython magic which can display Java and (eventually) HTML5 GeoGebra applets.


In [1]:
import os
import sys  

try:
  import pyggb.geogebra_magic
except ImportError:
  # Assuming CWD is examples/
  assert os.path.isfile('../pyggb/geogebra_magic.py')
  sys.path.append('../')
  import pyggb.geogebra_magic

In [2]:
%reload_ext pyggb.geogebra_magic

In [3]:
%ggb?

In [4]:
%ggb --width 650 --height 450 --showToolBar 1 --showResetIcon 1 star.ggb


Out[4]:
Sorry, the GeoGebra Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and activated. (<a href="http://java.sun.com/getjava">Click here to install Java now</a>)

In [5]:
%ggb --width 650 --height 450 noexist.ggb


Out[5]:
Sorry, the GeoGebra Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and activated. (<a href="http://java.sun.com/getjava">Click here to install Java now</a>)

In [6]:
from IPython.display import HTML, Javascript

In [7]:
Javascript("""
document.getElementById("ggb_applet_2").evalCommand("Circle[(0,0), 1]")
""")


Out[7]:

In [8]:
"""
function on_applet_load() {
  document.getElementById("ggb_applet_2").evalCommand("Circle[(0,0),1]");
}
console.log(document.getElementById("ggb_applet_2").status)
document.getElementById("ggb_applet_2").onLoad(on_applet_load)
"""


Out[8]:
'\nfunction on_applet_load() {\n  document.getElementById("ggb_applet_2").evalCommand("Circle[(0,0),1]");\n}\nconsole.log(document.getElementById("ggb_applet_2").status)\ndocument.getElementById("ggb_applet_2").onLoad(on_applet_load)\n'

In [ ]: