mirror of
https://github.com/IHaskell/IHaskell.git
synced 2025-04-19 12:56:08 +00:00
Add examples
This commit is contained in:
parent
6de64e1497
commit
36a30fdc10
1366
ihaskell-display/ihaskell-widgets/Examples/Bool Widgets.ipynb
Normal file
1366
ihaskell-display/ihaskell-widgets/Examples/Bool Widgets.ipynb
Normal file
File diff suppressed because it is too large
Load Diff
592
ihaskell-display/ihaskell-widgets/Examples/Box Widgets.ipynb
Normal file
592
ihaskell-display/ihaskell-widgets/Examples/Box Widgets.ipynb
Normal file
@ -0,0 +1,592 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### The Box widgets\n",
|
||||
"\n",
|
||||
"+ Box\n",
|
||||
"+ FlexBox\n",
|
||||
"+ Accordion\n",
|
||||
"+ TabWidget"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"source": [
|
||||
"These widgets are used to provide a layout for placing other widgets."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"{-# LANGUAGE OverloadedStrings #-}\n",
|
||||
"import IHaskell.Display.Widgets"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"These widgets have a `Children` field, which accepts a `[ChildWidget]`. A `ChildWidget` can be created using the `ChildWidget` constructor."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>Children :: Field</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"Children :: Field"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>SChildren :: Sing 'Children</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"SChildren :: Sing 'Children"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>ChildWidget :: forall (w :: WidgetType). (RecAll Attr (WidgetFields w) ToPairs) => IPythonWidget w -> ChildWidget</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"ChildWidget :: forall (w :: WidgetType). (RecAll Attr (WidgetFields w) ToPairs) => IPythonWidget w -> ChildWidget"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
":t Children\n",
|
||||
":t SChildren\n",
|
||||
":t ChildWidget"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### `Box` and `FlexBox`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"-- Create new Box and FlexBox\n",
|
||||
"box <- mkBox\n",
|
||||
"flx <- mkFlexBox"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"By default, boxes have a horizontal orientation. Thus adding some widgets to them lays them out horizontally."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import Control.Monad (replicateM)\n",
|
||||
"\n",
|
||||
"-- Make some buttons\n",
|
||||
"buttons <- replicateM 20 mkButton\n",
|
||||
"\n",
|
||||
"-- Add children widgets to boxes\n",
|
||||
"let children = map ChildWidget buttons\n",
|
||||
"setField box SChildren children\n",
|
||||
"setField flx SChildren children\n",
|
||||
"\n",
|
||||
"-- Display boxes\n",
|
||||
"box\n",
|
||||
"flx"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"You might be thinking that there is no difference between `Box` and `FlexBox`, but that's not true.\n",
|
||||
"\n",
|
||||
"Following are some differences:\n",
|
||||
"\n",
|
||||
"+ `Box` is always horizontal, whereas `FlexBox` has a configurable `Orientation`.\n",
|
||||
"+ `FlexBox` is flexible, and the flexibility is determined by its `Flex` field (0 to 2).\n",
|
||||
"+ `FlexBox` also has explicit `Pack` and `Align` fields."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### `Accordion` and `TabWidget`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"These widgets are useful for displaying a variety of content in a small amount of space."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"acc <- mkAccordion\n",
|
||||
"tab <- mkTabWidget"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Let's add some children and see what the result looks like."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"buttons' <- replicateM 5 mkButton\n",
|
||||
"\n",
|
||||
"let children = map ChildWidget buttons'\n",
|
||||
"\n",
|
||||
"setField acc SChildren children\n",
|
||||
"setField tab SChildren children\n",
|
||||
"\n",
|
||||
"acc\n",
|
||||
"tab"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Both the widgets are similar, the only difference is in the orientation. `Accordion` is vertical, whereas `TabWidget` is horizontal."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Haskell",
|
||||
"language": "haskell",
|
||||
"name": "haskell"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
743
ihaskell-display/ihaskell-widgets/Examples/Image Widget.ipynb
Normal file
743
ihaskell-display/ihaskell-widgets/Examples/Image Widget.ipynb
Normal file
@ -0,0 +1,743 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### The `Image` Widget"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"This widget can be used to display images given in the form of base64 encoded `Text`. The widget has a `B64Value` field, which can be changed to display images to it. It also has an `ImageFormat` field, which is set to `PNG` by default."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>IHaskell.Display.base64 :: ByteString -> Base64</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"IHaskell.Display.base64 :: ByteString -> Base64"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>IHaskell.Display.encode64 :: String -> Base64</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"IHaskell.Display.encode64 :: String -> Base64"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
":t IHaskell.Display.base64\n",
|
||||
":t IHaskell.Display.encode64"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The following example downloads an xkcd comic and displays it in an image widget."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"-- Uncomment the line below to install HTTP if you don't have it\n",
|
||||
"-- :!cabal install HTTP\n",
|
||||
"import Network.HTTP\n",
|
||||
"import IHaskell.Display (encode64)\n",
|
||||
"\n",
|
||||
"get url = simpleHTTP (getRequest url) >>= getResponseBody\n",
|
||||
"jpg <- get \"http://imgs.xkcd.com/comics/functional.png\"\n",
|
||||
"\n",
|
||||
"img <- mkImageWidget\n",
|
||||
"setField img SB64Value (encode64 jpg)\n",
|
||||
"img"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Replace the call to undefined by the path to an image, and it will be displayed in an image widget."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='err-msg'>Couldn't match type ‘String’ with ‘B.ByteString’<br/>Expected type: B.ByteString -> IHaskell.Display.Base64<br/> Actual type: String -> IHaskell.Display.Base64<br/>In the second argument of ‘(.)’, namely ‘encode64’<br/>In the second argument of ‘(>>=)’, namely ‘setField i SB64Value . encode64’</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"Couldn't match type ‘String’ with ‘B.ByteString’\n",
|
||||
"Expected type: B.ByteString -> IHaskell.Display.Base64\n",
|
||||
" Actual type: String -> IHaskell.Display.Base64\n",
|
||||
"In the second argument of ‘(.)’, namely ‘encode64’\n",
|
||||
"In the second argument of ‘(>>=)’, namely ‘setField i SB64Value . encode64’"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"imgpath = undefined\n",
|
||||
"\n",
|
||||
"import qualified Data.ByteString as B\n",
|
||||
"import IHaskell.Display (encode64)\n",
|
||||
"\n",
|
||||
"i <- mkImageWidget\n",
|
||||
"B.readFile imgpath >>= setField i SB64Value . encode64"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### The `Selection` Widgets"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"These widgets can be used to select one from many. The `SelectMultiple` widget allows multiple selections, whereas `Dropdown`, `RadioButtons`, `ToggleButtons`, and `Select` only allow one selection."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"-- Allows single selection\n",
|
||||
"tgbs <- mkToggleButtons\n",
|
||||
"\n",
|
||||
"-- Allows multiple selections\n",
|
||||
"msel <- mkSelectMultiple"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"setField msel SDescription \"Functions to show (One or more)\"\n",
|
||||
"setField msel SOptions (OptionLabels [\"sin\", \"cos\"])\n",
|
||||
"\n",
|
||||
"setField tgbs SDescription \"Plot style\"\n",
|
||||
"setField tgbs SOptions (OptionLabels [\"line\", \"point\"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import Graphics.Rendering.Chart.Easy hiding (tan)\n",
|
||||
"import Graphics.Rendering.Chart.Backend.Cairo\n",
|
||||
"import qualified Data.ByteString as B\n",
|
||||
"\n",
|
||||
"import Control.Monad (when, forM)\n",
|
||||
"import Data.Maybe (fromJust)\n",
|
||||
"\n",
|
||||
"dset :: [(String, [(Double, Double)])]\n",
|
||||
"dset = [(\"sin\", zmap sin r), (\"cos\", zmap cos r)]\n",
|
||||
" where zmap f xs = zip xs (map f xs)\n",
|
||||
" r = [0, 0.1 .. 6.3]\n",
|
||||
"\n",
|
||||
"i <- mkImageWidget\n",
|
||||
"setField i SWidth 500\n",
|
||||
"setField i SHeight 500\n",
|
||||
"\n",
|
||||
"-- Redraw the plot based on values from the widgets\n",
|
||||
"refresh = do\n",
|
||||
" -- Read values from the widgets\n",
|
||||
" funs <- map unpack <$> getField msel SSelectedValues\n",
|
||||
" sty <- unpack <$> getField tgbs SSelectedValue\n",
|
||||
" \n",
|
||||
" let pts = zip funs (map (fromJust . flip lookup dset) funs)\n",
|
||||
" opts = def { _fo_size = (500, 500) }\n",
|
||||
" toFile opts \".chart\" $ do\n",
|
||||
" layout_title .= \"Plotting: \" ++ unwords funs\n",
|
||||
" if sty == \"line\"\n",
|
||||
" then mapM_ (\\(s, ps) -> plot (line s [ps])) pts\n",
|
||||
" else mapM_ (\\(s, ps) -> plot (points s ps)) pts\n",
|
||||
"\n",
|
||||
" img <- B.readFile \".chart\"\n",
|
||||
" setField i SB64Value (base64 img)\n",
|
||||
" \n",
|
||||
"-- Add event handlers to make widgets work\n",
|
||||
"setField msel SSelectionHandler refresh\n",
|
||||
"setField tgbs SSelectionHandler refresh"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 26,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"-- Display the widgets\n",
|
||||
"msel\n",
|
||||
"tgbs\n",
|
||||
"i"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The `Dropdown`, `RadioButtons` and `Select` widgets behave just like the `ToggleButtons` widget. They have the same properties, and the same functionality."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### The Numeric Widgets"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**NOTE**: The following examples use widgets with `Int` in their names. There are also analogous widgets with `Float` in their names.\n",
|
||||
"\n",
|
||||
"As the widgets are the same operationally, only the `Int` widgets are shown."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### `IntText` and `BoundedIntText`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 27,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"int <- mkIntText\n",
|
||||
"bit <- mkBoundedIntText"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 28,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"int\n",
|
||||
"bit"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Both the widgets are similar, but the second one possesses some additional properties."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"setField bit SMaxInt 20\n",
|
||||
"setField bit SMinInt 10\n",
|
||||
"setField bit SChangeHandler (getField bit SIntValue >>= print)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now, the first widget will accept arbitrary input whereas the second one wil accept input the the 10-20 range. For example, try entering large values and hitting return/enter in the second widget."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### `IntSlider` and `IntRangeSlider`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Both these widgets are sliders (duh!). `IntSlider` represents a single value, whereas `IntRangeSlider` represents a pair (range) of values."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ins <- mkIntSlider\n",
|
||||
"irs <- mkIntRangeSlider"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ins\n",
|
||||
"irs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(25,75)"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"getField irs SIntPairValue"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### `IntProgress`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"This widget is meant to be used as a progress bar."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 33,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"inp <- mkIntProgress\n",
|
||||
"inp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 34,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"setField inp SIntValue 42"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Haskell",
|
||||
"language": "haskell",
|
||||
"name": "haskell"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
File diff suppressed because it is too large
Load Diff
208
ihaskell-display/ihaskell-widgets/Examples/Numeric Widgets.ipynb
Normal file
208
ihaskell-display/ihaskell-widgets/Examples/Numeric Widgets.ipynb
Normal file
@ -0,0 +1,208 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### The Numeric Widgets\n",
|
||||
"\n",
|
||||
"#### `Int` Widgets\n",
|
||||
"\n",
|
||||
"+ IntText\n",
|
||||
"+ BoundedIntText\n",
|
||||
"+ IntProgress\n",
|
||||
"+ IntSlider\n",
|
||||
"+ IntRangeSlider\n",
|
||||
"\n",
|
||||
"#### `Float` Widgets\n",
|
||||
"\n",
|
||||
"+ FloatText\n",
|
||||
"+ BoundedFloatText\n",
|
||||
"+ FloatProgress\n",
|
||||
"+ FloatSlider\n",
|
||||
"+ FloatRangeSlider\n",
|
||||
"\n",
|
||||
"**NOTE**: Only the `Int` widgets are shown in this notebook. The `Float` widgets are the same as their `Int` counterparts, but hold `Float`s instead of `Int`s."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### `IntText` and `BoundedIntText`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"int <- mkIntText\n",
|
||||
"int"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"bit <- mkBoundedIntText\n",
|
||||
"bit"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Both the widgets are similar, but the second one possesses some additional properties."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"setField bit SMaxInt 20\n",
|
||||
"setField bit SMinInt 10\n",
|
||||
"setField bit SChangeHandler (getField bit SIntValue >>= print)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now, the first widget will accept arbitrary input whereas the second one wil accept input the the 10-20 range. For example, try entering large values and hitting return/enter in the second widget."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### `IntSlider` and `IntRangeSlider`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Both these widgets are sliders (duh!). `IntSlider` represents a single value, whereas `IntRangeSlider` represents a pair (range) of values."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ins <- mkIntSlider\n",
|
||||
"irs <- mkIntRangeSlider"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ins\n",
|
||||
"irs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(25,75)"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"getField irs SIntPairValue"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### `IntProgress`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"This widget is meant to be used as a progress bar."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 33,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"inp <- mkIntProgress\n",
|
||||
"inp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 34,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"setField inp SIntValue 42"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Haskell",
|
||||
"language": "haskell",
|
||||
"name": "haskell"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
845
ihaskell-display/ihaskell-widgets/Examples/Output Widget.ipynb
Normal file
845
ihaskell-display/ihaskell-widgets/Examples/Output Widget.ipynb
Normal file
@ -0,0 +1,845 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### The `OutputWidget`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The output widget can be used to display rich output. `IHaskell.Display` provides functions to create such rich displays from raw data."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>plain :: String -> DisplayData</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"plain :: String -> DisplayData"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>html :: String -> DisplayData</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"html :: String -> DisplayData"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>jpg :: Width -> Height -> Base64 -> DisplayData</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"jpg :: Width -> Height -> Base64 -> DisplayData"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>svg :: String -> DisplayData</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"svg :: String -> DisplayData"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>latex :: String -> DisplayData</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"latex :: String -> DisplayData"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>javascript :: String -> DisplayData</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"javascript :: String -> DisplayData"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>many :: [Display] -> Display</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"many :: [Display] -> Display"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"{-# LANGUAGE OverloadedStrings #-}\n",
|
||||
"import IHaskell.Display.Widgets\n",
|
||||
"import IHaskell.Display\n",
|
||||
":t plain\n",
|
||||
":t html\n",
|
||||
":t jpg\n",
|
||||
":t svg\n",
|
||||
":t latex\n",
|
||||
":t javascript\n",
|
||||
":t many"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The `Output` widget is meant to be used through the functions:\n",
|
||||
"\n",
|
||||
"+ `appendOutput`: Append more output to the widget.\n",
|
||||
"+ `clearOutput`: Clear the output widget ASAP.\n",
|
||||
"+ `clearOutput_`: Clear the output widget on next use of `appendOutput`.\n",
|
||||
"+ `replaceOutput`: Clear then append."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import Text.Printf\n",
|
||||
"o <- mkOutputWidget -- Make output widget\n",
|
||||
"setField o SWidth 500\n",
|
||||
"o -- Display output widget\n",
|
||||
"\n",
|
||||
"fmt = \"<font color=\\\"%s\\\"><marquee direction=\\\"%s\\\" style=\\\"background:%s\\\">%s</marquee></font>\"\n",
|
||||
"add fg bg dir txt = appendOutput o $ html $ printf fmt fg dir bg txt\n",
|
||||
"\n",
|
||||
"add \"WHITE\" \"RED\" \"left\" \"The <b>OUTPUT</b> Widget\"\n",
|
||||
"add \"WHITE\" \"BLUE\" \"right\" \"Is really <b>SIMPLE</b>\"\n",
|
||||
"add \"WHITE\" \"GREEN\" \"left\" \"Use it as an <b>UPDATABLE</b> display</b>\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Currently, the output widget doesn't support displaying other widgets inside it. It does so in IPython, but not in IHaskell."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Haskell",
|
||||
"language": "haskell",
|
||||
"name": "haskell"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
@ -0,0 +1,248 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### The `Selection` Widgets\n",
|
||||
"\n",
|
||||
"+ Dropdown\n",
|
||||
"+ RadioButtons\n",
|
||||
"+ ToggleButtons\n",
|
||||
"+ Select\n",
|
||||
"+ SelectMultiple"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"These widgets can be used to choose between multiple alternatives. The `SelectMultiple` widget allows multiple selections, whereas `Dropdown`, `RadioButtons`, `ToggleButtons`, and `Select` only allow one selection."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"{-# LANGUAGE OverloadedStrings #-}\n",
|
||||
"import IHaskell.Display.Widgets"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"-- Allows single selection\n",
|
||||
"tgbs <- mkToggleButtons\n",
|
||||
"\n",
|
||||
"-- Allows multiple selections\n",
|
||||
"msel <- mkSelectMultiple"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"setField msel SDescription \"Functions to show (One or more)\"\n",
|
||||
"setField msel SOptions (OptionLabels [\"sin\", \"cos\"])\n",
|
||||
"\n",
|
||||
"setField tgbs SDescription \"Plot style\"\n",
|
||||
"setField tgbs SOptions (OptionLabels [\"line\", \"point\"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import Graphics.Rendering.Chart.Easy hiding (tan)\n",
|
||||
"import Graphics.Rendering.Chart.Backend.Cairo\n",
|
||||
"import qualified Data.ByteString as B\n",
|
||||
"import Data.Text (pack, unpack)\n",
|
||||
"import IHaskell.Display (base64)\n",
|
||||
"import Control.Applicative ((<$>))\n",
|
||||
"\n",
|
||||
"import Control.Monad (when, forM)\n",
|
||||
"import Data.Maybe (fromJust)\n",
|
||||
"\n",
|
||||
"dset :: [(String, [(Double, Double)])]\n",
|
||||
"dset = [(\"sin\", zmap sin r), (\"cos\", zmap cos r)]\n",
|
||||
" where zmap f xs = zip xs (map f xs)\n",
|
||||
" r = [0, 0.1 .. 6.3]\n",
|
||||
"\n",
|
||||
"i <- mkImageWidget\n",
|
||||
"setField i SWidth 500\n",
|
||||
"setField i SHeight 500\n",
|
||||
"\n",
|
||||
"-- Redraw the plot based on values from the widgets\n",
|
||||
"refresh = do\n",
|
||||
" -- Read values from the widgets\n",
|
||||
" funs <- map unpack <$> getField msel SSelectedValues\n",
|
||||
" sty <- unpack <$> getField tgbs SSelectedValue\n",
|
||||
" \n",
|
||||
" let pts = zip funs (map (fromJust . flip lookup dset) funs)\n",
|
||||
" opts = def { _fo_size = (500, 500) }\n",
|
||||
" toFile opts \".chart\" $ do\n",
|
||||
" layout_title .= \"Plotting: \" ++ unwords funs\n",
|
||||
" if sty == \"line\"\n",
|
||||
" then mapM_ (\\(s, ps) -> plot (line s [ps])) pts\n",
|
||||
" else mapM_ (\\(s, ps) -> plot (points s ps)) pts\n",
|
||||
"\n",
|
||||
" img <- B.readFile \".chart\"\n",
|
||||
" setField i SB64Value (base64 img)\n",
|
||||
" \n",
|
||||
"-- Add event handlers to make widgets work\n",
|
||||
"setField msel SSelectionHandler refresh\n",
|
||||
"setField tgbs SSelectionHandler refresh"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"-- Display the widgets\n",
|
||||
"msel\n",
|
||||
"tgbs\n",
|
||||
"i"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The `Dropdown`, `RadioButtons` and `Select` widgets behave just like the `ToggleButtons` widget. They have the same properties, and the same functionality."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Haskell",
|
||||
"language": "haskell",
|
||||
"name": "haskell"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
580
ihaskell-display/ihaskell-widgets/Examples/String Widgets.ipynb
Normal file
580
ihaskell-display/ihaskell-widgets/Examples/String Widgets.ipynb
Normal file
@ -0,0 +1,580 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## The String Widgets\n",
|
||||
"\n",
|
||||
"+ HTMLWidget\n",
|
||||
"+ LatexWidget\n",
|
||||
"+ TextWidget\n",
|
||||
"+ TextArea"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"These widgets are used to display data conventionally represented as strings."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"{-# LANGUAGE OverloadedStrings #-}\n",
|
||||
"import IHaskell.Display.Widgets"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"-- Constructors\n",
|
||||
"html <- mkHTMLWidget\n",
|
||||
"latex <- mkLatexWidget\n",
|
||||
"text <- mkTextWidget\n",
|
||||
"area <- mkTextArea"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"These widgets have a `Text` payload, represented by the `StringValue` field."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>StringValue :: Field</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"StringValue :: Field"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<style>/*\n",
|
||||
"Custom IHaskell CSS.\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"/* Styles used for the Hoogle display in the pager */\n",
|
||||
".hoogle-doc {\n",
|
||||
" display: block;\n",
|
||||
" padding-bottom: 1.3em;\n",
|
||||
" padding-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-code {\n",
|
||||
" display: block;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
"}\n",
|
||||
".hoogle-text {\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
".hoogle-name {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-head {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-sub {\n",
|
||||
" display: block;\n",
|
||||
" margin-left: 0.4em;\n",
|
||||
"}\n",
|
||||
".hoogle-package {\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-style: italic;\n",
|
||||
"}\n",
|
||||
".hoogle-module {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
".hoogle-class {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Styles used for basic displays */\n",
|
||||
".get-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
" white-space: pre-wrap;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".show-type {\n",
|
||||
" color: green;\n",
|
||||
" font-weight: bold;\n",
|
||||
" font-family: monospace;\n",
|
||||
" margin-left: 1em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".mono {\n",
|
||||
" font-family: monospace;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg {\n",
|
||||
" color: red;\n",
|
||||
" font-style: italic;\n",
|
||||
" font-family: monospace;\n",
|
||||
" white-space: pre;\n",
|
||||
" display: block;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"#unshowable {\n",
|
||||
" color: red;\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
".err-msg.in.collapse {\n",
|
||||
" padding-top: 0.7em;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Code that will get highlighted before it is highlighted */\n",
|
||||
".highlight-code {\n",
|
||||
" white-space: pre;\n",
|
||||
" font-family: monospace;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/* Hlint styles */\n",
|
||||
".suggestion-warning { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: rgb(200, 130, 0);\n",
|
||||
"}\n",
|
||||
".suggestion-error { \n",
|
||||
" font-weight: bold;\n",
|
||||
" color: red;\n",
|
||||
"}\n",
|
||||
".suggestion-name {\n",
|
||||
" font-weight: bold;\n",
|
||||
"}\n",
|
||||
"</style><span class='get-type'>SStringValue :: Sing 'StringValue</span>"
|
||||
],
|
||||
"text/plain": [
|
||||
"SStringValue :: Sing 'StringValue"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
":t StringValue\n",
|
||||
":t SStringValue -- singleton"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### HTML and Latex"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The `HTMLWidget` and `LatexWidget` display `Text` as rich formatted *HTML* and *LaTeX* respectively."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"-- Display the widgets\n",
|
||||
"html\n",
|
||||
"latex"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"-- Set some html string\n",
|
||||
"setField html SStringValue \"<b>Bold</b>\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"-- Set some latex string\n",
|
||||
"setField latex SStringValue \"$x + y$\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"-- The default width of LatexWidget is somewhat small\n",
|
||||
"setField latex SWidth 400"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We can also add some padding to the widgets."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"setField html SPadding 10\n",
|
||||
"setField latex SPadding 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### `TextWidget` and `TextArea`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"First, let's see what they look like:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"text\n",
|
||||
"area"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"-- Some padding\n",
|
||||
"setField text SPadding 5"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The `TextWidget` and `TextArea` also have a `Placeholder` property, which represents the text displayed in empty widgets."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"setField text SPlaceholder \"Enter your text here...\"\n",
|
||||
"setField area SPlaceholder \"Parsed output will appear here...\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Both the widgets also accept input. The `StringValue` of the widget is automatically updated on every change to the widget. Additionally, the `TextWidget` also has a `SubmitHandler` which is triggered on hitting the return/enter key."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Below we set up the `TextWidget` and `TextArea` for parsing phone numbers using parsec. The `TextWidget` is used to recieve input, and the `TextArea` is used to display output."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"-- Import parsec and other required libraries\n",
|
||||
"\n",
|
||||
"import Text.Parsec\n",
|
||||
"import Text.Parsec.String\n",
|
||||
"import Data.Text (pack, unpack)\n",
|
||||
"import Control.Applicative ((<$>))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now, we can write some parsers:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"-- Parse a single digit\n",
|
||||
"digit :: Parser Char\n",
|
||||
"digit = oneOf ['0'..'9']\n",
|
||||
"\n",
|
||||
"-- Parse a multi-digit number.\n",
|
||||
"number :: Parser Integer\n",
|
||||
"number = do\n",
|
||||
" digits <- many1 digit -- At least one digit\n",
|
||||
" return (read digits) -- Convert [Char] to Integer\n",
|
||||
" \n",
|
||||
"-- Parse a country code, starting with a +.\n",
|
||||
"countryCode :: Parser Integer\n",
|
||||
"countryCode = do\n",
|
||||
" char '+'\n",
|
||||
" number\n",
|
||||
" \n",
|
||||
"-- Parse an area code, optionally with parentheses.\n",
|
||||
"areaCode :: Parser Integer\n",
|
||||
"areaCode = choice [withParens, withoutParens]\n",
|
||||
" where\n",
|
||||
" withParens = between (char '(') (char ')') withoutParens\n",
|
||||
" withoutParens = number\n",
|
||||
" \n",
|
||||
"-- Simple data type representing a phone number.\n",
|
||||
"-- Real phone numbers are much more complex!\n",
|
||||
"data PhoneNumber = PhoneNumber {\n",
|
||||
" phoneCountryCode :: Maybe Integer,\n",
|
||||
" phoneNumbers :: [Integer]\n",
|
||||
" } deriving (Eq, Show)\n",
|
||||
" \n",
|
||||
"phoneNumber :: Parser PhoneNumber\n",
|
||||
"phoneNumber = do\n",
|
||||
" -- Try to parse a country code. If it doesn't work, it's Nothing.\n",
|
||||
" c <- optionMaybe countryCode\n",
|
||||
" optional separator\n",
|
||||
" a1 <- areaCode\n",
|
||||
" separator -- Separator required after area code\n",
|
||||
" a2 <- number\n",
|
||||
" separator -- Separator required before last group of digits\n",
|
||||
" a3 <- number\n",
|
||||
" return (PhoneNumber c [a1, a2, a3])\n",
|
||||
" \n",
|
||||
" where\n",
|
||||
" separator = oneOf \" -\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now, we set the `TextWidget`'s change handler to parse the input, and write the output to the `TextArea`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"setField text SChangeHandler $ do\n",
|
||||
" input <- unpack <$> getField text SStringValue\n",
|
||||
" str <- case parse phoneNumber \"<text widget>\" input of\n",
|
||||
" Left error -> return (show error)\n",
|
||||
" Right x -> return (show x)\n",
|
||||
" setField area SStringValue (pack str)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The `TextArea` doesn't have a `SubmitHandler`, but does have a `ChangeHandler`. It is best used to display large amounts of text."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Haskell",
|
||||
"language": "haskell",
|
||||
"name": "haskell"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user