Detect UI element under mouse for panels or nodes

Hi guys,
I am trying to determine the RNA path for a node property. Using bpy.ops.ui.copy_data_path_button() does not work with PropertyGroup for some reason… Instead, I was trying to identify the UI element under mouse in order to determine it’s type and calculate the path. I was able so far to identify the node under mouse using the code from nodewrangler, but not the UI elements inside the node. Any ideas?

And there is this https://developer.blender.org/T51096 with the usual answer…

“The Python tooltips are incomplete for PropertyGroups because RNA_path_full_property_py_ex() ( rna_access.c ) doesn’t return a full path.” https://blender.stackexchange.com/questions/158408/turning-off-anti-aliasing-inconsistency-between-info-window-and-valid-python

Probably, same reason here: https://developer.blender.org/T69973

There is no mechanism to access the GUI event callbacks, such as mouseover or mouseclick. However you can try workarounds.

The most extreme scenario is to attach a custom GUI that is drawn ontop of Blender elements but gives the correct widgets so you can interact with. That way you can in some way hardcode the GUI regions and attach event callbacks yourself.

This is a very extreme scenario, no one has ever done that so far, there are no guarantees that it will work perfectly.

1 Like

thanks, but I was hoping for a solution based on blender’s own UI widgets.

What I have noticed is that if you write code in the draw method (such as print) it can be executed during GUI evaluation. However the entire GUI is a blackbox with no way to access it internally.

import bpy

class HelloWorldPanel(bpy.types.Panel):
    bl_idname = "OBJECT_PT_hello_world"
    bl_label = "Hello World"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        self.layout.label(text="Hello World")


bpy.utils.register_class(HelloWorldPanel)

The best chance is that you can approximate the collision box using hard-coded relative values. That way you can simulate a “mouse over” event etc (Use your event callbcak mechanism … see: pubsub-js). Not exactly the perfect way, more of an evil hack. :slight_smile:

that’s what I fear… or maybe someday they will fix path_from_id to make it work with propgroups and propcollection :slight_smile:

Perhaps we can throw some ideas in a bucket list. Let Blender developers know about possibilities.

I don’t think that having UI widgets callback is a ground breaking idea. Every serious widgets framework has this functionality out of the box. Besides this, similar problems ware reported already multiple times. Apparently this is not big enough for B team. it’s only a low priority task

Now I remembered recently I was trying to think of something similar. I had not exactly the mindset of an event driven model in mind, but now as of speaking it fits correctly in this design model. It can be solved with some API capability like this.

A slider property that acts like an operator

this is not fixing my problem. I need to know the ‘prop path’ under the mouse for grouped props. the path can be determined if you have access to the prop itself first, but not the other way around. bpy.ops.ui.copy_data_path_button() works only for non grouped props

I found an workaroud for nodes. You can use node.inputs collection to store your props. this collection works with plain props. you don’t need groups to make it work. and if you don’t want to display the props, you can hide the socket…

This looks interesting, if you release any scripts later on let me know to have a look.