Commit c6e548f7 authored by Sumit Sahrawat's avatar Sumit Sahrawat

Some finishing touches to the 4.0 support

* [BUGFIX]: Fix bug with width, height etc. values

The values needed to be explicitly sent as "<value>(px/em/...)" strings.
Solved by assuming "px" for all values.

* Updated messaging specification documentation as necessary.
parent 5cb38e4f
......@@ -8,26 +8,17 @@
## Creating widgets
Let's say the user types in some code, and the only effect of that code is the creation of a widget.
The kernel will open a comm for the widget, and store a reference to that comm inside it. Then, to
notify the frontend about the creation of a widget, an initial state update is sent on the widget's
comm.
The kernel will open a comm for the widget, and store a reference to that comm. The comm_open message
also holds the initial state of the widget in it, which is used by the frontend to create a model for
the widget.
> The comm should be opened with a `target_name` of `"ipython.widget"`.
The initial state update message looks like this:
```json
{
"method": "update",
"state": { "<some/all widget properties>" }
}
```
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 some (especially
those used by sliders) need to be sent as strings.
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.
The initial state update must *at least* have the following fields:
The initial state must *at least* have the following fields:
- `msg_throttle` (default 3): To prevent the kernel from flooding with messages, the messages from
the widget to the kernel are throttled. If `msg_throttle` messages were sent, and all are still
......@@ -43,8 +34,8 @@ The initial state update must *at least* have the following fields:
- Rest of the properties as required initially.
This state update is also used with fragments of the overall state to sync changes between the
frontend and the kernel.
This state is also used with fragments of the overall state to sync changes between the frontend and
the kernel.
## Displaying widgets
......@@ -111,7 +102,7 @@ If this were not so, the frontend would not be able to determine under which cel
input widget, when an `input_request` is received.
Now, widgets cannot send `execute_request` messages. They can only send `comm_data` messages, which
means that it's not possible to fetch input through widget events.
means that it's not possible to fetch input inside widget event handlers.
---
......
......@@ -97,11 +97,11 @@ pattern Selector = S.SSelector
closeWidget :: IHaskellWidget w => w -> IO ()
closeWidget w = widgetSendClose w emptyObject
newtype StrInt = StrInt Integer
newtype PixCount = PixCount Integer
deriving (Num, Ord, Eq, Enum)
instance ToJSON StrInt where
toJSON (StrInt x) = toJSON . pack $ show x
instance ToJSON PixCount where
toJSON (PixCount x) = toJSON . pack $ show x ++ "px"
-- | Pre-defined border styles
data BorderStyleValue = NoBorder
......
......@@ -48,8 +48,8 @@ module IHaskell.Display.Widgets.Types where
--
-- The IPython widgets expect state updates of the form {"property": value}, where an empty string
-- for numeric values is ignored by the frontend and the default value is used instead. Some numbers
-- need to be sent as numbers (represented by @Integer@), whereas some need to be sent as Strings
-- (@StrInt@).
-- need to be sent as numbers (represented by @Integer@), whereas some (css lengths) need to be sent
-- as Strings (@PixCount@).
--
-- Child widgets are expected to be sent as strings of the form "IPY_MODEL_<uuid>", where @<uuid>@
-- represents the uuid of the widget's comm.
......@@ -58,7 +58,7 @@ module IHaskell.Display.Widgets.Types where
-- look at the supplied MsgSpec.md.
--
-- 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.Applicative ((<$>))
import qualified Control.Exception as Ex
......@@ -140,19 +140,19 @@ type family FieldType (f :: Field) :: * where
FieldType S.Visible = Bool
FieldType S.CSS = [(Text, Text, Text)]
FieldType S.DOMClasses = [Text]
FieldType S.Width = StrInt
FieldType S.Height = StrInt
FieldType S.Padding = StrInt
FieldType S.Margin = StrInt
FieldType S.Width = PixCount
FieldType S.Height = PixCount
FieldType S.Padding = PixCount
FieldType S.Margin = PixCount
FieldType S.Color = Text
FieldType S.BackgroundColor = Text
FieldType S.BorderColor = Text
FieldType S.BorderWidth = StrInt
FieldType S.BorderRadius = StrInt
FieldType S.BorderWidth = PixCount
FieldType S.BorderRadius = PixCount
FieldType S.BorderStyle = BorderStyleValue
FieldType S.FontStyle = FontStyleValue
FieldType S.FontWeight = FontWeightValue
FieldType S.FontSize = StrInt
FieldType S.FontSize = PixCount
FieldType S.FontFamily = Text
FieldType S.Description = Text
FieldType S.ClickHandler = IO ()
......@@ -220,7 +220,7 @@ class CustomBounded a where
upperBound :: a
-- Set according to what IPython widgets use
instance CustomBounded StrInt where
instance CustomBounded PixCount where
upperBound = 10 ^ 16 - 1
lowerBound = -(10 ^ 16 - 1)
......
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