Skip to content

Commit f703670

Browse files
ZerlineSylvainCorlay
authored andcommitted
'border' as a property.
1 parent 939e005 commit f703670

File tree

4 files changed

+24
-110
lines changed

4 files changed

+24
-110
lines changed

ipywidgets/widgets/widget_layout.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class Layout(Widget):
3737
'baseline', 'stretch'] + CSS_PROPERTIES, allow_none=True, help="The align-items CSS attribute.").tag(sync=True)
3838
align_self = CaselessStrEnum(['auto', 'flex-start', 'flex-end',
3939
'center', 'baseline', 'stretch'] + CSS_PROPERTIES, allow_none=True, help="The align-self CSS attribute.").tag(sync=True)
40-
border = Unicode(None, allow_none=True, help="The border CSS attribute.").tag(sync=True)
4140
border_top = Unicode(None, allow_none=True, help="The border top CSS attribute.").tag(sync=True)
4241
border_right = Unicode(None, allow_none=True, help="The border right CSS attribute.").tag(sync=True)
4342
border_bottom = Unicode(None, allow_none=True, help="The border bottom CSS attribute.").tag(sync=True)
@@ -79,13 +78,29 @@ class Layout(Widget):
7978
grid_column = Unicode(None, allow_none=True, help="The grid-column CSS attribute.").tag(sync=True)
8079
grid_area = Unicode(None, allow_none=True, help="The grid-area CSS attribute.").tag(sync=True)
8180

82-
def __init__(self, **kwargs):
83-
"""Public constructor"""
84-
super().__init__(**kwargs)
85-
if self.border is not None:
86-
for side in ['top', 'right', 'bottom', 'left']:
87-
if getattr(self, "border_" + side) is None:
88-
setattr(self, "border_" + side, self.border)
81+
def _get_border(self):
82+
"""
83+
`border` property getter. Return the common value of all side
84+
borders if they are identical. Otherwise return None.
85+
86+
"""
87+
found = None
88+
for side in ['top', 'right', 'bottom', 'left']:
89+
if not hasattr(self, "border_" + side):
90+
return
91+
old, found = found, getattr(self, "border_" + side)
92+
if found is None or (old is not None and found != old):
93+
return
94+
return found
95+
96+
def _set_border(self, border):
97+
"""
98+
`border` property setter. Set all 4 sides to `border` string.
99+
"""
100+
for side in ['top', 'right', 'bottom', 'left']:
101+
setattr(self, "border_" + side, border)
102+
103+
border = property(_get_border, _set_border)
89104

90105

91106
class LayoutTraitType(Instance):

packages/base/src/widget_layout.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const css_properties: Dict<string | null> = {
1212
align_content: null,
1313
align_items: null,
1414
align_self: null,
15-
border: null,
1615
border_top: null,
1716
border_right: null,
1817
border_bottom: null,

packages/schema/jupyterwidgetmodels.latest.json

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@
9191
"name": "align_self",
9292
"type": "string"
9393
},
94-
{
95-
"allow_none": true,
96-
"default": null,
97-
"help": "The border CSS attribute.",
98-
"name": "border",
99-
"type": "string"
100-
},
10194
{
10295
"allow_none": true,
10396
"default": null,
@@ -1700,98 +1693,6 @@
17001693
"name": "_model_module_version",
17011694
"type": "string"
17021695
},
1703-
{
1704-
"default": "ControllerButtonModel",
1705-
"help": "",
1706-
"name": "_model_name",
1707-
"type": "string"
1708-
},
1709-
{
1710-
"default": "@jupyter-widgets/controls",
1711-
"help": "",
1712-
"name": "_view_module",
1713-
"type": "string"
1714-
},
1715-
{
1716-
"default": "2.0.0",
1717-
"help": "",
1718-
"name": "_view_module_version",
1719-
"type": "string"
1720-
},
1721-
{
1722-
"default": "ControllerButtonView",
1723-
"help": "",
1724-
"name": "_view_name",
1725-
"type": "string"
1726-
},
1727-
{
1728-
"default": "reference to new instance",
1729-
"help": "",
1730-
"name": "layout",
1731-
"type": "reference",
1732-
"widget": "Layout"
1733-
},
1734-
{
1735-
"default": false,
1736-
"help": "Whether the button is pressed.",
1737-
"name": "pressed",
1738-
"type": "bool"
1739-
},
1740-
{
1741-
"allow_none": true,
1742-
"default": null,
1743-
"help": "Is widget tabbable?",
1744-
"name": "tabbable",
1745-
"type": "bool"
1746-
},
1747-
{
1748-
"allow_none": true,
1749-
"default": null,
1750-
"help": "A tooltip caption.",
1751-
"name": "tooltip",
1752-
"type": "string"
1753-
},
1754-
{
1755-
"default": 0.0,
1756-
"help": "The value of the button.",
1757-
"name": "value",
1758-
"type": "float"
1759-
}
1760-
],
1761-
"model": {
1762-
"module": "@jupyter-widgets/controls",
1763-
"name": "ControllerButtonModel",
1764-
"version": "1.5.0"
1765-
},
1766-
"view": {
1767-
"module": "@jupyter-widgets/controls",
1768-
"name": "ControllerButtonView",
1769-
"version": "1.5.0"
1770-
}
1771-
},
1772-
{
1773-
"attributes": [
1774-
{
1775-
"default": [],
1776-
"help": "CSS classes applied to widget DOM element",
1777-
"items": {
1778-
"type": "string"
1779-
},
1780-
"name": "_dom_classes",
1781-
"type": "array"
1782-
},
1783-
{
1784-
"default": "@jupyter-widgets/controls",
1785-
"help": "",
1786-
"name": "_model_module",
1787-
"type": "string"
1788-
},
1789-
{
1790-
"default": "1.5.0",
1791-
"help": "",
1792-
"name": "_model_module_version",
1793-
"type": "string"
1794-
},
17951696
{
17961697
"default": "ControllerModel",
17971698
"help": "",
@@ -1805,7 +1706,7 @@
18051706
"type": "string"
18061707
},
18071708
{
1808-
"default": "1.5.0",
1709+
"default": "2.0.0",
18091710
"help": "",
18101711
"name": "_view_module_version",
18111712
"type": "string"

packages/schema/jupyterwidgetmodels.latest.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Attribute | Type | Default | Help
2929
`align_content` | `null` or string (one of `'flex-start'`, `'flex-end'`, `'center'`, `'space-between'`, `'space-around'`, `'space-evenly'`, `'stretch'`, `'inherit'`, `'initial'`, `'unset'`) | `null` | The align-content CSS attribute.
3030
`align_items` | `null` or string (one of `'flex-start'`, `'flex-end'`, `'center'`, `'baseline'`, `'stretch'`, `'inherit'`, `'initial'`, `'unset'`) | `null` | The align-items CSS attribute.
3131
`align_self` | `null` or string (one of `'auto'`, `'flex-start'`, `'flex-end'`, `'center'`, `'baseline'`, `'stretch'`, `'inherit'`, `'initial'`, `'unset'`) | `null` | The align-self CSS attribute.
32-
`border` | `null` or string | `null` | The border CSS attribute.
3332
`border_bottom` | `null` or string | `null` | The border bottom CSS attribute.
3433
`border_left` | `null` or string | `null` | The border left CSS attribute.
3534
`border_right` | `null` or string | `null` | The border right CSS attribute.

0 commit comments

Comments
 (0)