Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
22abf977
Commit
22abf977
authored
Jul 04, 2015
by
Sumit Sahrawat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add bool widgets
parent
26903b1e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
161 additions
and
7 deletions
+161
-7
ihaskell-widgets.cabal
ihaskell-display/ihaskell-widgets/ihaskell-widgets.cabal
+2
-0
Widgets.hs
...-display/ihaskell-widgets/src/IHaskell/Display/Widgets.hs
+3
-0
CheckBox.hs
...ell-widgets/src/IHaskell/Display/Widgets/Bool/CheckBox.hs
+64
-0
ToggleButton.hs
...widgets/src/IHaskell/Display/Widgets/Bool/ToggleButton.hs
+69
-0
Common.hs
...y/ihaskell-widgets/src/IHaskell/Display/Widgets/Common.hs
+1
-0
Types.hs
...ay/ihaskell-widgets/src/IHaskell/Display/Widgets/Types.hs
+22
-7
No files found.
ihaskell-display/ihaskell-widgets/ihaskell-widgets.cabal
View file @
22abf977
...
...
@@ -56,6 +56,8 @@ library
-- Modules included in this library but not exported.
other-modules: IHaskell.Display.Widgets.Button
IHaskell.Display.Widgets.Image
IHaskell.Display.Widgets.Bool.CheckBox
IHaskell.Display.Widgets.Bool.ToggleButton
-- IHaskell.Display.Widgets.Dropdown
IHaskell.Display.Widgets.String.HTML
IHaskell.Display.Widgets.String.Latex
...
...
ihaskell-display/ihaskell-widgets/src/IHaskell/Display/Widgets.hs
View file @
22abf977
...
...
@@ -2,6 +2,9 @@ module IHaskell.Display.Widgets (module X) where
import
IHaskell.Display.Widgets.Button
as
X
import
IHaskell.Display.Widgets.Bool.CheckBox
as
X
import
IHaskell.Display.Widgets.Bool.ToggleButton
as
X
-- import IHaskell.Display.Widgets.Dropdown as X
import
IHaskell.Display.Widgets.Image
as
X
...
...
ihaskell-display/ihaskell-widgets/src/IHaskell/Display/Widgets/Bool/CheckBox.hs
0 → 100644
View file @
22abf977
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeSynonymInstances #-}
module
IHaskell.Display.Widgets.Bool.CheckBox
(
-- * The CheckBox Widget
CheckBoxWidget
,
-- * Constructor
mkCheckBoxWidget
,
)
where
-- To keep `cabal repl` happy when running from the ihaskell repo
import
Prelude
import
Control.Monad
(
when
,
join
)
import
Data.Aeson
import
Data.HashMap.Strict
as
HM
import
Data.IORef
(
newIORef
)
import
Data.Text
(
Text
)
import
Data.Vinyl
(
Rec
(
..
),
(
<+>
))
import
IHaskell.Display
hiding
(
Widget
)
import
IHaskell.Eval.Widgets
import
IHaskell.IPython.Message.UUID
as
U
import
IHaskell.Display.Widgets.Types
import
IHaskell.Display.Widgets.Common
-- | A 'CheckBoxWidget' represents a Checkbox widget from IPython.html.widgets.
type
CheckBoxWidget
=
Widget
CheckBoxType
-- | Create a new output widget
mkCheckBoxWidget
::
IO
CheckBoxWidget
mkCheckBoxWidget
=
do
-- Default properties, with a random uuid
uuid
<-
U
.
random
let
widgetState
=
WidgetState
$
defaultBoolWidget
"CheckboxView"
stateIO
<-
newIORef
widgetState
let
widget
=
Widget
uuid
stateIO
initData
=
object
[
"model_name"
.=
str
"WidgetModel"
,
"widget_class"
.=
str
"IPython.Checkbox"
]
-- Open a comm for this widget, and store it in the kernel state
widgetSendOpen
widget
initData
$
toJSON
widgetState
-- Return the image widget
return
widget
instance
IHaskellDisplay
CheckBoxWidget
where
display
b
=
do
widgetSendView
b
return
$
Display
[]
instance
IHaskellWidget
CheckBoxWidget
where
getCommUUID
=
uuid
comm
widget
(
Object
dict1
)
_
=
do
let
key1
=
"sync_data"
::
Text
key2
=
"value"
::
Text
Just
(
Object
dict2
)
=
HM
.
lookup
key1
dict1
Just
(
Bool
value
)
=
HM
.
lookup
key2
dict2
setField'
widget
SBoolValue
value
ihaskell-display/ihaskell-widgets/src/IHaskell/Display/Widgets/Bool/ToggleButton.hs
0 → 100644
View file @
22abf977
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeSynonymInstances #-}
module
IHaskell.Display.Widgets.Bool.ToggleButton
(
-- * The ToggleButton Widget
ToggleButton
,
-- * Constructor
mkToggleButton
,
)
where
-- To keep `cabal repl` happy when running from the ihaskell repo
import
Prelude
import
Control.Monad
(
when
,
join
)
import
Data.Aeson
import
Data.HashMap.Strict
as
HM
import
Data.IORef
(
newIORef
)
import
Data.Text
(
Text
)
import
Data.Vinyl
(
Rec
(
..
),
(
<+>
))
import
IHaskell.Display
hiding
(
Widget
)
import
IHaskell.Eval.Widgets
import
IHaskell.IPython.Message.UUID
as
U
import
IHaskell.Display.Widgets.Types
import
IHaskell.Display.Widgets.Common
-- | A 'ToggleButton' represents a ToggleButton widget from IPython.html.widgets.
type
ToggleButton
=
Widget
ToggleButtonType
-- | Create a new output widget
mkToggleButton
::
IO
ToggleButton
mkToggleButton
=
do
-- Default properties, with a random uuid
uuid
<-
U
.
random
let
boolState
=
defaultBoolWidget
"ToggleButtonView"
toggleState
=
(
STooltip
=::
""
)
:&
(
SIcon
=::
""
)
:&
(
SButtonStyle
=::
DefaultButton
)
:&
RNil
widgetState
=
WidgetState
(
boolState
<+>
toggleState
)
stateIO
<-
newIORef
widgetState
let
widget
=
Widget
uuid
stateIO
initData
=
object
[
"model_name"
.=
str
"WidgetModel"
,
"widget_class"
.=
str
"IPython.ToggleButton"
]
-- Open a comm for this widget, and store it in the kernel state
widgetSendOpen
widget
initData
$
toJSON
widgetState
-- Return the image widget
return
widget
instance
IHaskellDisplay
ToggleButton
where
display
b
=
do
widgetSendView
b
return
$
Display
[]
instance
IHaskellWidget
ToggleButton
where
getCommUUID
=
uuid
comm
widget
(
Object
dict1
)
_
=
do
let
key1
=
"sync_data"
::
Text
key2
=
"value"
::
Text
Just
(
Object
dict2
)
=
HM
.
lookup
key1
dict1
Just
(
Bool
value
)
=
HM
.
lookup
key2
dict2
setField'
widget
SBoolValue
value
ihaskell-display/ihaskell-widgets/src/IHaskell/Display/Widgets/Common.hs
View file @
22abf977
...
...
@@ -71,6 +71,7 @@ singletons [d|
| ButtonStyle
| B64Value
| ImageFormat
| BoolValue
deriving (Eq, Ord, Show)
|]
...
...
ihaskell-display/ihaskell-widgets/src/IHaskell/Display/Widgets/Types.hs
View file @
22abf977
...
...
@@ -27,8 +27,9 @@ import Data.Proxy
import
Data.Vinyl
(
Rec
(
..
),
(
<+>
),
recordToList
,
reifyConstraint
,
rmap
,
Dict
(
..
))
import
Data.Vinyl.Functor
(
Compose
(
..
),
Const
(
..
))
import
Data.Vinyl.Lens
(
rget
,
rput
,
type
(
∈
))
import
qualified
Data.Vinyl.TypeLevel
as
TL
import
Data.Vinyl.TypeLevel
(
RecAll
(
..
))
import
Data.Singletons.Prelude
((
:++
))
import
Data.Singletons.TH
import
Numeric.Natural
...
...
@@ -41,12 +42,13 @@ import IHaskell.Display.Widgets.Common
-- Classes from IPython's widget hierarchy
type
WidgetClass
=
'[
M
odelModule
,
ModelName
,
ViewModule
,
ViewName
,
MsgThrottle
,
Version
,
OnDisplayed
]
type
DOMWidgetClass
=
WidgetClass
TL
.
++
type
DOMWidgetClass
=
WidgetClass
:
++
'[
Visible
,
CSS
,
DOMClasses
,
Width
,
Height
,
Padding
,
Margin
,
Color
,
BackgroundColor
,
BorderColor
,
BorderWidth
,
BorderRadius
,
BorderStyle
,
FontStyle
,
FontWeight
,
FontSize
,
FontFamily
]
type
StringClass
=
DOMWidgetClass
TL
.++
'[
S
tringValue
,
Disabled
,
Description
,
Placeholder
]
type
StringClass
=
DOMWidgetClass
:++
'[
S
tringValue
,
Disabled
,
Description
,
Placeholder
]
type
BoolClass
=
DOMWidgetClass
:++
'[
B
oolValue
,
Disabled
,
Description
]
-- Types associated with Fields
type
family
FieldType
(
f
::
Field
)
::
*
where
...
...
@@ -85,6 +87,7 @@ type family FieldType (f :: Field) :: * where
FieldType
ButtonStyle
=
ButtonStyleValue
FieldType
B64Value
=
Base64
FieldType
ImageFormat
=
ImageFormatValue
FieldType
BoolValue
=
Bool
data
WidgetType
=
ButtonType
|
ImageType
...
...
@@ -93,15 +96,19 @@ data WidgetType = ButtonType
|
LatexType
|
TextType
|
TextAreaType
|
CheckBoxType
|
ToggleButtonType
type
family
WidgetFields
(
w
::
WidgetType
)
::
[
Field
]
where
WidgetFields
ButtonType
=
DOMWidgetClass
TL
.
++
'[
D
escription
,
Tooltip
,
Disabled
,
Icon
,
ButtonStyle
,
ClickHandler
]
WidgetFields
ImageType
=
DOMWidgetClass
TL
.
++
'[
I
mageFormat
,
B64Value
]
WidgetFields
ButtonType
=
DOMWidgetClass
:
++
'[
D
escription
,
Tooltip
,
Disabled
,
Icon
,
ButtonStyle
,
ClickHandler
]
WidgetFields
ImageType
=
DOMWidgetClass
:
++
'[
I
mageFormat
,
B64Value
]
WidgetFields
OutputType
=
DOMWidgetClass
WidgetFields
HTMLType
=
StringClass
WidgetFields
LatexType
=
StringClass
WidgetFields
TextType
=
StringClass
TL
.
++
'[
S
ubmitHandler
]
WidgetFields
TextType
=
StringClass
:
++
'[
S
ubmitHandler
]
WidgetFields
TextAreaType
=
StringClass
WidgetFields
CheckBoxType
=
BoolClass
WidgetFields
ToggleButtonType
=
BoolClass
:++
'[
T
ooltip
,
Icon
,
ButtonStyle
]
newtype
Attr
f
=
Attr
{
_unAttr
::
FieldType
f
}
...
...
@@ -144,6 +151,7 @@ instance ToPairs (Attr Icon) where toPairs (Attr x) = ["icon" .= toJSON x]
instance
ToPairs
(
Attr
ButtonStyle
)
where
toPairs
(
Attr
x
)
=
[
"button_style"
.=
toJSON
x
]
instance
ToPairs
(
Attr
B64Value
)
where
toPairs
(
Attr
x
)
=
[
"_b64value"
.=
toJSON
x
]
instance
ToPairs
(
Attr
ImageFormat
)
where
toPairs
(
Attr
x
)
=
[
"format"
.=
toJSON
x
]
instance
ToPairs
(
Attr
BoolValue
)
where
toPairs
(
Attr
x
)
=
[
"value"
.=
toJSON
x
]
(
=::
)
::
sing
f
->
FieldType
f
->
Attr
f
_
=::
x
=
Attr
x
...
...
@@ -187,10 +195,17 @@ defaultStringWidget viewName = defaultDOMWidget viewName <+> strAttrs
:&
(
SPlaceholder
=::
""
)
:&
RNil
defaultBoolWidget
::
FieldType
ViewName
->
Rec
Attr
BoolClass
defaultBoolWidget
viewName
=
defaultDOMWidget
viewName
<+>
boolAttrs
where
boolAttrs
=
(
SBoolValue
=::
False
)
:&
(
SDisabled
=::
False
)
:&
(
SDescription
=::
""
)
:&
RNil
newtype
WidgetState
w
=
WidgetState
{
_getState
::
Rec
Attr
(
WidgetFields
w
)
}
-- All records with ToPair instances for their Attrs will automatically have a toJSON instance now.
instance
TL
.
RecAll
Attr
(
WidgetFields
w
)
ToPairs
=>
ToJSON
(
WidgetState
w
)
where
instance
RecAll
Attr
(
WidgetFields
w
)
ToPairs
=>
ToJSON
(
WidgetState
w
)
where
toJSON
record
=
object
.
concat
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment