Created
March 12, 2016 17:03
-
-
Save hiamandeep/bf17e2b4f1a7b4ea5e78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "from __future__ import print_function # For py 2.7 compat" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "from IPython.display import HTML,display" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "/home/aman/.local/lib/python2.7/site-packages/IPython/html.py:14: ShimWarning: The `IPython.html` package has been deprecated. You should import from `notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.\n", | |
| " \"`IPython.html.widgets` has moved to `ipywidgets`.\", ShimWarning)\n", | |
| "/home/aman/.local/lib/python2.7/site-packages/ipykernel/__main__.py:5: DeprecationWarning: metadata {'sync': True} was set from the constructor. Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "from IPython.html import widgets\n", | |
| "from traitlets import Unicode\n", | |
| "\n", | |
| "class HelloWidget(widgets.DOMWidget):\n", | |
| " _view_name = Unicode('HelloView', sync=True)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "from IPython.display import HTML,display\n", | |
| "\n", | |
| "input_form = \"\"\"\n", | |
| "<link rel=\"stylesheet\" href=\"http://mathquill.com/mathquill/mathquill.css\"/>\n", | |
| "<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script>\n", | |
| "<script src=\"http://mathquill.com/mathquill/mathquill.js\"></script>\n", | |
| "\n", | |
| "<p>Type math here: <span id=\"math-field\"></span></p>\n", | |
| "<p>LaTeX of what you typed: <span id=\"latex\"></span></p>\n", | |
| "\"\"\"\n", | |
| "\n", | |
| "javascript = \"\"\"\n", | |
| "<script>\n", | |
| "var mathFieldSpan = document.getElementById('math-field');\n", | |
| "var latexSpan = document.getElementById('latex');\n", | |
| "\n", | |
| "var MQ = MathQuill.getInterface(2); // for backcompat\n", | |
| "var mathField = MQ.MathField(mathFieldSpan, {\n", | |
| " spaceBehavesLikeTab: true, // configurable\n", | |
| " handlers: {\n", | |
| " edit: function() { // useful event handlers\n", | |
| " latexSpan.textContent = mathField.latex(); // simple API\n", | |
| " }\n", | |
| " }\n", | |
| "});\n", | |
| "</script>\n", | |
| "\"\"\"\n", | |
| "#display(HTML(input_form + javascript))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "application/javascript": [ | |
| "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n", | |
| " \n", | |
| " var HelloView = widget.DOMWidgetView.extend({\n", | |
| " \n", | |
| " // Render the view.\n", | |
| " render: function(){ \n", | |
| " this.$el.html('Hello World!'); \n", | |
| " //this.$el.html(input_form + javascript)\n", | |
| " },\n", | |
| " });\n", | |
| " \n", | |
| " manager.WidgetManager.register_widget_view('HelloView', HelloView);\n", | |
| "});" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Javascript object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "%%javascript\n", | |
| "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n", | |
| " \n", | |
| " var HelloView = widget.DOMWidgetView.extend({\n", | |
| " \n", | |
| " // Render the view.\n", | |
| " render: function(){ \n", | |
| " this.$el.html('Hello World!'); \n", | |
| " //this.$el.html(input_form + javascript)\n", | |
| " },\n", | |
| " });\n", | |
| " \n", | |
| " manager.WidgetManager.register_widget_view('HelloView', HelloView);\n", | |
| "});" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "HelloWidget()" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 2", | |
| "language": "python", | |
| "name": "python2" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 2 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython2", | |
| "version": "2.7.11" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment