Skip to content

Commit fd36a64

Browse files
committed
Update widget spec
1 parent 0680330 commit fd36a64

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

ipywidgets/widgets/trait_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ def validate(self, obj, value):
157157
return value
158158
self.error(obj, value)
159159

160+
def default_value_repr(self):
161+
return repr(self.default_value.tobytes())
160162

161163
class CByteMemoryView(ByteMemoryView):
162164
"""A casting version of the byte memory view trait."""

packages/schema/generate-spec.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import ipywidgets as widgets
1212
from ipywidgets import Color
13-
from ipywidgets.widgets.trait_types import TypedTuple
13+
from ipywidgets.widgets.trait_types import TypedTuple, ByteMemoryView
1414
from ipywidgets.widgets.widget_link import Link
1515

1616
HEADER = '''# Model State
@@ -40,46 +40,46 @@
4040
}
4141

4242

43-
def widget_type(widget, widget_list):
43+
def trait_type(trait, widget_list):
4444
attributes = {}
45-
if isinstance(widget, CaselessStrEnum):
45+
if isinstance(trait, CaselessStrEnum):
4646
w_type = 'string'
47-
attributes['enum'] = widget.values
48-
elif isinstance(widget, Unicode):
47+
attributes['enum'] = trait.values
48+
elif isinstance(trait, Unicode):
4949
w_type = 'string'
50-
elif isinstance(widget, (Tuple, List)):
50+
elif isinstance(trait, (Tuple, List)):
5151
w_type = 'array'
52-
elif isinstance(widget, TypedTuple):
52+
elif isinstance(trait, TypedTuple):
5353
w_type = 'array'
54-
attributes['items'] = widget_type(widget._trait, widget_list)
55-
elif isinstance(widget, Bool):
54+
attributes['items'] = trait_type(trait._trait, widget_list)
55+
elif isinstance(trait, Bool):
5656
w_type = 'bool'
57-
elif isinstance(widget, (CFloat, Float)):
57+
elif isinstance(trait, (CFloat, Float)):
5858
w_type = 'float'
59-
elif isinstance(widget, (CInt, Int)):
59+
elif isinstance(trait, (CInt, Int)):
6060
w_type = 'int'
61-
elif isinstance(widget, Color):
61+
elif isinstance(trait, Color):
6262
w_type = 'color'
63-
elif isinstance(widget, Dict):
63+
elif isinstance(trait, Dict):
6464
w_type = 'object'
65-
elif isinstance(widget, Bytes):
65+
elif isinstance(trait, Bytes) or isinstance(trait, ByteMemoryView):
6666
w_type = 'bytes'
67-
elif isinstance(widget, Instance) and issubclass(widget.klass,
67+
elif isinstance(trait, Instance) and issubclass(trait.klass,
6868
widgets.Widget):
6969
w_type = 'reference'
70-
attributes['widget'] = widget.klass.__name__
70+
attributes['widget'] = trait.klass.__name__
7171
# ADD the widget to this documenting list
72-
if (widget.klass not in [i[1] for i in widget_list]
73-
and widget.klass is not widgets.Widget):
74-
widget_list.append((widget.klass.__name__, widget.klass))
75-
elif isinstance(widget, Any):
72+
if (trait.klass not in [i[1] for i in widget_list]
73+
and trait.klass is not widgets.Widget):
74+
widget_list.append((trait.klass.__name__, trait.klass))
75+
elif isinstance(trait, Any):
7676
# In our case, these all happen to be values that are converted to
7777
# strings
7878
w_type = 'label'
7979
else:
80-
w_type = widget.__class__.__name__
80+
w_type = trait.__class__.__name__
8181
attributes['type'] = w_type
82-
if widget.allow_none:
82+
if trait.allow_none:
8383
attributes['allow_none'] = True
8484
return attributes
8585

@@ -91,7 +91,7 @@ def jsdefault(trait):
9191
return 'reference to new instance'
9292
else:
9393
default = trait.default_value
94-
if isinstance(default, bytes):
94+
if isinstance(default, bytes) or isinstance(default, memoryview):
9595
default = trait.default_value_repr()
9696
return default
9797

@@ -163,7 +163,7 @@ def jsonify(identifier, widget, widget_list):
163163
help=trait.help or '',
164164
default=jsdefault(trait)
165165
)
166-
attribute.update(widget_type(trait, widget_list))
166+
attribute.update(trait_type(trait, widget_list))
167167
attributes.append(attribute)
168168

169169
return dict(model=model, view=view, attributes=attributes)

packages/schema/jupyterwidgetmodels.latest.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Attribute | Type | Default | Help
100100
`loop` | boolean | `true` | When true, the audio will start from the beginning after finishing
101101
`tabbable` | `null` or boolean | `null` | Is widget tabbable?
102102
`tooltip` | `null` or string | `null` | A tooltip caption.
103-
`value` | Bytes | `b''` | The media data as a byte string.
103+
`value` | Bytes | `b''` | The media data as a memory view of bytes.
104104

105105
### BoundedFloatTextModel (@jupyter-widgets/controls, 1.5.0); FloatTextView (@jupyter-widgets/controls, 1.5.0)
106106

@@ -330,7 +330,7 @@ Attribute | Type | Default | Help
330330
`layout` | reference to Layout widget | reference to new instance |
331331
`tabbable` | `null` or boolean | `null` | Is widget tabbable?
332332
`tooltip` | `null` or string | `null` | A tooltip caption.
333-
`value` | Bytes | `b''` | The media data as a byte string.
333+
`value` | Bytes | `b''` | The media data as a memory view of bytes.
334334

335335
### DatePickerModel (@jupyter-widgets/controls, 1.5.0); DatePickerView (@jupyter-widgets/controls, 1.5.0)
336336

@@ -630,7 +630,7 @@ Attribute | Type | Default | Help
630630
`layout` | reference to Layout widget | reference to new instance |
631631
`tabbable` | `null` or boolean | `null` | Is widget tabbable?
632632
`tooltip` | `null` or string | `null` | A tooltip caption.
633-
`value` | Bytes | `b''` | The media data as a byte string.
633+
`value` | Bytes | `b''` | The media data as a memory view of bytes.
634634
`width` | string | `''` | Width of the image in pixels. Use layout.width for styling the widget.
635635

636636
### IntProgressModel (@jupyter-widgets/controls, 1.5.0); ProgressView (@jupyter-widgets/controls, 1.5.0)
@@ -1136,7 +1136,7 @@ Attribute | Type | Default | Help
11361136
`loop` | boolean | `true` | When true, the video will start from the beginning after finishing
11371137
`tabbable` | `null` or boolean | `null` | Is widget tabbable?
11381138
`tooltip` | `null` or string | `null` | A tooltip caption.
1139-
`value` | Bytes | `b''` | The media data as a byte string.
1139+
`value` | Bytes | `b''` | The media data as a memory view of bytes.
11401140
`width` | string | `''` | Width of the video in pixels.
11411141

11421142
### OutputModel (@jupyter-widgets/output, 1.0.0); OutputView (@jupyter-widgets/output, 1.0.0)

0 commit comments

Comments
 (0)