diff options
author | mano-wii <germano.costa@ig.com.br> | 2018-12-20 07:40:05 +0300 |
---|---|---|
committer | mano-wii <germano.costa@ig.com.br> | 2018-12-20 07:40:05 +0300 |
commit | ce4fead3d96ecc2b9a6f6962017c266edf4e353b (patch) | |
tree | db8c06a134b7d48be98793bcf17139941ccf781d /mesh_snap_utilities_line | |
parent | 9c914cb37526bd8c080e84886d70e582618cc128 (diff) |
mesh_snap_utilities_line: workaround for tool registration
Diffstat (limited to 'mesh_snap_utilities_line')
-rw-r--r-- | mesh_snap_utilities_line/__init__.py | 91 |
1 files changed, 68 insertions, 23 deletions
diff --git a/mesh_snap_utilities_line/__init__.py b/mesh_snap_utilities_line/__init__.py index c6c5f27c..68a9bfcc 100644 --- a/mesh_snap_utilities_line/__init__.py +++ b/mesh_snap_utilities_line/__init__.py @@ -22,8 +22,8 @@ bl_info = { "name": "Snap_Utilities_Line", "author": "Germano Cavalcante", - "version": (5, 8, 24), - "blender": (0, 0, 0), + "version": (5, 8, 25), + "blender": (2, 80, 0), "location": "View3D > TOOLS > Make Line", "description": "Extends Blender Snap controls", #"wiki_url" : "http://blenderartists.org/forum/showthread.php?363859-Addon-CAD-Snap-Utilities", @@ -65,47 +65,92 @@ def tool_make_line(): "Connect them to split faces" ), icon=os.path.join(icons_dir, "ops.mesh.make_line"), -# widget="MESH_GGT_mouse_point", + #widget="MESH_GGT_mouse_point", operator="mesh.make_line", - keymap=( - ("mesh.make_line", dict(type='LEFTMOUSE', value='PRESS'), None), - ), + keymap="3D View Tool: Edit Mesh, Make Line", draw_settings=draw_settings, ) -def register(): - def get_tool_list(space_type, context_mode): - from bl_ui.space_toolsystem_common import ToolSelectPanelHelper - cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type) - return cls._tools[context_mode] +# ----------------------------------------------------------------------------- +# Tool Registraion + +def km_3d_view_tool_make_line(tool_mouse = 'LEFTMOUSE'): + return [( + "3D View Tool: Edit Mesh, Make Line", + {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, + {"items": [ + ("mesh.make_line", {"type": tool_mouse, "value": 'CLICK'}, None), + ]}, + )] + + +def get_tool_list(space_type, context_mode): + from bl_ui.space_toolsystem_common import ToolSelectPanelHelper + cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type) + return cls._tools[context_mode] + + +def register_make_line_tool(): + tools = get_tool_list('VIEW_3D', 'EDIT_MESH') + + for index, tool in enumerate(tools, 1): + if isinstance(tool, ToolDef) and tool.text == "Add Cube": + break + + tools.insert(index, tool_make_line) + + keyconfigs = bpy.context.window_manager.keyconfigs + kc_defaultconf = keyconfigs.get("blender") + kc_addonconf = keyconfigs.get("blender addon") + + # TODO: find the user defined tool_mouse. + keyconfig_data = km_3d_view_tool_make_line() + from bl_keymap_utils.io import keyconfig_init_from_data + keyconfig_init_from_data(kc_defaultconf, keyconfig_data) + keyconfig_init_from_data(kc_addonconf, keyconfig_data) + + +def unregister_make_line_tool(): + tools = get_tool_list('VIEW_3D', 'EDIT_MESH') + tools.remove(tool_make_line) + + km_name, km_args, km_content = km_3d_view_tool_make_line()[0] + + keyconfigs = bpy.context.window_manager.keyconfigs + defaultmap = keyconfigs.get("blender").keymaps + addonmap = keyconfigs.get("blender addon").keymaps + + addonmap.remove(addonmap.find(km_name, **km_args)) + defaultmap.remove(defaultmap.find(km_name, **km_args)) + + +# ----------------------------------------------------------------------------- +# Addon Registraion + +def register(): bpy.utils.register_class(preferences.SnapUtilitiesLinePreferences) bpy.utils.register_class(common_classes.VIEW3D_OT_rotate_custom_pivot) bpy.utils.register_class(common_classes.VIEW3D_OT_zoom_custom_target) bpy.utils.register_class(ops_line.SnapUtilitiesLine) -# bpy.utils.register_class(common_classes.MousePointWidget) -# bpy.utils.register_class(common_classes.MousePointWidgetGroup) + #bpy.utils.register_class(common_classes.MousePointWidget) + #bpy.utils.register_class(common_classes.MousePointWidgetGroup) - bpy.utils.register_tool('VIEW_3D', 'EDIT_MESH', tool_make_line) + register_make_line_tool() - # Move tool to after 'Add Cube' - tools = get_tool_list('VIEW_3D', 'EDIT_MESH') - for index, tool in enumerate(tools): - if isinstance(tool, ToolDef) and tool.text == "Add Cube": - break - tools.insert(index + 1, tools.pop(-1)) def unregister(): - bpy.utils.unregister_tool('VIEW_3D', 'EDIT_MESH', tool_make_line) + unregister_make_line_tool() -# bpy.utils.unregister_class(common_classes.MousePointWidgetGroup) -# bpy.utils.unregister_class(common_classes.MousePointWidget) + #bpy.utils.unregister_class(common_classes.MousePointWidgetGroup) + #bpy.utils.unregister_class(common_classes.MousePointWidget) bpy.utils.unregister_class(ops_line.SnapUtilitiesLine) bpy.utils.unregister_class(common_classes.VIEW3D_OT_zoom_custom_target) bpy.utils.unregister_class(common_classes.VIEW3D_OT_rotate_custom_pivot) bpy.utils.unregister_class(preferences.SnapUtilitiesLinePreferences) + if __name__ == "__main__": __name__ = "mesh_snap_utilities_line" __package__ = "mesh_snap_utilities_line" |