{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Simple example notebook that shows how one can use widgets to build custom dialogs."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.html import widgets\n",
"from IPython.display import display"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"By using Bootstrap's modal class and ContainerWidgets, we can build a simple dialog window."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def scrub_text_html(text):\n",
" text = text.replace('&', '&')\n",
" text = text.replace(' ', ' ')\n",
" text = text.replace('<', '<')\n",
" text = text.replace('>', '>')\n",
" text = text.replace('\\n', '
\\n')\n",
" return text\n",
"\n",
"def create_dialog(title=None, on_hidden=None):\n",
" dialog = widgets.ContainerWidget(visible=False)\n",
" dialog_header = widgets.ContainerWidget(parent=dialog)\n",
" dialog_header_close = widgets.ButtonWidget(parent=dialog_header, description = '×')\n",
" dialog_header_label = widgets.StringWidget(parent=dialog_header, default_view_name='HTMLView')\n",
" dialog_body = widgets.ContainerWidget(parent=dialog)\n",
" dialog_footer = widgets.ContainerWidget(parent=dialog)\n",
" \n",
" if title is None or title == '':\n",
" title = ' '\n",
" dialog_header_label.value = '