c3y
c3y

Reputation: 39

How To Get Currently Active Tool in Bokeh Figure

I'm interested in finding the currently selected tool out of the toolbar on a figure. Right now I have a customized toolbar, and I want to be able to get the active tool in a Python callback for a bokeh app.

def scrollCallback():
    # check if PanTool() is currently selected/active

fig = figure(...)
fig.toolbar.active_drag = None
fig.toolbar.active_scroll = None
fig.tools = [PanTool(), BoxZoomTool(), ResetTool()]
fig.on_event(events.Pan, scrollCallback)

Upvotes: 1

Views: 506

Answers (1)

bigreddot
bigreddot

Reputation: 34568

As of Bokeh 1.3.4 this information is not exposed to the Python public API. You can inspect an internal property .active on the JavaScript side (e.g. from a CustomJS callback). a kludgy workaround to get the information to a Python callback might be to have a CustomJS look at all the tools to see which are active, and set some value on, say, an invisible glyph, that the Python side can monitor for changes. I don't think that's a good solution, but probably the best one available. You could propose making the active state available publicly as a new feature request by making an issue on GitHub. Now that read-only properties exist, it might be simple and safe to allow this internal property to join the public API.

Upvotes: 1

Related Questions