Commit c05da985 authored by David Davó's avatar David Davó

Adding new fields to widgets

parent 792ac0ef
...@@ -31,7 +31,7 @@ The initial state must *at least* have the following fields in the `data.state` ...@@ -31,7 +31,7 @@ The initial state must *at least* have the following fields in the `data.state`
- `_view_module_version` - `_view_module_version`
- `_view_name` - `_view_name`
You can see more info on the model state of widgets [here](https://github.com/jupyter-widgets/ipywidgets/blob/master/packages/schema/jupyterwidgetmodels.v8.md). You can see more info on the model state of widgets [here](https://github.com/jupyter-widgets/ipywidgets/blob/master/packages/schema/jupyterwidgetmodels.v8.md), or as a json definition [here](https://github.com/jupyter-widgets/ipywidgets/blob/79312fb164e058c3a2fddd9f3ef35493515ed64b/packages/schema/jupyterwidgetmodels.latest.json)
> Warning!: By default there are two widgets modules: `@jupyter-widgets/controls` and `@jupyter-widgets/base`. > Warning!: By default there are two widgets modules: `@jupyter-widgets/controls` and `@jupyter-widgets/base`.
......
...@@ -13,4 +13,10 @@ then remove the output from the Nootebooks with: ...@@ -13,4 +13,10 @@ then remove the output from the Nootebooks with:
```bash ```bash
jupyter nbconvert *.ipynb --to notebook --inplace --clear-output jupyter nbconvert *.ipynb --to notebook --inplace --clear-output
``` ```
\ No newline at end of file
## Things to do
- [ ] Validate the JSON implementation of widgets against the MsgSpec schema
- [ ] Create integration tests for the widgets
- [ ] Make the `output` widget work
- [ ] Processing of widget messages concurrently
\ No newline at end of file
...@@ -18,6 +18,7 @@ import Prelude ...@@ -18,6 +18,7 @@ import Prelude
import Control.Monad (void) import Control.Monad (void)
import Data.Aeson import Data.Aeson
import Data.IORef (newIORef) import Data.IORef (newIORef)
import Data.Vinyl (Rec(..), (<+>))
import IHaskell.Display import IHaskell.Display
import IHaskell.Eval.Widgets import IHaskell.Eval.Widgets
...@@ -35,7 +36,10 @@ mkCheckBox = do ...@@ -35,7 +36,10 @@ mkCheckBox = do
-- Default properties, with a random uuid -- Default properties, with a random uuid
wid <- U.random wid <- U.random
let widgetState = WidgetState $ defaultBoolWidget "CheckboxView" "CheckboxModel" let boolAttrs = defaultBoolWidget "CheckboxView" "CheckboxModel"
checkBoxAttrs = (Indent =:: True)
:& RNil
widgetState = WidgetState $ boolAttrs <+> checkBoxAttrs
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
......
...@@ -37,8 +37,7 @@ mkToggleButton = do ...@@ -37,8 +37,7 @@ mkToggleButton = do
wid <- U.random wid <- U.random
let boolState = defaultBoolWidget "ToggleButtonView" "ToggleButtonModel" let boolState = defaultBoolWidget "ToggleButtonView" "ToggleButtonModel"
toggleState = (Tooltip =:: "") toggleState = (Icon =:: "")
:& (Icon =:: "")
:& (ButtonStyle =:: DefaultButton) :& (ButtonStyle =:: DefaultButton)
:& RNil :& RNil
widgetState = WidgetState (boolState <+> toggleState) widgetState = WidgetState (boolState <+> toggleState)
......
...@@ -35,15 +35,13 @@ mkButton = do ...@@ -35,15 +35,13 @@ mkButton = do
-- Default properties, with a random uuid -- Default properties, with a random uuid
wid <- U.random wid <- U.random
let dom = defaultDOMWidget "ButtonView" "ButtonModel" let ddw = defaultDescriptionWidget "ButtonView" "ButtonModel"
but = (Description =:: "") but = (Disabled =:: False)
:& (Tooltip =:: "")
:& (Disabled =:: False)
:& (Icon =:: "") :& (Icon =:: "")
:& (ButtonStyle =:: DefaultButton) :& (ButtonStyle =:: DefaultButton)
:& (ClickHandler =:: return ()) :& (ClickHandler =:: return ())
:& RNil :& RNil
buttonState = WidgetState (dom <+> but) buttonState = WidgetState (ddw <+> but)
stateIO <- newIORef buttonState stateIO <- newIORef buttonState
......
...@@ -32,23 +32,9 @@ pattern ModelModule = S.SModelModule ...@@ -32,23 +32,9 @@ pattern ModelModule = S.SModelModule
pattern ModelModuleVersion = S.SModelModuleVersion pattern ModelModuleVersion = S.SModelModuleVersion
pattern ModelName = S.SModelName pattern ModelName = S.SModelName
pattern DisplayHandler = S.SDisplayHandler pattern DisplayHandler = S.SDisplayHandler
pattern Visible = S.SVisible
pattern CSS = S.SCSS
pattern DOMClasses = S.SDOMClasses pattern DOMClasses = S.SDOMClasses
pattern Width = S.SWidth pattern Width = S.SWidth
pattern Height = S.SHeight pattern Height = S.SHeight
pattern Padding = S.SPadding
pattern Margin = S.SMargin
pattern Color = S.SColor
pattern BackgroundColor = S.SBackgroundColor
pattern BorderColor = S.SBorderColor
pattern BorderWidth = S.SBorderWidth
pattern BorderRadius = S.SBorderRadius
pattern BorderStyle = S.SBorderStyle
pattern FontStyle = S.SFontStyle
pattern FontWeight = S.SFontWeight
pattern FontSize = S.SFontSize
pattern FontFamily = S.SFontFamily
pattern Description = S.SDescription pattern Description = S.SDescription
pattern ClickHandler = S.SClickHandler pattern ClickHandler = S.SClickHandler
pattern SubmitHandler = S.SSubmitHandler pattern SubmitHandler = S.SSubmitHandler
...@@ -83,9 +69,8 @@ pattern LowerFloat = S.SLowerFloat ...@@ -83,9 +69,8 @@ pattern LowerFloat = S.SLowerFloat
pattern UpperFloat = S.SUpperFloat pattern UpperFloat = S.SUpperFloat
pattern Orientation = S.SOrientation pattern Orientation = S.SOrientation
pattern BaseFloat = S.SBaseFloat pattern BaseFloat = S.SBaseFloat
pattern ShowRange = S.SShowRange
pattern ReadOut = S.SReadOut pattern ReadOut = S.SReadOut
pattern SliderColor = S.SSliderColor pattern ReadOutFormat = S.SReadOutFormat
pattern BarStyle = S.SBarStyle pattern BarStyle = S.SBarStyle
pattern ChangeHandler = S.SChangeHandler pattern ChangeHandler = S.SChangeHandler
pattern Children = S.SChildren pattern Children = S.SChildren
...@@ -98,8 +83,12 @@ pattern Align = S.SAlign ...@@ -98,8 +83,12 @@ pattern Align = S.SAlign
pattern Titles = S.STitles pattern Titles = S.STitles
pattern SelectedIndex = S.SSelectedIndex pattern SelectedIndex = S.SSelectedIndex
pattern ReadOutMsg = S.SReadOutMsg pattern ReadOutMsg = S.SReadOutMsg
pattern Indent = S.SIndent
pattern Child = S.SChild pattern Child = S.SChild
pattern Selector = S.SSelector pattern Selector = S.SSelector
pattern ContinuousUpdate = S.SContinuousUpdate
pattern Tabbable = S.STabbable
pattern Rows = S.SRows
-- | Close a widget's comm -- | Close a widget's comm
closeWidget :: IHaskellWidget w => w -> IO () closeWidget :: IHaskellWidget w => w -> IO ()
......
...@@ -19,6 +19,7 @@ import Control.Monad (void) ...@@ -19,6 +19,7 @@ import Control.Monad (void)
import Data.Aeson import Data.Aeson
import Data.IORef (newIORef) import Data.IORef (newIORef)
import qualified Data.Scientific as Sci import qualified Data.Scientific as Sci
import Data.Vinyl (Rec(..), (<+>))
import IHaskell.Display import IHaskell.Display
import IHaskell.Eval.Widgets import IHaskell.Eval.Widgets
...@@ -36,7 +37,12 @@ mkBoundedFloatText = do ...@@ -36,7 +37,12 @@ mkBoundedFloatText = do
-- Default properties, with a random uuid -- Default properties, with a random uuid
wid <- U.random wid <- U.random
let widgetState = WidgetState $ defaultBoundedFloatWidget "FloatTextView" "BoundedFloatTextModel" let boundedFloatAttrs = defaultBoundedFloatWidget "FloatTextView" "BoundedFloatTextModel"
textAttrs = (Disabled =:: False)
:& (ContinuousUpdate =:: False)
:& (StepFloat =:: Nothing)
:& RNil
widgetState = WidgetState $ boundedFloatAttrs <+> textAttrs
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
......
...@@ -19,7 +19,7 @@ import Control.Monad (void) ...@@ -19,7 +19,7 @@ import Control.Monad (void)
import Data.Aeson import Data.Aeson
import Data.IORef (newIORef) import Data.IORef (newIORef)
import qualified Data.Scientific as Sci import qualified Data.Scientific as Sci
import Data.Vinyl (Rec(..), (<+>), rput) import Data.Vinyl (Rec(..), (<+>))
import IHaskell.Display import IHaskell.Display
import IHaskell.Eval.Widgets import IHaskell.Eval.Widgets
...@@ -37,15 +37,16 @@ mkFloatLogSlider = do ...@@ -37,15 +37,16 @@ mkFloatLogSlider = do
-- Default properties, with a random uuid -- Default properties, with a random uuid
wid <- U.random wid <- U.random
let boundedFloatAttrs = defaultBoundedFloatWidget "FloatLogSliderView" "FloatLogSliderModel" let boundedLogFloatAttrs = defaultBoundedLogFloatWidget "FloatLogSliderView" "FloatLogSliderModel"
sliderAttrs = (Orientation =:: HorizontalOrientation) sliderAttrs = (StepFloat =:: Just 0.1)
:& (ShowRange =:: False) :& (Orientation =:: HorizontalOrientation)
:& (ReadOut =:: True) :& (ReadOut =:: True)
:& (SliderColor =:: "") :& (ReadOutFormat =:: ".3g")
:& (ContinuousUpdate =:: True)
:& (Disabled =:: False)
:& (BaseFloat =:: 10.0) :& (BaseFloat =:: 10.0)
:& RNil :& RNil
widgetState = WidgetState $ rput (MaxFloat =:: 4.0) widgetState = WidgetState $ boundedLogFloatAttrs <+> sliderAttrs
$ boundedFloatAttrs <+> sliderAttrs
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
......
...@@ -38,10 +38,12 @@ mkFloatSlider = do ...@@ -38,10 +38,12 @@ mkFloatSlider = do
wid <- U.random wid <- U.random
let boundedFloatAttrs = defaultBoundedFloatWidget "FloatSliderView" "FloatSliderModel" let boundedFloatAttrs = defaultBoundedFloatWidget "FloatSliderView" "FloatSliderModel"
sliderAttrs = (Orientation =:: HorizontalOrientation) sliderAttrs = (StepFloat =:: Just 0.1)
:& (ShowRange =:: False) :& (Orientation =:: HorizontalOrientation)
:& (ReadOut =:: True) :& (ReadOut =:: True)
:& (SliderColor =:: "") :& (ReadOutFormat =:: ".2f")
:& (ContinuousUpdate =:: True)
:& (Disabled =:: False)
:& RNil :& RNil
widgetState = WidgetState $ boundedFloatAttrs <+> sliderAttrs widgetState = WidgetState $ boundedFloatAttrs <+> sliderAttrs
......
...@@ -39,10 +39,12 @@ mkFloatRangeSlider = do ...@@ -39,10 +39,12 @@ mkFloatRangeSlider = do
wid <- U.random wid <- U.random
let boundedFloatAttrs = defaultBoundedFloatRangeWidget "FloatRangeSliderView" "FloatRangeSliderModel" let boundedFloatAttrs = defaultBoundedFloatRangeWidget "FloatRangeSliderView" "FloatRangeSliderModel"
sliderAttrs = (Orientation =:: HorizontalOrientation) sliderAttrs = (StepFloat =:: Just 0.1)
:& (ShowRange =:: True) :& (Orientation =:: HorizontalOrientation)
:& (ReadOut =:: True) :& (ReadOut =:: True)
:& (SliderColor =:: "") :& (ReadOutFormat =:: ".2f")
:& (ContinuousUpdate =:: True)
:& (Disabled =:: False)
:& RNil :& RNil
widgetState = WidgetState $ boundedFloatAttrs <+> sliderAttrs widgetState = WidgetState $ boundedFloatAttrs <+> sliderAttrs
......
...@@ -38,7 +38,9 @@ mkFloatText = do ...@@ -38,7 +38,9 @@ mkFloatText = do
wid <- U.random wid <- U.random
let floatAttrs = defaultFloatWidget "FloatTextView" "FloatTextModel" let floatAttrs = defaultFloatWidget "FloatTextView" "FloatTextModel"
textAttrs = (StepFloat =:+ 0.1) textAttrs = (Disabled =:: False)
:& (ContinuousUpdate =:: False)
:& (StepFloat =:: Nothing)
:& RNil :& RNil
widgetState = WidgetState $ floatAttrs <+> textAttrs widgetState = WidgetState $ floatAttrs <+> textAttrs
......
...@@ -19,6 +19,7 @@ import Control.Monad (void) ...@@ -19,6 +19,7 @@ import Control.Monad (void)
import Data.Aeson import Data.Aeson
import Data.IORef (newIORef) import Data.IORef (newIORef)
import qualified Data.Scientific as Sci import qualified Data.Scientific as Sci
import Data.Vinyl (Rec(..), (<+>))
import IHaskell.Display import IHaskell.Display
import IHaskell.Eval.Widgets import IHaskell.Eval.Widgets
...@@ -36,7 +37,12 @@ mkBoundedIntText = do ...@@ -36,7 +37,12 @@ mkBoundedIntText = do
-- Default properties, with a random uuid -- Default properties, with a random uuid
wid <- U.random wid <- U.random
let widgetState = WidgetState $ defaultBoundedIntWidget "IntTextView" "BoundedIntTextModel" let boundedIntAttrs = defaultBoundedIntWidget "IntTextView" "BoundedIntTextModel"
textAttrs = (Disabled =:: False)
:& (ContinuousUpdate =:: False)
:& (StepInt =:: Just 1)
:& RNil
widgetState = WidgetState $ boundedIntAttrs <+> textAttrs
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
......
...@@ -38,10 +38,12 @@ mkIntSlider = do ...@@ -38,10 +38,12 @@ mkIntSlider = do
wid <- U.random wid <- U.random
let boundedIntAttrs = defaultBoundedIntWidget "IntSliderView" "IntSliderModel" let boundedIntAttrs = defaultBoundedIntWidget "IntSliderView" "IntSliderModel"
sliderAttrs = (Orientation =:: HorizontalOrientation) sliderAttrs = (StepInt =:: Just 1)
:& (ShowRange =:: False) :& (Orientation =:: HorizontalOrientation)
:& (ReadOut =:: True) :& (ReadOut =:: True)
:& (SliderColor =:: "") :& (ReadOutFormat =:: "d")
:& (ContinuousUpdate =:: True)
:& (Disabled =:: False)
:& RNil :& RNil
widgetState = WidgetState $ boundedIntAttrs <+> sliderAttrs widgetState = WidgetState $ boundedIntAttrs <+> sliderAttrs
......
...@@ -39,10 +39,12 @@ mkIntRangeSlider = do ...@@ -39,10 +39,12 @@ mkIntRangeSlider = do
wid <- U.random wid <- U.random
let boundedIntAttrs = defaultBoundedIntRangeWidget "IntRangeSliderView" "IntRangeSliderModel" let boundedIntAttrs = defaultBoundedIntRangeWidget "IntRangeSliderView" "IntRangeSliderModel"
sliderAttrs = (Orientation =:: HorizontalOrientation) sliderAttrs = (StepInt =:: Just 1)
:& (ShowRange =:: True) :& (Orientation =:: HorizontalOrientation)
:& (ReadOut =:: True) :& (ReadOut =:: True)
:& (SliderColor =:: "") :& (ReadOutFormat =:: "d")
:& (ContinuousUpdate =:: True)
:& (Disabled =:: False)
:& RNil :& RNil
widgetState = WidgetState $ boundedIntAttrs <+> sliderAttrs widgetState = WidgetState $ boundedIntAttrs <+> sliderAttrs
......
...@@ -38,7 +38,9 @@ mkIntText = do ...@@ -38,7 +38,9 @@ mkIntText = do
wid <- U.random wid <- U.random
let intAttrs = defaultIntWidget "IntTextView" "IntTextModel" let intAttrs = defaultIntWidget "IntTextView" "IntTextModel"
textAttrs = (StepInt =:+ 1) textAttrs = (Disabled =:: False)
:& (ContinuousUpdate =:: False)
:& (StepInt =:: Just 1)
:& RNil :& RNil
widgetState = WidgetState $ intAttrs <+> textAttrs widgetState = WidgetState $ intAttrs <+> textAttrs
......
...@@ -163,7 +163,7 @@ liftToWidgets func rc initvals = do ...@@ -163,7 +163,7 @@ liftToWidgets func rc initvals = do
-- Set initial values for all widgets -- Set initial values for all widgets
setInitialValues initializers widgets initvals setInitialValues initializers widgets initvals
-- applyValueSetters valueSetters widgets $ getList defvals -- applyValueSetters valueSetters widgets $ getList defvals
setField out Width 500 -- setField out Width 500
-- TODO This can't be set right now since we switched FlexBox to a regular -- TODO This can't be set right now since we switched FlexBox to a regular
-- Box. This is a styling/layout parameter now but these haven't been implemented yet. -- Box. This is a styling/layout parameter now but these haven't been implemented yet.
-- setField bx Orientation VerticalOrientation -- setField bx Orientation VerticalOrientation
......
...@@ -38,23 +38,9 @@ singletons ...@@ -38,23 +38,9 @@ singletons
| ModelModuleVersion | ModelModuleVersion
| ModelName | ModelName
| DisplayHandler | DisplayHandler
| Visible
| CSS
| DOMClasses | DOMClasses
| Width | Width
| Height | Height
| Padding
| Margin
| Color
| BackgroundColor
| BorderColor
| BorderWidth
| BorderRadius
| BorderStyle
| FontStyle
| FontWeight
| FontSize
| FontFamily
| Description | Description
| ClickHandler | ClickHandler
| SubmitHandler | SubmitHandler
...@@ -89,9 +75,8 @@ singletons ...@@ -89,9 +75,8 @@ singletons
| UpperFloat | UpperFloat
| Orientation | Orientation
| BaseFloat | BaseFloat
| ShowRange
| ReadOut | ReadOut
| SliderColor | ReadOutFormat
| BarStyle | BarStyle
| ChangeHandler | ChangeHandler
| Children | Children
...@@ -104,7 +89,11 @@ singletons ...@@ -104,7 +89,11 @@ singletons
| Titles | Titles
| SelectedIndex | SelectedIndex
| ReadOutMsg | ReadOutMsg
| Indent
| Child | Child
| Selector | Selector
| ContinuousUpdate
| Tabbable
| Rows
deriving (Eq, Ord, Show) deriving (Eq, Ord, Show)
|] |]
...@@ -36,7 +36,11 @@ mkTextWidget = do ...@@ -36,7 +36,11 @@ mkTextWidget = do
-- Default properties, with a random uuid -- Default properties, with a random uuid
wid <- U.random wid <- U.random
let strWidget = defaultStringWidget "TextView" "TextModel" let strWidget = defaultStringWidget "TextView" "TextModel"
txtWidget = (SubmitHandler =:: return ()) :& (ChangeHandler =:: return ()) :& RNil txtWidget = (Disabled =:: False)
:& (ContinuousUpdate =:: True)
:& (SubmitHandler =:: return ())
:& (ChangeHandler =:: return ())
:& RNil
widgetState = WidgetState $ strWidget <+> txtWidget widgetState = WidgetState $ strWidget <+> txtWidget
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
......
...@@ -35,7 +35,11 @@ mkTextArea = do ...@@ -35,7 +35,11 @@ mkTextArea = do
-- Default properties, with a random uuid -- Default properties, with a random uuid
wid <- U.random wid <- U.random
let strAttrs = defaultStringWidget "TextareaView" "TextareaModel" let strAttrs = defaultStringWidget "TextareaView" "TextareaModel"
wgtAttrs = (ChangeHandler =:: return ()) :& RNil wgtAttrs = (Rows =:: Nothing)
:& (Disabled =:: False)
:& (ContinuousUpdate =:: True)
:& (ChangeHandler =:: return ())
:& RNil
widgetState = WidgetState $ strAttrs <+> wgtAttrs widgetState = WidgetState $ strAttrs <+> wgtAttrs
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment