nodeslicer/infra/blender/mixins.py
2026-05-18 13:19:19 +03:00

37 lines
No EOL
1.1 KiB
Python

import bpy
class DrawCollectionMixin():
items: bpy.props.CollectionProperty # pyright: ignore[reportGeneralTypeIssues]
def draw_collection(self, items, layout):
col = layout.column(align=True)
for item in items:
item.draw_item(col)
def _draw_prop(self, text, layout):
self.draw_collection(self.items, layout)
def update_collection(items: bpy.props.CollectionProperty) -> None: # pyright: ignore[reportGeneralTypeIssues]
if len(items) == 0:
items.add()
if items[-1].is_active:
items.add()
while len(items) >= 2:
if not items[-1].is_active and not items[-2].is_active:
items.remove(len(items) - 1)
else:
break
class UpdateCollectionMixin():
items: bpy.props.CollectionProperty # pyright: ignore[reportGeneralTypeIssues]
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.update()
def update(self):
update_collection(self.items)
class CollectionMixin(DrawCollectionMixin, UpdateCollectionMixin): ...