def tool_from_class(tool_cls): # Convert class to tuple, store in the class for removal. tool_def = ToolDef.from_dict({ "idname": tool_cls.bl_idname, "label": tool_cls.bl_label, "description": getattr(tool_cls, "bl_description", tool_cls.__doc__), "icon": getattr(tool_cls, "bl_icon", None), "cursor": getattr(tool_cls, "bl_cursor", None), "widget": getattr(tool_cls, "bl_widget", None), "keymap": getattr(tool_cls, "bl_keymap", None), "data_block": getattr(tool_cls, "bl_data_block", None), "operator": getattr(tool_cls, "bl_operator", None), "draw_settings": getattr(tool_cls, "draw_settings", None), "draw_cursor": getattr(tool_cls, "draw_cursor", None), }) tool_cls._bl_tool = tool_def keymap_data = tool_def.keymap if keymap_data is not None: if context_mode is None: context_descr = "All" else: context_descr = context_mode.replace("_", " ").title() from bpy import context wm = context.window_manager kc = wm.keyconfigs.default if callable(keymap_data[0]): cls._km_action_simple(kc, context_descr, tool_def.label, keymap_data) return tool_def
def tool_from_class(tool_cls): # Convert class to tuple, store in the class for removal. tool_def = ToolDef.from_dict({ "idname": tool_cls.bl_idname, "label": tool_cls.bl_label, "description": getattr(tool_cls, "bl_description", tool_cls.__doc__), "icon": getattr(tool_cls, "bl_icon", None), "cursor": getattr(tool_cls, "bl_cursor", None), "widget": getattr(tool_cls, "bl_widget", None), "keymap": getattr(tool_cls, "bl_keymap", None), "data_block": getattr(tool_cls, "bl_data_block", None), "operator": getattr(tool_cls, "bl_operator", None), "draw_settings": getattr(tool_cls, "draw_settings", None), "draw_cursor": getattr(tool_cls, "draw_cursor", None), }) tool_cls._bl_tool = tool_def keymap_data = tool_def.keymap if keymap_data is not None: if context_mode is None: context_descr = "All" else: context_descr = context_mode.replace("_", " ").title() from bpy import context wm = context.window_manager keyconfigs = wm.keyconfigs kc_default = keyconfigs.default # Note that Blender's default tools use the default key-config for both. # We need to use the add-ons for 3rd party tools so reloading the key-map doesn't clear them. kc = keyconfigs.addon if callable(keymap_data[0]): cls._km_action_simple(kc_default, kc, context_descr, tool_def.label, keymap_data) return tool_def