def test_int_slider(document, comm): slider = IntSlider(start=0, end=3, value=1, name='Slider') widget = slider.get_root(document, comm=comm) assert isinstance(widget, slider._widget_type) assert widget.title == 'Slider' assert widget.step == 1 assert widget.start == 0 assert widget.end == 3 assert widget.value == 1 slider._process_events({'value': 2}) assert slider.value == 2 slider._process_events({'value_throttled': 2}) assert slider.value_throttled == 2 slider.value = 0 assert widget.value == 0 # Testing that value matches start value if value not set. slider_2 = IntSlider(start=1, end=3, name='Slider_2') widget_2 = slider_2.get_root(document, comm=comm) assert widget_2.value == widget_2.start # Testing throttled mode with config.set(throttled=True): slider._process_events({'value': 1}) assert slider.value == 0 # no change slider._process_events({'value_throttled': 1}) assert slider.value == 1 slider.value = 2 assert widget.value == 2
def test_bind_two_widgets_as_kwargs(): widget = IntSlider(value=0) widget2 = IntSlider(value=1) def add(value, value2): return value + value2 bound_function = bind(add, value=widget, value2=widget2) assert bound_function() == 1 widget.value = 1 assert bound_function() == 2 widget2.value = 2 assert bound_function() == 3 with pytest.raises(TypeError): bound_function(1, 2) assert bound_function(value2=5) == 6
def test_int_slider(document, comm): slider = IntSlider(start=0, end=3, value=1, name='Slider') widget = slider.get_root(document, comm=comm) assert isinstance(widget, slider._widget_type) assert widget.title == 'Slider' assert widget.step == 1 assert widget.start == 0 assert widget.end == 3 assert widget.value == 1 slider._comm_change({'value': 2}) assert slider.value == 2 slider.value = 0 assert widget.value == 0 # Testing that value matches start value if value not set. slider_2 = IntSlider(start=1, end=3, name='Slider_2') widget_2 = slider_2.get_root(document, comm=comm) assert widget_2.value == widget_2.start
def test_bind_two_widget_arg_with_remaining_arg(): widget = IntSlider(value=0) def add(value, value2): return value + value2 bound_function = bind(add, widget) assert bound_function(1) == 1 widget.value = 1 assert bound_function(2) == 3 assert bound_function(value2=3) == 4
def test_bind_widget_to_kwarg(): widget = IntSlider(value=0) def add1(value): return value + 1 bound_function = bind(add1, value=widget) assert bound_function() == 1 widget.value = 1 assert bound_function() == 2 with pytest.raises(TypeError): bound_function(1)
def test_bind_bound_function_to_kwarg(): widget = IntSlider(value=1) def add1(value): return value + 1 def divide(divisor=2, value=0): return value / divisor bound_function = bind(divide, value=bind(add1, widget.param.value)) assert bound_function() == 1 widget.value = 3 assert bound_function() == 2
def test_int_slider(document, comm): slider = IntSlider(start=0, end=3, value=1, name='Slider') widget = slider.get_root(document, comm=comm) assert isinstance(widget, slider._widget_type) assert widget.title == 'Slider' assert widget.step == 1 assert widget.start == 0 assert widget.end == 3 assert widget.value == 1 slider._comm_change({'value': 2}) assert slider.value == 2 slider.value = 0 assert widget.value == 0
def test_int_slider(document, comm): slider = IntSlider(start=0, end=3, value=1, name='Slider') box = slider._get_model(document, comm=comm) assert isinstance(box, WidgetBox) widget = box.children[0] assert isinstance(widget, slider._widget_type) assert widget.title == 'Slider' assert widget.step == 1 assert widget.start == 0 assert widget.end == 3 assert widget.value == 1 slider._comm_change({'value': 2}) assert slider.value == 2 slider.value = 0 assert widget.value == 0
def test_gridspec_stretch_with_replacement_pane(document, comm): slider = IntSlider(start=0, end=2) @depends(slider) def div(value): return Div(text=str(value)) gspec = GridSpec(sizing_mode='stretch_width') gspec[0, 0:2] = Div() gspec[1, 2] = div model = gspec.get_root(document, comm=comm) ((div1, _, _, _, _), (row, _, _, _, _)) = model.children div2 = row.children[0] assert div1.sizing_mode == 'stretch_width' assert div1.height == 300 assert div2.sizing_mode == 'stretch_width' assert div2.height == 300 slider.value = 1 assert row.children[0] is not div2 assert row.children[0].sizing_mode == 'stretch_width' assert row.children[0].height == 300
def test_embed_merged_sliders(document, comm): s1 = IntSlider(name='A', start=1, end=10, value=1) t1 = StaticText() s1.param.watch(lambda event: setattr(t1, 'value', event.new), 'value') s2 = IntSlider(name='A', start=1, end=10, value=1) t2 = StaticText() s2.param.watch(lambda event: setattr(t2, 'value', event.new), 'value') panel = Row(s1, s2, t1, t2) with config.set(embed=True): model = panel.get_root(document, comm) state_model = embed_state(panel, model, document) assert len(document.roots) == 2 assert model is document.roots[0] cbs = list(model.select({'type': CustomJS})) assert len(cbs) == 5 ref1, ref2 = model.children[2].ref['id'], model.children[3].ref['id'] state0 = json.loads(state_model.state[0]['content'])['events'] assert state0 == [{ "attr": "text", "kind": "ModelChanged", "model": { "id": ref1 }, "new": "1" }, { "attr": "text", "kind": "ModelChanged", "model": { "id": ref2 }, "new": "1" }] state1 = json.loads(state_model.state[1]['content'])['events'] assert state1 == [{ "attr": "text", "kind": "ModelChanged", "model": { "id": ref1 }, "new": "5" }, { "attr": "text", "kind": "ModelChanged", "model": { "id": ref2 }, "new": "5" }] state2 = json.loads(state_model.state[2]['content'])['events'] assert state2 == [{ "attr": "text", "kind": "ModelChanged", "model": { "id": ref1 }, "new": "9" }, { "attr": "text", "kind": "ModelChanged", "model": { "id": ref2 }, "new": "9" }]
def test_params_identical_names(self): a = IntSlider(name="Name") b = IntSlider(name="Name") p = Params(parameters=[a.param.value, b.param.value]) assert len(p.hashkey) == 3 # the two widgets + _memoize_key
def test_param_value_if_widget(): widget = IntSlider() assert param_value_if_widget(widget) is widget.param.value
import numpy as np import panel as pn from panel.widgets import IntSlider from ipywidgets import AppLayout, Image, Layout, Box, widgets # pip install ipywidgets from IPython import display img_path = './project/project02/data/dog2.jpg' src = cv2.imread(img_path) gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY) #Component 선언 IntSlider_Threshold = IntSlider(value=1, min=1, max=50, step=1, description='Threshold: ', disabled=False, continuous_update=False, orientation='horizontal', readout=True, readout_format='d') def layout(header, left, right): layout = AppLayout(header=header, left_sidebar=left, center=None, right_sidebar=right) return layout wImg_original = Image(layout=Layout(border="solid"), width="45%")