Custom Tooltip/Icon not implemented in SelectTools

Hello,

I am trying to set a custom tooltip and custom icon for the BoxSelectTool (using it with a CustomJS Div as a measurement tool!), and it seems that the custom_tooltip and custom_icon params are not a part of this class. I have been using both customizations in the PointDrawTool, so I would think it would be a pretty simple thing to add in. Looks like BoxSelectTool is implementing the SelectTool class, so that would be the place to add it so that it applies to all Select Tools.

This is similar to the issue/solution in Icons for custom toolbar tool - #9 by p-himik

Thanks!

You must be using an old version of Bokeh? The BoxSelectTool does have both custom_icon and custom_tooltip properties and it appears these properties existed as far back as version 2.0. If you are using a version more recent than that, then a Minimal Reproducible Example would be needed in order to speculate more about what might be going on.

Hi Bryan,

Thanks for the quick response! I am using bokeh 2.2.3, however not seeing those params when looking in the API docs under BoxSelectTool (the links you provided were for the BoxEditTool). Those params seem to be present in all classes inheriting the EditTool, but not in those inheriting the SelectTool.

Just in case, below is my reprex:

import pandas as pd
from bokeh.models import BoxSelectTool, CrosshairTool, PointDrawTool
from bokeh.plotting import ColumnDataSource, figure, output_file, reset_output, show

p = figure()
# Draw some random points
x_coords = [0, 1, 2, 3, 4]
y_coords = [0, 1, 2, 3, 4]
p.scatter(x=x_coords, y=y_coords, color='red')

# Setup source, renderer, icon, and PointDrawTool -> this works fine and my icon shows up
src = ColumnDataSource(pd.DataFrame({'x': [], 'y': []}))
r1 = p.rect(x='x', y='y', width=0.5, height=0.5, source=src)
pd_icon = '/home/user/icon.png'  # this is a 200x200 transparent png file
pd_tool = PointDrawTool(renderers=[r1], custom_tooltip='Add New Rect', custom_icon=pd_icon)

# Try the same with tool of type SelectTool -> this does not work, causes error (below)
select_icon = '/home/user/icon2.png'
box_sel = BoxSelectTool(dimensions='height', mode=None, custom_tooltip='Box Select Test', custom_icon=select_icon)
p.add_tools(pd_tool, box_sel)

show(p)

This ends up giving me the following traceback (which makes sense):

Traceback (most recent call last):

  File "<ipython-input-65-fe6b63b66c18>", line 16, in <module>
    box_sel = BoxSelectTool(dimensions='height', mode=None, custom_tooltip='Box Select Test', custom_icon=select_icon)

  File "/home/user/anaconda3/envs/bokeh-test/lib/python3.8/site-packages/bokeh/model.py", line 235, in __init__
    super().__init__(**kwargs)

  File "/home/user/anaconda3/envs/bokeh-test/lib/python3.8/site-packages/bokeh/core/has_props.py", line 249, in __init__
    setattr(self, name, value)

  File "/home/user/anaconda3/envs/bokeh-test/lib/python3.8/site-packages/bokeh/core/has_props.py", line 285, in __setattr__
    raise AttributeError("unexpected attribute '%s' to %s, %s attributes are %s" %

AttributeError: unexpected attribute 'custom_tooltip' to BoxSelectTool, possible attributes are dimensions, js_event_callbacks, js_property_callbacks, mode, name, names, origin, overlay, renderers, select_every_mousemove, subscribed_events or tags

Ah, my mistake. custom_icon is found on the EditTool base class. I am not sure offhand if there is any particular reason it is not on all action tools. In any case the, appropriate place to ask for it to be considered for future feature development is a GitHub Issue.

Ok sounds good - created Issue #10914

1 Like