def callback_disable(n_id):
    global callback_dict
    handle_pixel = callback_dict.get(n_id, None)
    if not handle_pixel:
        return
    SpaceNodeEditor.draw_handler_remove(handle_pixel, 'WINDOW')
    del callback_dict[n_id]
    tag_redraw_all_nodeviews()
示例#2
0
def callback_disable(n_id):
    # global callback_dict
    handle_pixel = callback_dict.get(n_id, None)
    if not handle_pixel:
        return
    SpaceNodeEditor.draw_handler_remove(handle_pixel, 'WINDOW')
    del callback_dict[n_id]
    tag_redraw_all_nodeviews()
    def modal(self, context, event):
        context.area.tag_redraw()

        if event.shift and event.type == 'SLASH' and event.value == 'PRESS':
            self.current_string = self.current_string + '?'

        elif event.type in KEYBOARD and event.value == 'PRESS':
            if event.type in CAPS or event.type in remap_nums.keys() or event.type == 'SPACE':

                if event.type == 'SPACE':
                    final_value = ' '
                else:
                    final_value = remap_nums.get(event.type, event.type.lower())

                self.current_string = self.current_string + final_value
            elif event.type == 'BACK_SPACE':
                has_length = len(self.current_string)
                self.current_string = self.current_string[:-1] if has_length else ''
            elif event.type in {'UP_ARROW', 'DOWN_ARROW'}:
                self.new_direction = {'UP_ARROW': -1, 'DOWN_ARROW': 1}.get(event.type)
                self.current_index += self.new_direction

            flat_node_cats['list_return'] = results = return_search_results(self.current_string)
            if results and len(results):
                self.current_index %= len(results)

        elif event.type in {'LEFTMOUSE', 'RET'}:
            SpaceNodeEditor.draw_handler_remove(self._handle, 'WINDOW')

            if route_as_nodelookup(self, context):
                pass
            elif route_as_macro(self, context):
                pass
            elif route_as_websearch(self):
                pass
           
            print('completed')
            flat_node_cats['list_return'] = []
            return {'FINISHED'}

        elif event.type in {'RIGHTMOUSE', 'ESC'}:
            SpaceNodeEditor.draw_handler_remove(self._handle, 'WINDOW')
            flat_node_cats['list_return'] = []
            return {'CANCELLED'}

        return {'RUNNING_MODAL'}
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'}
示例#7
0
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()