From c1f4b6e9d80ad4148e21b092e6374908a76177c8 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 18 Jul 2025 06:19:18 +0200 Subject: [PATCH] Nodes: Python: show idname in node tooltip Currently, it's hard to figure out the idname of a node when just looking at it in the node editor. while most users don't need this information, it's very useful for Python developers. This patch adds the node idname to the tooltip that shows up when hovering over the node header. It only shows if "Python Tooltips" is enabled in the preferences. This also fixes a bug where the dynamic node description wouldn't show when the node is collapsed. Pull Request: https://projects.blender.org/blender/blender/pulls/142178 --- .../blender/editors/space_node/node_draw.cc | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 8c175961158..0b7843d0e6e 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -2683,6 +2683,30 @@ static bool node_undefined_or_unsupported(const bNodeTree &node_tree, const bNod return false; } +static void node_header_custom_tooltip(const bNode &node, uiBut &but) +{ + UI_but_func_tooltip_custom_set( + &but, + [](bContext & /*C*/, uiTooltipData &data, uiBut * /*but*/, void *argN) { + const bNode &node = *static_cast(argN); + const std::string description = node.typeinfo->ui_description_fn ? + node.typeinfo->ui_description_fn(node) : + node.typeinfo->ui_description; + UI_tooltip_text_field_add( + data, std::move(description), "", UI_TIP_STYLE_NORMAL, UI_TIP_LC_NORMAL); + if (U.flag & USER_TOOLTIPS_PYTHON) { + UI_tooltip_text_field_add(data, + fmt::format("Python: {}", node.idname), + "", + UI_TIP_STYLE_MONO, + UI_TIP_LC_PYTHON, + true); + } + }, + &const_cast(node), + nullptr); +} + static void node_draw_basis(const bContext &C, TreeDrawContext &tree_draw_ctx, const View2D &v2d, @@ -2978,17 +3002,7 @@ static void node_draw_basis(const bContext &C, 0, 0, TIP_(node.typeinfo->ui_description.c_str())); - UI_but_func_tooltip_set( - but, - [](bContext * /*C*/, void *arg, const StringRef tip) -> std::string { - const bNode &node = *static_cast(arg); - if (node.typeinfo->ui_description_fn) { - return node.typeinfo->ui_description_fn(node); - } - return tip; - }, - const_cast(&node), - nullptr); + node_header_custom_tooltip(node, *but); if (node.is_muted()) { UI_but_flag_enable(but, UI_BUT_INACTIVE); @@ -3229,6 +3243,7 @@ static void node_draw_collapsed(const bContext &C, 0, 0, TIP_(node.typeinfo->ui_description.c_str())); + node_header_custom_tooltip(node, *but); /* Outline. */ {