def callback_enable(*args): n_id = args[0] global callback_dict if n_id in callback_dict: return handle_pixel = SpaceNodeEditor.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_VIEW') callback_dict[n_id] = handle_pixel tag_redraw_all_nodeviews()
def callback_enable(*args): n_id = args[0] # global callback_dict if n_id in callback_dict: return handle_pixel = SpaceNodeEditor.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_VIEW') callback_dict[n_id] = handle_pixel tag_redraw_all_nodeviews()
def invoke(self, context, event): if context.area.type == 'NODE_EDITOR': # [ ] make current session history available, maybe with ctrl+up/down ? # [ ] make longterm session history available? # unusually, if this is not set the operator seems to behave like it remembers the last string. self.current_string = "" flat_node_cats['results'] = make_flat_nodecats() start_position = 20, 20 # event.mouse_region_x, event.mouse_region_y args = (self, context, start_position) self._handle = SpaceNodeEditor.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_PIXEL') context.window_manager.modal_handler_add(self) return {'RUNNING_MODAL'} else: self.report({'WARNING'}, "NODE_EDITOR not found, cannot run operator") return {'CANCELLED'}
def draw_text(node, text: str, draw_id=None, color=(1, 1, 1, 1), scale=1., align="RIGHT", dynamic_location=True): """Draw any text nearby a node, use together with callback_disable align = {"RIGHT", "UP", "DOWN"} todo replace with typing.Literal""" draw_id = draw_id or node.node_id if draw_id in callback_dict: callback_disable(draw_id) color = color if len(color) == 4 else (*color, 1) text_location = None if dynamic_location else _get_text_location( node, align) handle_pixel = SpaceNodeEditor.draw_handler_add( _draw_text_handler, (node.id_data.tree_id, node.node_id, text, color, scale, align, text_location), 'WINDOW', 'POST_VIEW') callback_dict[draw_id] = handle_pixel tag_redraw_all_nodeviews()