Show addon tab panel in just the Compositor, not in Shader Editor (Blender Python API)

I have posted a Blender SO question here regarding a question I have about the Blender Python API.

Any help is appreciated. Thank you in advance!

Answered on SE as well, you can add a poll function:

def poll(cls, context):
    snode = context.space_data
    return snode.tree_type == 'CompositorNodeTree'

Thanks! This works.

Thanks! Could you maybe explain a bit about what this is doing so I know for next time?

I am probably not the best one to explain as I’m just an artist but here you go:
A poll method is a condition that needs to be met for your class to exist.
If you query the context.space_data.tree_type, it will tell you which type the editor is in. The different types are: CompositorNodeTree, ShaderNodeTree, SimulationNodeTree, TextureNodeTree
So we ask “is my Node Editor currently in the CompositorNodeTree mode?”, and if it is the case, it will return True. If the poll function returns true, it will create your Class that execute your UI draw.

Now, I don’t know the API by heart, so I’ll give you a tip on how I was able to find this information quickly. In Preferences, under Interface, you can check “Developper Extras”. Now, in the Blender UI, you will be able to right click on anything and check “Edit Source”.
I did it on the Editor type selector:

It then opens the Python UI file in the Text Editor, you have to go into your Scripting layout, and open it:
It will open exactly at the line that corresponds to what you clicked on, and just by looking around that line, I could find the information I needed about the Node editor Tree_types

1 Like

Wow. Thanks for the explanation. :grinning: