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

Editable sliders' name can be changed #2678

Merged
merged 3 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions panel/tests/widgets/test_slider.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from datetime import datetime, date
from collections import OrderedDict

from bokeh.models import Div as BkDiv, Slider as BkSlider, Column as BkColumn
from bokeh.models import (
Div as BkDiv, Slider as BkSlider, Column as BkColumn, Row as BkRow)
import pytest

from panel import config
from panel.widgets import (DateSlider, DateRangeSlider, DiscreteSlider,
FloatSlider, IntSlider, RangeSlider)
FloatSlider, IntSlider, RangeSlider,
EditableFloatSlider, EditableIntSlider, StaticText)


def test_float_slider(document, comm):
Expand Down Expand Up @@ -314,3 +317,65 @@ def test_discrete_slider_options_dict(document, comm):

discrete_slider.value = options['1']
assert widget.value == 1


@pytest.mark.parametrize(
'editableslider,start,end,step,val1,val2,val3',
[
(EditableFloatSlider, 0.1, 0.5, 0.1, 0.4, 0.2, 0.5),
(EditableIntSlider, 1, 5, 1, 4, 2, 5)
],
ids=["EditableFloatSlider", "EditableIntSlider"]
)
def test_editable_float_slider(document, comm,
editableslider, start, end, step, val1, val2, val3):

slider = editableslider(start=start, end=end, value=val1, name='Slider')

widget = slider.get_root(document, comm=comm)

assert isinstance(widget, BkColumn)

col_items = widget.children

assert len(col_items) == 2

row, slider_widget = col_items

assert isinstance(slider_widget, editableslider._slider_widget._widget_type)
assert slider_widget.title == ''
assert slider_widget.step == step
assert slider_widget.start == start
assert slider_widget.end == end
assert slider_widget.value == val1

assert isinstance(row, BkRow)

static_widget, input_widget = row.children

assert isinstance(static_widget, StaticText._widget_type)
assert static_widget.text == 'Slider:'

assert isinstance(input_widget, editableslider._input_widget._widget_type)
assert input_widget.title == ''
assert input_widget.step == step
assert input_widget.value == val1

slider._process_events({'value': val2})
assert slider.value == input_widget.value == slider_widget.value == val2
slider._process_events({'value_throttled': val2})
assert slider.value_throttled == val2

# Testing throttled mode
with config.set(throttled=True):
slider._process_events({'value': val1})
assert slider.value == val2 # no change
slider._process_events({'value_throttled': val1})
assert slider.value == val1

slider.value = val3
assert input_widget.value == slider_widget.value == val3

slider.name = 'New Slider'

assert static_widget.text == 'New Slider:'
5 changes: 3 additions & 2 deletions panel/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ class CompositeWidget(Widget):

def __init__(self, **params):
super().__init__(**params)
layout = {p: getattr(self, p) for p in Layoutable.param
layout_params = [p for p in Layoutable.param if p != 'name']
layout = {p: getattr(self, p) for p in layout_params
if getattr(self, p) is not None}
if layout.get('width', self.width) is None and not 'sizing_mode' in layout:
layout['sizing_mode'] = 'stretch_width'
self._composite = self._composite_type(**layout)
self._models = self._composite._models
self.param.watch(self._update_layout_params, list(Layoutable.param))
self.param.watch(self._update_layout_params, layout_params)

def _update_layout_params(self, *events):
updates = {event.name: event.new for event in events}
Expand Down