3
$\begingroup$

I can't find anywhere how can i add the panel of an operator in the Speaker properties data tab only. it appears in all other objects data tab and i can't find a context list

enter image description here

class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"

Thank you.

$\endgroup$
5
$\begingroup$

Add a poll method.

To narrow it down could look to see if context object is of type 'SPEAKER' or since it is in the properties space, there is a speaker context member available when the object is not a speaker it will be none.

class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "data"

    @classmethod 
    def poll(cls, context):
        return context.speaker is not None
    
    def draw(self, context):
        layout = self.layout

        obj = context.object

        row = layout.row()
        row.label(text="Hello world!", icon='WORLD_DATA')
$\endgroup$
1
  • $\begingroup$ I hope this is Python, because I'm a beginner learning it. Thanks for sharing. $\endgroup$ – Rita Geraghty stands by Monica Jan 7 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.