Skip to content

Commit c9ed15c

Browse files
author
Zerline
committed
'border' set at widget creation.
1 parent d7d2842 commit c9ed15c

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

ipywidgets/widgets/widget_layout.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ class Layout(Widget):
7979
grid_column = Unicode(None, allow_none=True, help="The grid-column CSS attribute.").tag(sync=True)
8080
grid_area = Unicode(None, allow_none=True, help="The grid-area CSS attribute.").tag(sync=True)
8181

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)
89+
8290

8391
class LayoutTraitType(Instance):
8492

tests/test_borders.ipynb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
18-
"t1 = Text(\"text input\")\n",
18+
"t1 = Text(\"text input\", layout=Layout(width=\"80px\", border=\"1px dashed red\"))\n",
1919
"b1 = Button(description=\"button\")\n",
2020
"HBox((t1,b1))"
2121
]
@@ -27,7 +27,6 @@
2727
"outputs": [],
2828
"source": [
2929
"b1.layout.border = \"2px solid yellow\"\n",
30-
"t1.layout.border = \"1px dashed red\"\n",
3130
"t1.layout.border_left = \"5px dotted blue\"\n",
3231
"b1.layout.border_right = \"2px dotted blue\""
3332
]
@@ -39,7 +38,7 @@
3938
"outputs": [],
4039
"source": [
4140
"t2 = Text(\"text input\")\n",
42-
"b2 = ToggleButton(description=\"toggle button\")\n",
41+
"b2 = ToggleButton(description=\"toggle button\", layout=Layout(width=\"200px\", border_left=\"2px solid yellow\"))\n",
4342
"HBox((t2,b2))"
4443
]
4544
},
@@ -51,7 +50,6 @@
5150
"source": [
5251
"t2.layout.border_left = \"5px dotted blue\"\n",
5352
"b2.layout.border_right = \"2px dotted blue\"\n",
54-
"b2.layout.border = \"2px solid yellow\"\n",
5553
"t2.layout.border = \"1px dashed red\""
5654
]
5755
},
@@ -61,10 +59,9 @@
6159
"metadata": {},
6260
"outputs": [],
6361
"source": [
64-
"t1.style.border_top = \"5px solid green\"\n",
65-
"b1.style.border = \"1px solid purple\"\n",
66-
"t2.style.border_top = \"5px solid green\"\n",
67-
"b2.style.border = \"1px solid purple\""
62+
"t1.layout.border_top = \"5px solid green\"\n",
63+
"b1.layout.border = \"1px solid purple\"\n",
64+
"t2.layout.border_right = \"5px double skyblue\""
6865
]
6966
}
7067
],

0 commit comments

Comments
 (0)