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 @@ ...@@ -8,26 +8,17 @@
## Creating widgets ## Creating widgets
Let's say the user types in some code, and the only effect of that code is the creation of a widget. 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 The kernel will open a comm for the widget, and store a reference to that comm. The comm_open message
notify the frontend about the creation of a widget, an initial state update is sent on the widget's also holds the initial state of the widget in it, which is used by the frontend to create a model for
comm. 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 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 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 frontend. Some numbers need to be sent as actual numbers (when non-null), whereas the ones representing
those used by sliders) need to be sent as strings. 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 - `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 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: ...@@ -43,8 +34,8 @@ The initial state update must *at least* have the following fields:
- Rest of the properties as required initially. - Rest of the properties as required initially.
This state update is also used with fragments of the overall state to sync changes between the This state is also used with fragments of the overall state to sync changes between the frontend and
frontend and the kernel. the kernel.
## Displaying widgets ## Displaying widgets
...@@ -111,7 +102,7 @@ If this were not so, the frontend would not be able to determine under which cel ...@@ -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. input widget, when an `input_request` is received.
Now, widgets cannot send `execute_request` messages. They can only send `comm_data` messages, which 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 ...@@ -97,11 +97,11 @@ pattern Selector = S.SSelector
closeWidget :: IHaskellWidget w => w -> IO () closeWidget :: IHaskellWidget w => w -> IO ()
closeWidget w = widgetSendClose w emptyObject closeWidget w = widgetSendClose w emptyObject
newtype StrInt = StrInt Integer newtype PixCount = PixCount Integer
deriving (Num, Ord, Eq, Enum) deriving (Num, Ord, Eq, Enum)
instance ToJSON StrInt where instance ToJSON PixCount where
toJSON (StrInt x) = toJSON . pack $ show x toJSON (PixCount x) = toJSON . pack $ show x ++ "px"
-- | Pre-defined border styles -- | Pre-defined border styles
data BorderStyleValue = NoBorder data BorderStyleValue = NoBorder
......
...@@ -48,8 +48,8 @@ module IHaskell.Display.Widgets.Types where ...@@ -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 -- 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 -- 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 -- need to be sent as numbers (represented by @Integer@), whereas some (css lengths) need to be sent
-- (@StrInt@). -- as Strings (@PixCount@).
-- --
-- Child widgets are expected to be sent as strings of the form "IPY_MODEL_<uuid>", where @<uuid>@ -- 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. -- represents the uuid of the widget's comm.
...@@ -58,7 +58,7 @@ module IHaskell.Display.Widgets.Types where ...@@ -58,7 +58,7 @@ module IHaskell.Display.Widgets.Types where
-- 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 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 ((<$>))
import qualified Control.Exception as Ex import qualified Control.Exception as Ex
...@@ -140,19 +140,19 @@ type family FieldType (f :: Field) :: * where ...@@ -140,19 +140,19 @@ type family FieldType (f :: Field) :: * where
FieldType S.Visible = Bool FieldType S.Visible = Bool
FieldType S.CSS = [(Text, Text, Text)] FieldType S.CSS = [(Text, Text, Text)]
FieldType S.DOMClasses = [Text] FieldType S.DOMClasses = [Text]
FieldType S.Width = StrInt FieldType S.Width = PixCount
FieldType S.Height = StrInt FieldType S.Height = PixCount
FieldType S.Padding = StrInt FieldType S.Padding = PixCount
FieldType S.Margin = StrInt FieldType S.Margin = PixCount
FieldType S.Color = Text FieldType S.Color = Text
FieldType S.BackgroundColor = Text FieldType S.BackgroundColor = Text
FieldType S.BorderColor = Text FieldType S.BorderColor = Text
FieldType S.BorderWidth = StrInt FieldType S.BorderWidth = PixCount
FieldType S.BorderRadius = StrInt FieldType S.BorderRadius = PixCount
FieldType S.BorderStyle = BorderStyleValue FieldType S.BorderStyle = BorderStyleValue
FieldType S.FontStyle = FontStyleValue FieldType S.FontStyle = FontStyleValue
FieldType S.FontWeight = FontWeightValue FieldType S.FontWeight = FontWeightValue
FieldType S.FontSize = StrInt FieldType S.FontSize = PixCount
FieldType S.FontFamily = Text FieldType S.FontFamily = Text
FieldType S.Description = Text FieldType S.Description = Text
FieldType S.ClickHandler = IO () FieldType S.ClickHandler = IO ()
...@@ -220,7 +220,7 @@ class CustomBounded a where ...@@ -220,7 +220,7 @@ class CustomBounded a where
upperBound :: a upperBound :: a
-- Set according to what IPython widgets use -- Set according to what IPython widgets use
instance CustomBounded StrInt where instance CustomBounded PixCount where
upperBound = 10 ^ 16 - 1 upperBound = 10 ^ 16 - 1
lowerBound = -(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