Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AppLayout widget #2333

Merged
merged 39 commits into from Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
041aa2b
added test widget
btel Mar 4, 2019
bc0a5eb
adding applayout traitlet widgets
btel Mar 4, 2019
79db631
add defaults
btel Mar 4, 2019
8d79146
inherit from GridBox instead of delgating
btel Mar 4, 2019
5e8d24e
allow to change the children dynamically
btel Mar 4, 2019
0cb2687
added unit test
btel Mar 4, 2019
6472f9b
remove print
btel Mar 4, 2019
137d8da
refactor + add all widget positions
btel Mar 5, 2019
b3ee45e
linting + fix default merging
btel Mar 5, 2019
28e6d6d
test layout with a single widget
btel Mar 5, 2019
43ee468
rename AppLayout -> TwoByTwoLayout
btel Mar 5, 2019
8fb6f33
added first draft of template docs
btel Mar 5, 2019
c821a3b
fix link to grid docs
btel Mar 5, 2019
63785d3
add merge option
btel Mar 5, 2019
0180c91
allow to pass custom layout opitions to layout class
btel Mar 6, 2019
46d092c
add height/width properties
btel Mar 6, 2019
ca9c03a
refactoring
btel Mar 6, 2019
4d5f6ba
implement AppLayout template
btel Mar 6, 2019
e0d0eb9
hide header and footer is missing
btel Mar 6, 2019
fac71f7
handle special case of merging in AppLayout
btel Mar 6, 2019
b6366f0
add AppLayout to the docs
btel Mar 6, 2019
1d713fb
adding test to complete coverage
btel Mar 6, 2019
451cdf6
delegate top level layout properties to self.layout attribute
btel Mar 7, 2019
76235db
update examples (fix overflow + alignment options)
btel Mar 7, 2019
ed57196
fix issue with dynamically updated localtions (did not render correctly)
btel Mar 7, 2019
94ca86b
check style tag
btel Mar 7, 2019
e89f23d
check for frontend updates
btel Mar 7, 2019
59ce21f
add extra states for align_items
btel Mar 7, 2019
f02d21a
add style example in docs and fix layout bug
btel Mar 7, 2019
0fce35b
handle correctly merge updates
btel Mar 7, 2019
3823443
add control of width/height
btel Mar 7, 2019
ec9361d
added an example of full application
btel Mar 8, 2019
0b61545
add gridspeclayout (first version)
btel Mar 8, 2019
63bcfc2
adding merging by slicing support
btel Mar 8, 2019
ed4b088
added bqplot scatter example with gridspeclayout
btel Mar 8, 2019
81865d9
coverage: remove obsolete code, add tests
btel Mar 8, 2019
f59dae5
cleaning code
btel Mar 8, 2019
9be11ad
implement retrieving widget with slice
btel Apr 8, 2019
4ba354b
updated layout templates notebooks
btel Apr 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions ipywidgets/widgets/tests/test_widget_templates.py
Expand Up @@ -3,6 +3,7 @@
from unittest import TestCase

import ipywidgets as widgets
from ipywidgets.widgets.widget_templates import LayoutTemplate

class TestTwoByTwoLayout(TestCase):
"""test layout templates"""
Expand Down Expand Up @@ -474,3 +475,20 @@ def test_merge_empty_cells(self):
assert box.center.layout.grid_area == 'center'

assert len(box.get_state()['children']) == 1

class TestLayoutTemplate(TestCase):
"""test mixin with layout properties"""

class DummyTemplate(LayoutTemplate):
layout = widgets.Layout()

def test_layout_updated_on_trait_change(self):
"test whether respective layout traits are updated when traits change"

template = self.DummyTemplate(width="100%")
assert template.width == '100%'
assert template.layout.width == '100%'

template.width = 'auto'
assert template.width == 'auto'
assert template.layout.width == 'auto'
23 changes: 18 additions & 5 deletions ipywidgets/widgets/widget_templates.py
@@ -1,6 +1,8 @@
"""Implement common widgets layouts as reusable components"""

from traitlets import Instance, Bool, Unicode, CaselessStrEnum
from traitlets import HasTraits
from traitlets import All
from traitlets import observe

from .widget import Widget
Expand Down Expand Up @@ -28,8 +30,8 @@
}

@doc_subst(_doc_snippets)
class LayoutTemplate(GridBox):
"""Base class for layout templates
class LayoutTemplate(HasTraits):
"""Mixin class for layout templates

This class handles mainly style attributes (height, grid_gap etc.)

Expand All @@ -38,6 +40,12 @@ class LayoutTemplate(GridBox):

{style_params}

Note
----

This class is only meant to be used in inheritance as mixin with other
classes. It will not work, unless `self.layout` attribute is defined.

"""

# style attributes (passed to Layout)
Expand Down Expand Up @@ -70,6 +78,11 @@ def __init__(self, **kwargs):
super(LayoutTemplate, self).__init__(**kwargs)
self._copy_layout_props()

@observe(All)
def _delegate_to_layout(self, change):
"delegate the trait types to their counterparts in self.layout"
setattr(self.layout, change['name'], change['new']) # pylint: disable=no-member
btel marked this conversation as resolved.
Show resolved Hide resolved
pass

def _copy_layout_props(self):

Expand All @@ -78,11 +91,11 @@ def _copy_layout_props(self):
for prop in _props:
value = getattr(self, prop)
if value:
setattr(self.layout, prop, value)
setattr(self.layout, prop, value) #pylint: disable=no-member


@doc_subst(_doc_snippets)
class AppLayout(LayoutTemplate):
class AppLayout(GridBox, LayoutTemplate):
""" Define an application like layout of widgets.

Parameters
Expand Down Expand Up @@ -180,7 +193,7 @@ def _child_changed(self, change): #pylint: disable=unused-argument
self._update_layout()

@doc_subst(_doc_snippets)
class TwoByTwoLayout(LayoutTemplate):
class TwoByTwoLayout(GridBox, LayoutTemplate):
""" Define a layout with 2x2 regular grid.

Parameters
Expand Down