Skip to content

Commit

Permalink
support tooltip kwarg for gradio elements
Browse files Browse the repository at this point in the history
  • Loading branch information
AUTOMATIC1111 committed Aug 1, 2023
1 parent 401ba1b commit 6a0d498
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions javascript/hints.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,14 @@ onUiUpdate(function(mutationRecords) {
tooltipCheckTimer = setTimeout(processTooltipCheckNodes, 1000);
}
});

onUiLoaded(function() {
for (var comp of window.gradio_config.components) {
if (comp.props.webui_tooltip && comp.props.elem_id) {
var elem = gradioApp().getElementById(comp.props.elem_id);
if (elem) {
elem.title = comp.props.webui_tooltip;
}
}
}
});
14 changes: 14 additions & 0 deletions modules/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ def add_classes_to_gradio_component(comp):


def IOComponent_init(self, *args, **kwargs):
self.webui_tooltip = kwargs.pop('tooltip', None)

if scripts_current is not None:
scripts_current.before_component(self, **kwargs)

Expand All @@ -663,8 +665,20 @@ def IOComponent_init(self, *args, **kwargs):
return res


def Block_get_config(self):
config = original_Block_get_config(self)

webui_tooltip = getattr(self, 'webui_tooltip', None)
if webui_tooltip:
config["webui_tooltip"] = webui_tooltip

return config


original_IOComponent_init = gr.components.IOComponent.__init__
original_Block_get_config = gr.components.Block.get_config
gr.components.IOComponent.__init__ = IOComponent_init
gr.components.Block.get_config = Block_get_config


def BlockContext_init(self, *args, **kwargs):
Expand Down

1 comment on commit 6a0d498

@akx
Copy link
Collaborator

@akx akx commented on 6a0d498 Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

It's a monkey-patch alright, but the best we can do without upstream support.

Please sign in to comment.