Created
February 23, 2014 03:21
-
-
Save Midnighter/9166362 to your computer and use it in GitHub Desktop.
mock-up widget for networkx
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
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:954452ff382802fba5a326b129107c528deb146be85e646bfbdcb091dab3b1c2" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"Mock-up of a Networkx Widget" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from __future__ import print_function\n", | |
"\n", | |
"from IPython.html import widgets\n", | |
"from IPython.display import display\n", | |
"from IPython.utils.traitlets import Unicode" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"menu = widgets.ToggleButtonsWidget(values=[\"\", \"Nodes\", \"Links\", \"Layout\"], value=\"\")\n", | |
"display(menu)\n", | |
"\n", | |
"node_lbl = widgets.CheckboxWidget(description=\"Label\", value=False)\n", | |
"group_key = widgets.TextWidget(description=\"Group Keyword\")\n", | |
"group_update = widgets.ButtonWidget(description=\"Update\")\n", | |
"group_remove = widgets.ButtonWidget(description=\"Remove\")\n", | |
"group_container = widgets.ContainerWidget(children=[group_key, group_update, group_remove])\n", | |
"groups = widgets.ContainerWidget()\n", | |
"nodes = widgets.ContainerWidget(visible=False, children=[node_lbl, group_container, groups])\n", | |
"display(nodes)\n", | |
"group_container.remove_class(\"vbox\")\n", | |
"group_container.add_class(\"hbox\")\n", | |
"\n", | |
"def fake_group_update(clicked):\n", | |
" header = [widgets.HTMLWidget(value=\"<h5>Pick your group colours:</h5>\")]\n", | |
" groups.children = header + [widgets.TextWidget(description=grp) for grp in [\"A\", \"B\", \"C\"]]\n", | |
" groups.visible = True\n", | |
"group_update.on_click(fake_group_update)\n", | |
"\n", | |
"def fake_group_remove(clicked):\n", | |
" groups.visible = False\n", | |
"group_remove.on_click(fake_group_remove)\n", | |
"\n", | |
"link_lbl = widgets.CheckboxWidget(description=\"Label\", value=False)\n", | |
"style = widgets.DropdownWidget(description=\"Style\", values=[\"line\", \"arch\"])\n", | |
"style_box = widgets.ContainerWidget(children=[style])\n", | |
"links = widgets.ContainerWidget(visible=False, children=[link_lbl, style_box])\n", | |
"display(links)\n", | |
"\n", | |
"def on_link_style(name, value):\n", | |
" if value == \"arch\":\n", | |
" style_box.children = [style, widgets.FloatSliderWidget(description=\"Radius\")]\n", | |
" else:\n", | |
" style_box.children = [style]\n", | |
"style.on_trait_change(on_link_style, \"value\")\n", | |
"\n", | |
"layout_list = widgets.DropdownWidget(description=\"Layout Algorithm\", values=[\"spring\", \"circle\"], value=\"spring\")\n", | |
"layouts = widgets.ContainerWidget(visible=False, children=[layout_list, widgets.FloatSliderWidget(description=\"Force\")])\n", | |
"display(layouts)\n", | |
"\n", | |
"def on_layout(name, value):\n", | |
" if value == \"spring\":\n", | |
" layouts.children = [layout_list, widgets.FloatSliderWidget(description=\"Force\")]\n", | |
" elif value == \"circle\":\n", | |
" layouts.children = [layout_list, widgets.FloatSliderWidget(description=\"Radius\")]\n", | |
" else:\n", | |
" layouts.children = [layout_list]\n", | |
"layout_list.on_trait_change(on_layout, \"value\")\n", | |
"\n", | |
"def menu_toggle(name, value):\n", | |
" if value == \"\":\n", | |
" nodes.visible = False\n", | |
" links.visible = False\n", | |
" layouts.visible = False\n", | |
" elif value == \"Nodes\":\n", | |
" nodes.visible = True\n", | |
" links.visible = False\n", | |
" layouts.visible = False\n", | |
" elif value == \"Links\":\n", | |
" nodes.visible = False\n", | |
" links.visible = True\n", | |
" layouts.visible = False\n", | |
" elif value == \"Layout\":\n", | |
" nodes.visible = False\n", | |
" links.visible = False\n", | |
" layouts.visible = True\n", | |
"# menu.values = {\"\": None, \"Nodes\": nodes, \"Links\": links, \"Layout\": None}\n", | |
"# menu.value = None\n", | |
"menu.on_trait_change(menu_toggle, \"value\")" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 2 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment