6
$\begingroup$

Is it possible to make collapsible panel like it is for object modifiers? I need something similar for my plugin. After choose menu item I want to create new panel with collapsible box, where can I change parameters for objects. screenshoot http://www.23hq.com/pkulas/photo/18279220/original I tried before to make panel with bpy.types.UILayout.template_list but it was too hard to build from scratch for me. Documentation isn't very friendly, hard to know what can I use for these arguments (active_dataptr, active_propname) Next months I'm working on my plugin, before that I need to make good UI for it.

$\endgroup$
  • $\begingroup$ Have you tried to check the Python code for the modifiers' UI? $\endgroup$ – someonewithpc Nov 22 '14 at 18:37
  • $\begingroup$ Yes I tried but it's more complex and associated with different global variables. Here is a part of modifier UI $\endgroup$ – Reborn Nov 22 '14 at 19:09
  • $\begingroup$ possible duplicate of How to make compare with Menus $\endgroup$ – Ray Mairlot Nov 23 '14 at 14:37
9
$\begingroup$

It's basically a camouflaged checkbox (boolean property) with changing icon:

import bpy


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 = "object"

    def draw(self, context):
        layout = self.layout
        obj = context.object

        box = layout.box()

        row = box.row()
        row.prop(obj, "expanded",
            icon="TRIA_DOWN" if obj.expanded else "TRIA_RIGHT",
            icon_only=True, emboss=False
        )
        row.label(text="Active object is: " + obj.name)

        if obj.expanded:
            row = box.row()
            row.prop(obj, "name")

            row = box.row()
            row.label(text="Hello world!", icon='WORLD_DATA')

            row = box.row()
            row.operator("mesh.primitive_cube_add")


def register():
    bpy.utils.register_class(HelloWorldPanel)
    bpy.types.Object.expanded = bpy.props.BoolProperty(default=True)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)
    del bpy.types.Object.expanded


if __name__ == "__main__":
    register()
$\endgroup$

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