I have a panel setup to do a whole bunch of stuff for a laptop model. I want it to have a system where you can add/remove a 'controller' as you would background images. I have the UI setup with the add controller button and a remove button, with all the content inside a box. How can I set this up to add a new box with all the content when the add button is pressed, and remove one when the remove button is pressed, the same way the background image system works?
Here's what I've got:
Here a small section of my code, I think it's all that should be needed:
class IgnitProperties(bpy.types.PropertyGroup):
user_items = CollectionProperty(
type = UserItems
)
class UserItems(bpy.types.PropertyGroup):
user_str = bpy.props.StringProperty()
user_int = bpy.props.IntProperty()
class AddMacBook(bpy.types.Operator):
bl_label = "Add MacBook"
bl_idname = "macbook_controller.add_macbook"
def execute(self, context):
item = bpy.context.scene.user_items.add()
item.user_int = 5
item.user_str = 'custom value'
return{'FINISHED'}
class RemoveMacBook(bpy.types.Operator):
bl_label = "Remove MacBook"
bl_idname = "macbook_controler.remove_macbook"
del_item = bpy.props.IntProperty(name='item index to remove')
def execute(self, context):
context.scene.user_items.remove(self.del_item)
return{'FINISHED'}
class IGLayoutDemoPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "MacBook Controller"
bl_idname = "macbook_controller.macbook_controller"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
scene = context.scene
split = layout.split()
scene = context.scene
camera = scene.camera.data
obj = context.object
# Add
row = layout.row(align=True)
layout.operator("macbook_controller.add_macbook")
# Box
box = layout.box()
row = box.row(align=True)
# Collapsable Menu
collapse = scene.ignit_panel.collapse
if collapse == True:
row.prop(scene.ignit_panel, "collapse",
icon="TRIA_DOWN",
icon_only=True, emboss=False
)
else:
row.prop(scene.ignit_panel, "collapse",
icon="TRIA_RIGHT",
icon_only=True, emboss=False
)
# Title (per object)
row.label(text = "MacBook")
# Remove
row.operator("macbook_controler.remove_macbook", text="", icon = "X", emboss = False)
# Collapsing everything inside the box
if collapse == True:
# Main Features
row = box.row(align=True)
row.label(text = "Main Features:")
row = box.row(align=True)
row.prop(scene.ignit_panel, "isight_camera_indicator")
row = box.row(align=True)
row.prop(scene.ignit_panel, "menubar_and_dock")
row = box.row(align=True)
row.prop(scene.ignit_panel, "backlit_keys")
row = box.row(align=True)
row.prop(scene.ignit_panel, "screen_brightness")
row = box.row(align=True)
row.prop(scene.ignit_panel, "dirt_and_dust_factor")
# Screen Icons
row = box.row(align=True)
row.label(text = "Screen Icons:")
row = box.row(align=True)
row.prop(scene.ignit_panel, "screen_icons", text = "Screen Icon Brightness")
row = box.row(align=True)
row.prop(scene.ignit_panel, "icons", expand = True)
icons = scene.ignit_panel.icons
row = box.row(align=True)
if icons == 'Brightness':
row.prop(scene.ignit_panel, "icon_factor", text = "Brightness Icon")
elif icons == 'Backlit Keys':
row.prop(scene.ignit_panel, "icon_factor", text = "Backlit Keys Icon")
elif icons == 'Volume':
row.prop(scene.ignit_panel, "icon_factor", text = "Volume Icon")
# Screen Rotation
row = box.row(align=True)
row.label(text = "Screen Rotation:")
row = box.row(align=True)
row.prop(scene.ignit_panel, "screen_rotation")
# Screen Texture
row = box.row(align=True)
row.label(text = "Screen Texture:")
row = box.row(align=True)
row.prop(scene.ignit_panel, "screen_path")
row.operator("macbook_controller.identifier_file_selector", text="", icon='FILESEL')
# MacBook Colors
row = box.row(align=True)
row.label(text = "MacBook Color:")
row = box.row(align=True)
row.prop(scene.ignit_panel, "colors", expand = True)
for idx, item in enumerate(scene.ignit_panel.user_items):
row = col.row()
row.prop(item,'user_str')
row.operator(UserDelOptions.bl_idname, text='',
icon='X').del_item = idx
row = col.row()
row.prop(item,'user_int')
def register():
bpy.utils.register_module(__name__)
bpy.types.Scene.ignit_panel = bpy.props.PointerProperty(type=IgnitProperties)
def unregister():
bpy.utils.unregister__module(__name__)
del bpy.types.Scene.ignit_panel