示例#1
0
    def test_js_on_change_executes(self, single_plot_page):
        source = ColumnDataSource(dict(x=[1, 2], y=[1, 1]))
        plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
        plot.add_glyph(source, Circle(x='x', y='y', size=20))
        text_input = PasswordInput(css_classes=['foo'])
        text_input.js_on_change('value', CustomJS(code=RECORD("value", "cb_obj.value")))

        page = single_plot_page(column(text_input, plot))

        el = page.driver.find_element_by_css_selector('.foo input')
        enter_text_in_element(page.driver, el, "val1")

        results = page.results
        assert results['value'] == 'val1'

        # double click to highlight and overwrite old text
        enter_text_in_element(page.driver, el, "val2", click=2)

        results = page.results
        assert results['value'] == 'val2'

        # Check clicking outside input also triggers
        enter_text_in_element(page.driver, el, "val3", click=2, enter=False)
        page.click_canvas_at_position(10, 10)
        results = page.results

        assert results['value'] == 'val3'

        assert page.has_no_console_errors()
    def test_js_on_change_executes(self, single_plot_page):
        source = ColumnDataSource(dict(x=[1, 2], y=[1, 1]))
        plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
        plot.add_glyph(source, Circle(x='x', y='y', size=20))
        text_input = PasswordInput(css_classes=['foo'])
        text_input.js_on_change('value', CustomJS(code=RECORD("value", "cb_obj.value")))

        page = single_plot_page(column(text_input, plot))

        el = page.driver.find_element_by_css_selector('.foo input')
        enter_text_in_element(page.driver, el, "val1")

        results = page.results
        assert results['value'] == 'val1'

        # double click to highlight and overwrite old text
        enter_text_in_element(page.driver, el, "val2", click=2)

        results = page.results
        assert results['value'] == 'val2'

        # Check clicking outside input also triggers
        enter_text_in_element(page.driver, el, "val3", click=2, enter=False)
        page.click_canvas_at_position(10, 10)
        results = page.results

        assert results['value'] == 'val3'

        assert page.has_no_console_errors()
示例#3
0
def modify_doc(doc):
    source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"]))
    plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
    plot.add_glyph(source, Circle(x='x', y='y', size=20))
    plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data"))))
    text_input = PasswordInput(css_classes=["foo"])
    def cb(attr, old, new):
        source.data['val'] = [old, new]
    text_input.on_change('value', cb)
    doc.add_root(column(text_input, plot))
def modify_doc(doc):
    source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"]))
    plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
    plot.add_glyph(source, Circle(x='x', y='y', size=20))
    plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data"))))
    text_input = PasswordInput(css_classes=["foo"])
    def cb(attr, old, new):
        source.data['val'] = [old, new]
    text_input.on_change('value', cb)
    doc.add_root(column(text_input, plot))
示例#5
0
    def test_server_on_change_round_trip(
            self, bokeh_server_page: BokehServerPage) -> None:
        text_input = PasswordInput()
        modify_doc, plot = mk_modify_doc(text_input)
        page = bokeh_server_page(modify_doc)

        el = find_element_for(page.driver, text_input, "input")
        enter_text_in_element(page.driver, el, "val1")

        page.eval_custom_action()

        results = page.results
        assert results['data']['val'] == ["", "val1"]

        # double click to highlight and overwrite old text
        enter_text_in_element(page.driver, el, "val2", click=2)

        page.eval_custom_action()

        results = page.results
        assert results['data']['val'] == ["val1", "val2"]

        # Check clicking outside input also triggers
        enter_text_in_element(page.driver, el, "val3", click=2, enter=False)
        page.click_canvas_at_position(plot, 10, 10)

        page.eval_custom_action()

        results = page.results
        assert results['data']['val'] == ["val2", "val3"]
示例#6
0
    def test_displays_password_input(self, bokeh_model_page):
        pw_input = PasswordInput(css_classes=["foo"])

        page = bokeh_model_page(pw_input)

        el = page.driver.find_element_by_css_selector('.foo input')
        assert el.get_attribute('type') == "password"

        assert page.has_no_console_errors()
示例#7
0
    def test_displays_password_input(self,
                                     bokeh_model_page: BokehModelPage) -> None:
        pw_input = PasswordInput()
        page = bokeh_model_page(pw_input)

        el = find_element_for(page.driver, pw_input, "input")
        assert el.get_attribute('type') == "password"

        assert page.has_no_console_errors()
示例#8
0
    def test_displays_password_input(self, bokeh_model_page):
        pw_input = PasswordInput(css_classes=["foo"])

        page = bokeh_model_page(pw_input)

        input_div = page.driver.find_element_by_class_name('foo')
        el = input_div.find_element_by_tag_name("input")
        assert el.get_attribute('type') == "password"

        assert page.has_no_console_errors()
