A simple Node:
import bpy
class TestNode(bpy.types.Node):
'''ww Test Node'''
bl_idname = 'ww_TestNode'
bl_label = 'TestNode'
bl_icon = 'ARROW_LEFTRIGHT'
bl_width_min = 400
bl_width_max = 5000
@classmethod
def poll(cls, ntree):
return ntree.bl_idname == 'ww_NTTest'
def update_func(self,context):
pass
def init(self, context):
bpy.ops.ww.test_modal_operator()
pass
def copy(self, node):
print("copied node", node)
def free(self):
print("Node removed", self)
def draw_buttons(self, context, layout):
row = layout.row()
row.operator('ww.test_modal_operator',text='Test Button')
def draw_buttons_ext(self, context, layout):
pass
A simple modal Operator
class TestModalOperator(bpy.types.Operator):
""" This operator Tests it's invoke method"""
bl_idname = "ww.test_modal_operator"
bl_label = "Test Modal Operator"
def modal(self, context, event):
if event.type =="ESC":
return self.cancel(context)
if event.type == 'TIMER':
pass
return {'PASS_THROUGH'}
def execute(self, context):
print('execute')
self._timer = context.window_manager.event_timer_add(0.001, window=context.window)
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
def invoke(self, context, event):
print('invoke')
return {'RUNNING_MODAL'}
def cancel(self, context):
print('cancel')
context.window_manager.event_timer_remove(self._timer)
return {'CANCELLED'}
By inserting the node into the tree it starts a modal operator. Using it's init method. A button to start an other instance of the operator is provided as well.
The instantiation by the init method does not call the invoke method of the operator but the call goes to the execute method, the button goes to the invoke method.
Is this intentionally? If so why?
WKR Martin