Commit 48c3c1f6 authored by Sumit Sahrawat's avatar Sumit Sahrawat

Make widget messages match with IPywidgets

The ihaskell-widgets should send messages identical to what the
IPywidgets send. This has not been tested as there are some unresolved
issues in IHaskell that surface only if ipywidgets is installed.
parent fe02d7db
...@@ -40,11 +40,9 @@ mkCheckBox = do ...@@ -40,11 +40,9 @@ mkCheckBox = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget 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 -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the image widget -- Return the image widget
return widget return widget
......
...@@ -45,11 +45,9 @@ mkToggleButton = do ...@@ -45,11 +45,9 @@ mkToggleButton = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget 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 -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the image widget -- Return the image widget
return widget return widget
......
...@@ -40,10 +40,9 @@ mkBox = do ...@@ -40,10 +40,9 @@ mkBox = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let box = IPythonWidget uuid stateIO let box = IPythonWidget uuid stateIO
initData = object ["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.Box"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen box initData $ toJSON widgetState widgetSendOpen box $ toJSON widgetState
-- Return the widget -- Return the widget
return box return box
......
...@@ -46,10 +46,9 @@ mkFlexBox = do ...@@ -46,10 +46,9 @@ mkFlexBox = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let box = IPythonWidget uuid stateIO let box = IPythonWidget uuid stateIO
initData = object ["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.FlexBox"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen box initData $ toJSON widgetState widgetSendOpen box $ toJSON widgetState
-- Return the widget -- Return the widget
return box return box
......
...@@ -41,11 +41,9 @@ mkAccordion = do ...@@ -41,11 +41,9 @@ mkAccordion = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let box = IPythonWidget uuid stateIO let box = IPythonWidget uuid stateIO
initData = object
["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.Accordion"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen box initData $ toJSON widgetState widgetSendOpen box $ toJSON widgetState
-- Return the widget -- Return the widget
return box return box
......
...@@ -41,10 +41,9 @@ mkTabWidget = do ...@@ -41,10 +41,9 @@ mkTabWidget = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let box = IPythonWidget uuid stateIO let box = IPythonWidget uuid stateIO
initData = object ["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.Tab"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen box initData $ toJSON widgetState widgetSendOpen box $ toJSON widgetState
-- Return the widget -- Return the widget
return box return box
......
...@@ -49,10 +49,8 @@ mkButton = do ...@@ -49,10 +49,8 @@ mkButton = do
let button = IPythonWidget uuid stateIO let button = IPythonWidget uuid stateIO
let initData = object ["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.Button"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen button initData $ toJSON buttonState widgetSendOpen button $ toJSON buttonState
-- Return the button widget -- Return the button widget
return button return button
......
...@@ -18,6 +18,8 @@ import qualified IHaskell.Display.Widgets.Singletons as S ...@@ -18,6 +18,8 @@ import qualified IHaskell.Display.Widgets.Singletons as S
pattern ViewModule = S.SViewModule pattern ViewModule = S.SViewModule
pattern ViewName = S.SViewName pattern ViewName = S.SViewName
pattern ModelModule = S.SModelModule
pattern ModelName = S.SModelName
pattern MsgThrottle = S.SMsgThrottle pattern MsgThrottle = S.SMsgThrottle
pattern Version = S.SVersion pattern Version = S.SVersion
pattern DisplayHandler = S.SDisplayHandler pattern DisplayHandler = S.SDisplayHandler
......
...@@ -42,13 +42,9 @@ mkBoundedFloatText = do ...@@ -42,13 +42,9 @@ mkBoundedFloatText = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
[ "model_name" .= str "WidgetModel"
, "widget_class" .= str "IPython.BoundedFloatText"
]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -44,13 +44,9 @@ mkFloatProgress = do ...@@ -44,13 +44,9 @@ mkFloatProgress = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
[ "model_name" .= str "WidgetModel"
, "widget_class" .= str "IPython.FloatProgress"
]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -47,11 +47,9 @@ mkFloatSlider = do ...@@ -47,11 +47,9 @@ mkFloatSlider = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.FloatSlider"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -50,13 +50,9 @@ mkFloatRangeSlider = do ...@@ -50,13 +50,9 @@ mkFloatRangeSlider = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
[ "model_name" .= str "WidgetModel"
, "widget_class" .= str "IPython.FloatRangeSlider"
]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -41,11 +41,9 @@ mkFloatText = do ...@@ -41,11 +41,9 @@ mkFloatText = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.FloatText"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -46,10 +46,8 @@ mkImageWidget = do ...@@ -46,10 +46,8 @@ mkImageWidget = do
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
let initData = object ["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.Image"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the image widget -- Return the image widget
return widget return widget
......
...@@ -41,13 +41,9 @@ mkBoundedIntText = do ...@@ -41,13 +41,9 @@ mkBoundedIntText = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
[ "model_name" .= str "WidgetModel"
, "widget_class" .= str "IPython.BoundedIntText"
]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -44,11 +44,9 @@ mkIntProgress = do ...@@ -44,11 +44,9 @@ mkIntProgress = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.IntProgress"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -47,11 +47,9 @@ mkIntSlider = do ...@@ -47,11 +47,9 @@ mkIntSlider = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.IntSlider"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -48,13 +48,9 @@ mkIntRangeSlider = do ...@@ -48,13 +48,9 @@ mkIntRangeSlider = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
[ "model_name" .= str "WidgetModel"
, "widget_class" .= str "IPython.IntRangeSlider"
]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -41,10 +41,9 @@ mkIntText = do ...@@ -41,10 +41,9 @@ mkIntText = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object ["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.IntText"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -45,10 +45,9 @@ mkOutputWidget = do ...@@ -45,10 +45,9 @@ mkOutputWidget = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object ["model_name" .= str "WidgetModel"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the image widget -- Return the image widget
return widget return widget
......
...@@ -41,11 +41,9 @@ mkDropdown = do ...@@ -41,11 +41,9 @@ mkDropdown = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.Dropdown"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -39,11 +39,9 @@ mkRadioButtons = do ...@@ -39,11 +39,9 @@ mkRadioButtons = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.RadioButtons"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -39,10 +39,9 @@ mkSelect = do ...@@ -39,10 +39,9 @@ mkSelect = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object ["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.Select"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -40,13 +40,9 @@ mkSelectMultiple = do ...@@ -40,13 +40,9 @@ mkSelectMultiple = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
[ "model_name" .= str "WidgetModel"
, "widget_class" .= str "IPython.SelectMultiple"
]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -44,13 +44,9 @@ mkToggleButtons = do ...@@ -44,13 +44,9 @@ mkToggleButtons = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
[ "model_name" .= str "WidgetModel"
, "widget_class" .= str "IPython.ToggleButtons"
]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -13,9 +13,11 @@ import Data.Singletons.TH ...@@ -13,9 +13,11 @@ import Data.Singletons.TH
-- Widget properties -- Widget properties
singletons singletons
[d| [d|
data Field = ViewModule data Field = ViewModule
| ViewName | ViewName
| ModelModule
| ModelName
| MsgThrottle | MsgThrottle
| Version | Version
| DisplayHandler | DisplayHandler
......
...@@ -37,10 +37,9 @@ mkHTMLWidget = do ...@@ -37,10 +37,9 @@ mkHTMLWidget = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object ["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.HTML"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -37,10 +37,9 @@ mkLatexWidget = do ...@@ -37,10 +37,9 @@ mkLatexWidget = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object ["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.Latex"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -41,10 +41,9 @@ mkTextWidget = do ...@@ -41,10 +41,9 @@ mkTextWidget = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object ["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.Text"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -41,11 +41,9 @@ mkTextArea = do ...@@ -41,11 +41,9 @@ mkTextArea = do
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
let widget = IPythonWidget uuid stateIO let widget = IPythonWidget uuid stateIO
initData = object
["model_name" .= str "WidgetModel", "widget_class" .= str "IPython.Textarea"]
-- Open a comm for this widget, and store it in the kernel state -- Open a comm for this widget, and store it in the kernel state
widgetSendOpen widget initData $ toJSON widgetState widgetSendOpen widget $ toJSON widgetState
-- Return the widget -- Return the widget
return widget return widget
......
...@@ -57,7 +57,7 @@ module IHaskell.Display.Widgets.Types where ...@@ -57,7 +57,7 @@ module IHaskell.Display.Widgets.Types where
-- To know more about the IPython messaging specification (as implemented in this package) take a -- To know more about the IPython messaging specification (as implemented in this package) take a
-- look at the supplied MsgSpec.md. -- look at the supplied MsgSpec.md.
-- --
-- Widgets are not able to do console input, the reason for that can also be found in the messaging -- Widgets are not able to do console input, the reason for that can be found in the messaging
-- specification -- specification
import Control.Monad (unless, join, when, void, mapM_) import Control.Monad (unless, join, when, void, mapM_)
import Control.Applicative ((<$>)) import Control.Applicative ((<$>))
...@@ -89,7 +89,7 @@ import qualified IHaskell.Display.Widgets.Singletons as S ...@@ -89,7 +89,7 @@ import qualified IHaskell.Display.Widgets.Singletons as S
import IHaskell.Display.Widgets.Common import IHaskell.Display.Widgets.Common
-- Classes from IPython's widget hierarchy. Defined as such to reduce code duplication. -- Classes from IPython's widget hierarchy. Defined as such to reduce code duplication.
type WidgetClass = '[S.ViewModule, S.ViewName, S.MsgThrottle, S.Version, type WidgetClass = '[S.ViewModule, S.ViewName, S.ModelModule, S.ModelName, S.MsgThrottle, S.Version,
S.DisplayHandler] S.DisplayHandler]
type DOMWidgetClass = WidgetClass :++ '[S.Visible, S.CSS, S.DOMClasses, S.Width, S.Height, S.Padding, type DOMWidgetClass = WidgetClass :++ '[S.Visible, S.CSS, S.DOMClasses, S.Width, S.Height, S.Padding,
...@@ -128,10 +128,12 @@ type BoxClass = DOMWidgetClass :++ '[S.Children, S.OverflowX, S.OverflowY, S.Box ...@@ -128,10 +128,12 @@ type BoxClass = DOMWidgetClass :++ '[S.Children, S.OverflowX, S.OverflowY, S.Box
type SelectionContainerClass = BoxClass :++ '[S.Titles, S.SelectedIndex, S.ChangeHandler] type SelectionContainerClass = BoxClass :++ '[S.Titles, S.SelectedIndex, S.ChangeHandler]
-- Types associated with Fields. -- Types associated with Fields.
type family FieldType (f :: Field) :: * where type family FieldType (f :: Field) :: * where
FieldType S.ViewModule = Text FieldType S.ViewModule = Text
FieldType S.ViewName = Text FieldType S.ViewName = Text
FieldType S.ModelModule = Text
FieldType S.ModelName = Text
FieldType S.MsgThrottle = Integer FieldType S.MsgThrottle = Integer
FieldType S.Version = Integer FieldType S.Version = Integer
FieldType S.DisplayHandler = IO () FieldType S.DisplayHandler = IO ()
...@@ -339,6 +341,12 @@ instance ToPairs (Attr S.ViewModule) where ...@@ -339,6 +341,12 @@ instance ToPairs (Attr S.ViewModule) where
instance ToPairs (Attr S.ViewName) where instance ToPairs (Attr S.ViewName) where
toPairs x = ["_view_name" .= toJSON x] toPairs x = ["_view_name" .= toJSON x]
instance ToPairs (Attr S.ModelModule) where
toPairs x = ["_model_module" .= toJSON x]
instance ToPairs (Attr S.ModelName) where
toPairs x = ["_model_name" .= toJSON x]
instance ToPairs (Attr S.MsgThrottle) where instance ToPairs (Attr S.MsgThrottle) where
toPairs x = ["msg_throttle" .= toJSON x] toPairs x = ["msg_throttle" .= toJSON x]
...@@ -591,6 +599,8 @@ reflect = fromSing ...@@ -591,6 +599,8 @@ reflect = fromSing
defaultWidget :: FieldType S.ViewName -> Rec Attr WidgetClass defaultWidget :: FieldType S.ViewName -> Rec Attr WidgetClass
defaultWidget viewName = (ViewModule =:: "") defaultWidget viewName = (ViewModule =:: "")
:& (ViewName =:: viewName) :& (ViewName =:: viewName)
:& (ModelModule =:: "")
:& (ModelName =:: "WidgetModel")
:& (MsgThrottle =:+ 3) :& (MsgThrottle =:+ 3)
:& (Version =:: 0) :& (Version =:: 0)
:& (DisplayHandler =:: return ()) :& (DisplayHandler =:: return ())
......
...@@ -159,9 +159,10 @@ inputReplyParser = requestParser $ \obj -> do ...@@ -159,9 +159,10 @@ inputReplyParser = requestParser $ \obj -> do
commOpenParser :: LByteString -> Message commOpenParser :: LByteString -> Message
commOpenParser = requestParser $ \obj -> do commOpenParser = requestParser $ \obj -> do
uuid <- obj .: "comm_id" uuid <- obj .: "comm_id"
name <- obj .: "target_name" targetName <- obj .: "target_name"
targetModule <- obj .: "target_module"
value <- obj .: "data" value <- obj .: "data"
return $ CommOpen noHeader name uuid value return $ CommOpen noHeader targetName targetModule uuid value
commDataParser :: LByteString -> Message commDataParser :: LByteString -> Message
commDataParser = requestParser $ \obj -> do commDataParser = requestParser $ \obj -> do
......
...@@ -97,7 +97,11 @@ instance ToJSON Message where ...@@ -97,7 +97,11 @@ instance ToJSON Message where
object ["prompt" .= prompt] object ["prompt" .= prompt]
toJSON req@CommOpen{} = toJSON req@CommOpen{} =
object ["comm_id" .= commUuid req, "target_name" .= commTargetName req, "data" .= commData req] object [ "comm_id" .= commUuid req
, "target_name" .= commTargetName req
, "target_module" .= commTargetModule req
, "data" .= commData req
]
toJSON req@CommData{} = toJSON req@CommData{} =
object ["comm_id" .= commUuid req, "data" .= commData req] object ["comm_id" .= commUuid req, "data" .= commData req]
......
...@@ -375,6 +375,7 @@ data Message = ...@@ -375,6 +375,7 @@ data Message =
CommOpen CommOpen
{ header :: MessageHeader { header :: MessageHeader
, commTargetName :: String , commTargetName :: String
, commTargetModule :: String
, commUuid :: UUID , commUuid :: UUID
, commData :: Value , commData :: Value
} }
......
...@@ -52,9 +52,8 @@ widgetSend :: IHaskellWidget a ...@@ -52,9 +52,8 @@ widgetSend :: IHaskellWidget a
widgetSend msgType widget value = queue $ msgType (Widget widget) value widgetSend msgType widget value = queue $ msgType (Widget widget) value
-- | Send a message to open a comm -- | Send a message to open a comm
widgetSendOpen :: IHaskellWidget a => a -> Value -> Value -> IO () widgetSendOpen :: IHaskellWidget a => a -> Value -> IO ()
widgetSendOpen widget initVal stateVal = widgetSendOpen = widgetSend Open
queue $ Open (Widget widget) initVal stateVal
-- | Send a state update message -- | Send a state update message
widgetSendUpdate :: IHaskellWidget a => a -> Value -> IO () widgetSendUpdate :: IHaskellWidget a => a -> Value -> IO ()
...@@ -93,8 +92,9 @@ handleMessage :: (Message -> IO ()) ...@@ -93,8 +92,9 @@ handleMessage :: (Message -> IO ())
-> IO KernelState -> IO KernelState
handleMessage send replyHeader state msg = do handleMessage send replyHeader state msg = do
case msg of case msg of
Open widget initVal stateVal -> do Open widget value -> do
let target = targetName widget let target_name = targetName widget
target_module = targetModule widget
uuid = getCommUUID widget uuid = getCommUUID widget
present = isJust $ Map.lookup uuid oldComms present = isJust $ Map.lookup uuid oldComms
...@@ -109,12 +109,9 @@ handleMessage send replyHeader state msg = do ...@@ -109,12 +109,9 @@ handleMessage send replyHeader state msg = do
if present if present
then return state then return state
else do else do
-- Send the comm open -- Send the comm open, with the initial state
header <- dupHeader replyHeader CommOpenMessage header <- dupHeader replyHeader CommOpenMessage
send $ CommOpen header target uuid initVal send $ CommOpen header target_name target_module uuid value
-- Initial state update
communicate . toJSON $ UpdateState stateVal
-- Send anything else the widget requires. -- Send anything else the widget requires.
open widget communicate open widget communicate
...@@ -123,8 +120,7 @@ handleMessage send replyHeader state msg = do ...@@ -123,8 +120,7 @@ handleMessage send replyHeader state msg = do
return newState return newState
Close widget value -> do Close widget value -> do
let target = targetName widget let uuid = getCommUUID widget
uuid = getCommUUID widget
present = isJust $ Map.lookup uuid oldComms present = isJust $ Map.lookup uuid oldComms
newComms = Map.delete uuid $ openComms state newComms = Map.delete uuid $ openComms state
......
...@@ -65,11 +65,15 @@ class IHaskellDisplay a where ...@@ -65,11 +65,15 @@ class IHaskellDisplay a where
-- | Display as an interactive widget. -- | Display as an interactive widget.
class IHaskellDisplay a => IHaskellWidget a where class IHaskellDisplay a => IHaskellWidget a where
-- | Output target name for this widget. The actual input parameter should be ignored. By default -- | Target name for this widget. The actual input parameter should be ignored. By default
-- evaluate to "ipython.widget", which is used by IPython for its backbone widgets. -- evaluate to "ipython.widget", which is used by IPython for its backbone widgets.
targetName :: a -> String targetName :: a -> String
targetName _ = "ipython.widget" targetName _ = "ipython.widget"
-- | Target module for this widget. Evaluates to an empty string by default.
targetModule :: a -> String
targetModule _ = ""
-- | Get the uuid for comm associated with this widget. The widget is responsible for storing the -- | Get the uuid for comm associated with this widget. The widget is responsible for storing the
-- UUID during initialization. -- UUID during initialization.
getCommUUID :: a -> UUID getCommUUID :: a -> UUID
...@@ -102,6 +106,7 @@ instance IHaskellDisplay Widget where ...@@ -102,6 +106,7 @@ instance IHaskellDisplay Widget where
instance IHaskellWidget Widget where instance IHaskellWidget Widget where
targetName (Widget widget) = targetName widget targetName (Widget widget) = targetName widget
targetModule (Widget widget) = targetModule widget
getCommUUID (Widget widget) = getCommUUID widget getCommUUID (Widget widget) = getCommUUID widget
open (Widget widget) = open widget open (Widget widget) = open widget
comm (Widget widget) = comm widget comm (Widget widget) = comm widget
...@@ -185,11 +190,10 @@ data LintStatus = LintOn ...@@ -185,11 +190,10 @@ data LintStatus = LintOn
deriving (Eq, Show) deriving (Eq, Show)
-- | Send JSON objects with specific formats -- | Send JSON objects with specific formats
data WidgetMsg = Open Widget Value Value data WidgetMsg = Open Widget Value
| |
-- ^ Cause the interpreter to open a new comm, and register the associated widget in -- ^ Cause the interpreter to open a new comm, and register the associated widget in
-- the kernelState. Also sends a Value with comm_open, and then sends an initial -- the kernelState. Also sends an initial state Value with comm_open.
-- state update Value.
Update Widget Value Update Widget Value
| |
-- ^ Cause the interpreter to send a comm_msg containing a state update for the -- ^ Cause the interpreter to send a comm_msg containing a state update for the
......
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