import omni.ext
from .skel_animation_widget import SkelAnimationAttributesWidget
from .mesh_skel_binding_widget import MeshSkelBindingAttributesWidget


class SkelPropertyExtension(omni.ext.IExt):
    def __init__(self):
        self._skel_widget = None

    def on_startup(self, ext_id):
        import omni.kit.window.property as p
        self._skel_animation_widget = SkelAnimationAttributesWidget("Skeletal Animation")
        self._mesh_skel_binding_widget = MeshSkelBindingAttributesWidget("Skeletal Binding")
        w = p.get_window()
        if w:
            w.register_widget("prim", "skel_animation", self._skel_animation_widget)
            w.register_widget("prim", "mesh_skel_binding", self._mesh_skel_binding_widget)

    def on_shutdown(self):
        if self._skel_widget is not None:
            import omni.kit.window.property as p
            w = p.get_window()
            if w:
                w.unregister_widget("prim", "skel_animation")
                w.unregister_widget("prim", "mesh_skel_binding")
            self._skel_animation_widget.destroy()
            self._skel_animation_widget = None
            self._mesh_skel_binding_widget.destroy()
            self._mesh_skel_binding_widget = None