示例#9
0
    def test_displays_title(self, bokeh_model_page: BokehModelPage) -> None:
        pw_input = PasswordInput(title="title")
        page = bokeh_model_page(pw_input)

        el = find_element_for(page.driver, pw_input, "label")
        assert el.text == "title"
        el = find_element_for(page.driver, pw_input, "input")
        assert el.get_attribute('placeholder') == ""
        assert el.get_attribute('type') == "password"

        assert page.has_no_console_errors()
示例#10
0
    def test_displays_title(self, bokeh_model_page):
        pw_input = PasswordInput(title="title", css_classes=["foo"])

        page = bokeh_model_page(pw_input)

        el = page.driver.find_element_by_css_selector('.foo label')
        assert el.text == "title"
        el = page.driver.find_element_by_css_selector('.foo input')
        assert el.get_attribute('placeholder') == ""
        assert el.get_attribute('type') == "password"

        assert page.has_no_console_errors()
示例#11
0
    def test_displays_title(self, bokeh_model_page):
        pw_input = PasswordInput(title="title", css_classes=["foo"])

        page = bokeh_model_page(pw_input)

        input_div = page.driver.find_element_by_class_name('foo')
        el = input_div.find_element_by_tag_name("label")
        assert el.text == "title"
        el = input_div.find_element_by_tag_name("input")
        assert el.get_attribute('placeholder') == ""

        assert el.get_attribute('type') == "password"

        assert page.has_no_console_errors()
示例#12
0
    def test_server_on_change_no_round_trip_without_enter_or_click(
            self, bokeh_server_page: BokehServerPage) -> None:
        text_input = PasswordInput()
        modify_doc, _ = mk_modify_doc(text_input)
        page = bokeh_server_page(modify_doc)

        el = find_element_for(page.driver, text_input, "input")
        enter_text_in_element(
            page.driver, el, "pre",
            enter=False)  # not change event if enter is not pressed

        page.eval_custom_action()

        results = page.results
        assert results['data']['val'] == ["a", "b"]
示例#13
0
from bokeh.io import show
from bokeh.models import CustomJS, PasswordInput

password_input = PasswordInput(placeholder="enter password...")
password_input.js_on_change("value", CustomJS(code="""
    console.log('password_input: value=' + this.value, this.toString())
"""))

show(password_input)
示例#14
0
"""This example using a PasswordInput is purely for demonstration.

Putting a password plaintext in a CustomJS is not advised since it would expose the password.
"""

from bokeh.layouts import column, row
from bokeh.models import Button, CustomJS, PasswordInput, PreText, TextInput
from bokeh.plotting import output_file, show

USER = "******"
PASSWD = "Bok3h"

text = PreText(text="LOGIN TO KNOW\nTHE SECRET:")
user = TextInput(placeholder="username", title="(UserName: "******")")
pwd = PasswordInput(placeholder="password", title="(Password: "******")")
btn = Button(label="GO!", width=150)

secret = PreText()  # Secret information displayed if correct password entered

## Verify if the password typed is bokeh using a JS script
verify_pwd = CustomJS(args=dict(user=user, pwd=pwd, secret=secret),
                      code="""
    secret.text = 'Wrong Password.';
    if (user.value == %r && pwd.value == %r) {
        secret.text = 'Right Password. The Secret is 42.';
    }
""" % (USER, PASSWD))

#user.callback = verify_pwd # Check password pressing enter.
pwd.callback = verify_pwd  # Check password pressing enter.
btn.callback = verify_pwd  # Check password clicking on the Button.
示例#15
0
Putting a plaintext password ``CustomJS`` code as done here would expose the
password and is not advised in practice!
"""

from bokeh.layouts import column, row
from bokeh.models import Button, CustomJS, PasswordInput, PreText, TextInput
from bokeh.plotting import output_file, show

output_file("using_password_input.html", title="Password Field")

USER = "******"
PASSWD = "Bok3h"

text = PreText(text="LOGIN TO KNOW THE SECRET:")
user = TextInput(placeholder="username", title=f"(UserName: {USER})")
password = PasswordInput(placeholder="password", title=f"(Password: {PASSWD})")
button = Button(label="GO!", width=150)

secret = PreText() # Secret information displayed if correct password entered

# Verify if the password typed is bokeh using a JS script
verify = CustomJS(args=dict(user=user, password=password, secret=secret), code="""
    secret.text = 'Wrong Password.';
    if (user.value == %r && password.value == %r) {
        secret.text = 'Correct Password. The Secret is 42.';
    }
""" % (USER, PASSWD))

password.js_on_change('value', verify)
button.js_on_event('button_click', verify)