Commit 9168aa5b authored by David Davó's avatar David Davó

Widgets: Metadata now carries version of widget

parent 4e1a2a13
...@@ -24,3 +24,6 @@ cabal.sandbox.config ...@@ -24,3 +24,6 @@ cabal.sandbox.config
.tmp3 .tmp3
stack.yaml.lock stack.yaml.lock
result result
default.nix
dist-*/
cabal.project.local
\ No newline at end of file
# ChangeLog for `ihaskell-widgets` # ChangeLog for `ihaskell-widgets`
## `v0.3.0.0`
> Revamped to be compatible with Widget Messaging Protocol, version 2
## `v0.2.2.1` ## `v0.2.2.1`
+ The `properties` function now prints types associated with widget fields. + The `properties` function now prints types associated with widget fields.
......
...@@ -14,6 +14,8 @@ the widget. ...@@ -14,6 +14,8 @@ the widget.
> The comm should be opened with a `target_name` of `"ipython.widget"`. > The comm should be opened with a `target_name` of `"ipython.widget"`.
> The comm_open message's metadata gives the version of the widget messaging protocol, i.e., `{'version': '2.0.0'}`
Any *numeric* property initialized with the empty string is provided the default value by the Any *numeric* property initialized with the empty string is provided the default value by the
frontend. Some numbers need to be sent as actual numbers (when non-null), whereas the ones representing frontend. Some numbers need to be sent as actual numbers (when non-null), whereas the ones representing
lengths in CSS units need to be sent as strings. lengths in CSS units need to be sent as strings.
......
...@@ -10,7 +10,7 @@ name: ihaskell-widgets ...@@ -10,7 +10,7 @@ name: ihaskell-widgets
-- PVP summary: +-+------- breaking API changes -- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions -- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change -- | | | +--- code changes with no API change
version: 0.2.3.3 version: 0.3.0.0
-- A short (one-line) description of the package. -- A short (one-line) description of the package.
synopsis: IPython standard widgets for IHaskell. synopsis: IPython standard widgets for IHaskell.
......
...@@ -62,6 +62,7 @@ instance IHaskellDisplay IntSlider where ...@@ -62,6 +62,7 @@ instance IHaskellDisplay IntSlider where
instance IHaskellWidget IntSlider where instance IHaskellWidget IntSlider where
getCommUUID = uuid getCommUUID = uuid
getVersion _ = "2.0.0"
comm widget val _ = comm widget val _ =
case nestedObjectLookup val ["sync_data", "value"] of case nestedObjectLookup val ["sync_data", "value"] of
Just (Number value) -> do Just (Number value) -> do
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTs #-} {-# LANGUAGE GADTs #-}
{-# LANGUAGE AutoDeriveTypeable #-}
{-# LANGUAGE CPP #-} {-# LANGUAGE CPP #-}
-- | This module houses all the type-trickery needed to make widgets happen. -- | This module houses all the type-trickery needed to make widgets happen.
......
...@@ -109,7 +109,8 @@ handleMessage send replyHeader state msg = do ...@@ -109,7 +109,8 @@ handleMessage send replyHeader state msg = do
else do else do
-- Send the comm open, with the initial state -- Send the comm open, with the initial state
hdr <- dupHeader replyHeader CommOpenMessage hdr <- dupHeader replyHeader CommOpenMessage
send $ CommOpen hdr target_name target_module uuid value let hdrV = setVersion hdr $ getVersion widget
send $ CommOpen hdrV target_name target_module uuid value
-- Send anything else the widget requires. -- Send anything else the widget requires.
open widget communicate open widget communicate
...@@ -189,7 +190,7 @@ instance ToJSON IPythonMessage where ...@@ -189,7 +190,7 @@ instance ToJSON IPythonMessage where
object object
[ "header" .= replyHeader [ "header" .= replyHeader
, "parent_header" .= str "" , "parent_header" .= str ""
, "metadata" .= str "{}" , "metadata" .= object []
, "content" .= val , "content" .= val
, "msg_type" .= (toJSON . showMessageType $ mtype) , "msg_type" .= (toJSON . showMessageType $ mtype)
] ]
......
...@@ -11,6 +11,7 @@ module IHaskell.Types ( ...@@ -11,6 +11,7 @@ module IHaskell.Types (
MessageHeader(..), MessageHeader(..),
MessageType(..), MessageType(..),
dupHeader, dupHeader,
setVersion,
Username, Username,
Metadata, Metadata,
replyType, replyType,
...@@ -41,8 +42,10 @@ module IHaskell.Types ( ...@@ -41,8 +42,10 @@ module IHaskell.Types (
import IHaskellPrelude import IHaskellPrelude
import Data.Aeson (ToJSON (..), Value, (.=), object) import qualified Data.HashMap.Strict as HashMap
import Data.Aeson (ToJSON (..), Value, (.=), object, Object, Value(String))
import Data.Function (on) import Data.Function (on)
import Data.Text (pack)
import Data.Serialize import Data.Serialize
import GHC.Generics import GHC.Generics
...@@ -73,6 +76,9 @@ class IHaskellDisplay a => IHaskellWidget a where ...@@ -73,6 +76,9 @@ class IHaskellDisplay a => IHaskellWidget a where
-- UUID during initialization. -- UUID during initialization.
getCommUUID :: a -> UUID getCommUUID :: a -> UUID
-- | Get the version for this widget. Sent as metadata during comm_open.
getVersion :: a -> String
-- | Called when the comm is opened. Allows additional messages to be sent after comm open. -- | Called when the comm is opened. Allows additional messages to be sent after comm open.
open :: a -- ^ Widget to open a comm port with. open :: a -- ^ Widget to open a comm port with.
-> (Value -> IO ()) -- ^ A function for sending messages. -> (Value -> IO ()) -- ^ A function for sending messages.
...@@ -125,6 +131,7 @@ instance IHaskellWidget Widget where ...@@ -125,6 +131,7 @@ instance IHaskellWidget Widget where
targetName (Widget widget) = targetName widget targetName (Widget widget) = targetName widget
targetModule (Widget widget) = targetModule widget targetModule (Widget widget) = targetModule widget
getCommUUID (Widget widget) = getCommUUID widget getCommUUID (Widget widget) = getCommUUID widget
getVersion (Widget widget) = getVersion widget
open (Widget widget) = open widget open (Widget widget) = open widget
comm (Widget widget) = comm widget comm (Widget widget) = comm widget
close (Widget widget) = close widget close (Widget widget) = close widget
...@@ -277,6 +284,12 @@ dupHeader hdr messageType = do ...@@ -277,6 +284,12 @@ dupHeader hdr messageType = do
uuid <- liftIO random uuid <- liftIO random
return hdr { mhMessageId = uuid, mhMsgType = messageType } return hdr { mhMessageId = uuid, mhMsgType = messageType }
-- | Modyfies a header and appends the version as metadata
setVersion :: MessageHeader -- ^ The header to modify
-> String -- ^ The version to set
-> MessageHeader -- ^ The modified header
setVersion hdr v = hdr { mhMetadata = Metadata (HashMap.fromList [("version", String $ pack v)]) }
-- | Whether or not an error occurred. -- | Whether or not an error occurred.
data ErrorOccurred = Success data ErrorOccurred = Success
| Failure | Failure
......
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