Cleanup: use staticmethod where appropriate
[blender.git] / release / scripts / templates_py / ui_tool_simple.py
1 # This example adds an object mode tool to the toolbar.
2 # This is just the circle-select and lasso tools tool.
3 import bpy
4 from bpy.types import WorkSpaceTool
5
6 class MyTool(WorkSpaceTool):
7     bl_space_type='VIEW_3D'
8     bl_context_mode='OBJECT'
9
10     # The prefix of the idname should be your add-on name.
11     bl_idname = "my_template.my_circle_select"
12     bl_label = "My Circle Select"
13     bl_description = (
14         "This is a tooltip\n"
15         "with multiple lines"
16     )
17     bl_icon = "ops.generic.select_circle"
18     bl_widget = None
19     bl_keymap = (
20         ("view3d.select_circle", {"type": 'LEFTMOUSE', "value": 'PRESS'},
21          {"properties": [("wait_for_input", False)]}),
22         ("view3d.select_circle", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
23          {"properties": [("mode", 'SUB'), ("wait_for_input", False)]}),
24     )
25
26     def draw_settings(context, layout, tool):
27         props = tool.operator_properties("view3d.select_circle")
28         layout.prop(props, "mode")
29         layout.prop(props, "radius")
30
31
32 class MyOtherTool(WorkSpaceTool):
33     bl_space_type='VIEW_3D'
34     bl_context_mode='OBJECT'
35
36     bl_idname = "my_template.my_other_select"
37     bl_label = "My Lasso Tool Select"
38     bl_description = (
39         "This is a tooltip\n"
40         "with multiple lines"
41     )
42     bl_icon = "ops.generic.select_lasso"
43     bl_widget = None
44     bl_keymap = (
45         ("view3d.select_lasso", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
46         ("view3d.select_lasso", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
47          {"properties": [("mode", 'SUB')]}),
48     )
49
50     def draw_settings(context, layout, tool):
51         props = tool.operator_properties("view3d.select_lasso")
52         layout.prop(props, "mode")
53
54
55 def register():
56     bpy.utils.register_tool(MyTool, after={"builtin.scale_cage"}, separator=True, group=True)
57     bpy.utils.register_tool(MyOtherTool, after={MyTool.bl_idname})
58
59 def unregister():
60     bpy.utils.unregister_tool(MyTool)
61     bpy.utils.unregister_tool(MyOtherTool)
62
63 if __name__ == "__main__":
64     register()