Bokeh:确定哪个模型调用了 on_change 事件处理程序

Bokeh: Determine which model called an on_change event handler

我有以下场景,我想用 on_change 执行函数:

def update_func:
    calling_widget = < I need the name of the widget here: "SelectorWidget" >
    do_something

SelectorWidget = MultiSelect(title="A widget", value = "default", options = option_list)

SelectorWidget.on_change('value', update_func)

同一个update_func会用在不同的widget上,希望每次都能获取到触发函数的Widget的名称。

有什么想法吗?

尝试:

from functools import partial

# add a widget arg to standard callback signature
def update_func(attr, old, new, widget):
    # do something with widget

SelectorWidget = MultiSelect(title="A widget", 
                             value="default", 
                             options=option_list)

# use partial to make a callback callable with widget arg bound
SelectorWidget.on_change('value', 
                         partial(update_func, widget=SelectorWidget))