rig_picker/area.py

98 lines
2.9 KiB
Python

import bpy
from bpy.types import NodeTree, NODE_PT_tools_active, NODE_HT_header
# Derived from the NodeTree base type, similar to Menu, Operator, Panel, etc.
class RigPickerTree(NodeTree):
# Description string
'''A custom node tree type that will show up in the editor type list'''
# Optional identifier string. If not explicitly defined, the python class name is used.
# Label for nice name display
bl_label = "Rig Picker"
# Icon identifier
bl_icon = 'OUTLINER_DATA_ARMATURE'
def draw_header(self, context):
if context.space_data.tree_type == 'RigPickerTree':
layout = self.layout
layout.template_header()
#layout.separator_spacer()
if not context.space_data.node_tree:
ntree = bpy.data.node_groups.get('.rig_picker')
if not ntree:
ntree = bpy.data.node_groups.new('.rig_picker', 'RigPickerTree')
context.space_data.node_tree = ntree
#layout.template_ID(context.space_data, "node_tree", new="node.new_node_tree")
#layout.separator_spacer()
layout.operator('rigpicker.reload_picker', icon='FILE_REFRESH', text='')
#layout.prop('rigpicker.reload_picker', icon='FILE_REFRESH', text='')
layout.separator_spacer()
else:
self._draw(context)
def tools_from_context(context, mode=None):
sp = context.space_data
if sp and sp.type == 'NODE_EDITOR' and sp.tree_type == 'RigPickerTree':
return []
else:
return NODE_PT_tools_active._tools_from_context(context, mode)
def tool_set_by_id(self, context):
sd = context.space_data
if sd and sd.type == 'NODE_EDITOR' and sd.tree_type == 'RigPickerTree':
return {"FINISHED"}
else:
return self._execute(context)
@classmethod
def poll(cls, context):
sp = context.space_data
if sp and sp.type == 'NODE_EDITOR' and sp.tree_type == 'RigPickerTree':
return False
else:
return self._poll(context)
classes = (
RigPickerTree,
)
def register():
bpy.types.WM_OT_tool_set_by_id._execute = bpy.types.WM_OT_tool_set_by_id.execute #tool_set_by_id
bpy.types.WM_OT_tool_set_by_id.execute = tool_set_by_id
NODE_PT_tools_active._tools_from_context = NODE_PT_tools_active.tools_from_context
NODE_PT_tools_active.tools_from_context = tools_from_context
NODE_HT_header._draw = NODE_HT_header.draw
NODE_HT_header.draw = draw_header
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
bpy.types.WM_OT_tool_set_by_id.execute = bpy.types.WM_OT_tool_set_by_id._execute
del bpy.types.WM_OT_tool_set_by_id._execute
NODE_PT_tools_active.tools_from_context = NODE_PT_tools_active._tools_from_context
del NODE_PT_tools_active._tools_from_context
NODE_HT_header.draw = NODE_HT_header._draw
del NODE_HT_header._draw