Commit: b932635bfd0260019157de796556cd1f7a7c762b Author: William Reynish Date: Wed Apr 10 12:49:51 2019 +0200 Branches: master https://developer.blender.org/rBb932635bfd0260019157de796556cd1f7a7c762b
Industry Compatible Keymap: initial keymap This is the initial implementation. It's fully functional for object and edit mode, but requires more work in Sculpt and Paint modes. See T54963 =================================================================== A release/scripts/presets/keyconfig/industry_compatible.py A release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py =================================================================== diff --git a/release/scripts/presets/keyconfig/industry_compatible.py b/release/scripts/presets/keyconfig/industry_compatible.py new file mode 100644 index 00000000000..8ce38d4b40e --- /dev/null +++ b/release/scripts/presets/keyconfig/industry_compatible.py @@ -0,0 +1,91 @@ +import os +import bpy + +# ------------------------------------------------------------------------------ +# Operators needed by this keymap to function + +# Selection Modes + +class IC_KEYMAP_OT_mesh_select_mode(bpy.types.Operator): + bl_idname = "ic_keymap.mesh_select_mode" + bl_label = "Switch to Vertex, Edge or Face Mode from any mode" + bl_options = {'UNDO'} + + type: bpy.props.EnumProperty( + name="Mode", + items=( + ('VERT', "Vertex", "Switcth to Vertex Mode From any Mode"), + ('EDGE', "Edge", "Switcth to Edge Mode From any Mode"), + ('FACE', "Face", "Switcth to Face Mode From any Mode"), + ), + ) + + @classmethod + def poll(cls, context): + return (context.active_object is not None) and (context.object.type == 'MESH') + + def execute(self, context): + bpy.ops.object.mode_set(mode='EDIT') + bpy.ops.mesh.select_mode(type=self.type) + + return{'FINISHED'} + + +classes = ( + IC_KEYMAP_OT_mesh_select_mode, +) + + +# ------------------------------------------------------------------------------ +# Keymap + +dirname, filename = os.path.split(__file__) +idname = os.path.splitext(filename)[0] + +def update_fn(_self, _context): + load() + + +def keyconfig_data_oskey_from_ctrl(keyconfig_data_src): + # TODO, make into more generic event transforming function. + keyconfig_data_dst = [] + for km_name, km_parms, km_items_data_src in keyconfig_data_src: + km_items_data_dst = km_items_data_src.copy() + items_dst = [] + km_items_data_dst["items"] = items_dst + for item_src in km_items_data_src["items"]: + item_op, item_event, item_prop = item_src + if "ctrl" in item_event: + item_event = item_event.copy() + item_event["oskey"] = item_event["ctrl"] + del item_event["ctrl"] + items_dst.append((item_op, item_event, item_prop)) + items_dst.append(item_src) + keyconfig_data_dst.append((km_name, km_parms, km_items_data_dst)) + return keyconfig_data_dst + + +industry_compatible = bpy.utils.execfile(os.path.join(dirname, "keymap_data", "industry_compatible_data.py")) + + +def load(): + from sys import platform + from bl_keymap_utils.io import keyconfig_init_from_data + + prefs = bpy.context.preferences + + kc = bpy.context.window_manager.keyconfigs.new(idname) + params = industry_compatible.Params(use_mouse_emulate_3_button=prefs.inputs.use_mouse_emulate_3_button) + keyconfig_data = industry_compatible.generate_keymaps(params) + + if platform == 'darwin': + keyconfig_data = keyconfig_data_oskey_from_ctrl(keyconfig_data) + + keyconfig_init_from_data(kc, keyconfig_data) + +if __name__ == "__main__": + # XXX, no way to unregister + for cls in classes: + bpy.utils.register_class(cls) + + load() diff --git a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py new file mode 100644 index 00000000000..db1573f5105 --- /dev/null +++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py @@ -0,0 +1,3618 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + + +# ------------------------------------------------------------------------------ +# Configurable Parameters + +class Params: + __slots__ = ( + "select_mouse", + "select_mouse_value", + "select_tweak", + "action_mouse", + "action_tweak", + "tool_mouse", + "tool_tweak", + "use_mouse_emulate_3_button", + + ) + + def __init__( + self, + *, + use_mouse_emulate_3_button=False, + ): + self.tool_mouse = 'LEFTMOUSE' + self.tool_tweak = 'EVT_TWEAK_L' + self.action_tweak = 'EVT_TWEAK_R' + self.use_mouse_emulate_3_button = use_mouse_emulate_3_button + + +# ------------------------------------------------------------------------------ +# Constants + + +# Physical layout. +NUMBERS_1 = ('ONE', 'TWO', 'THREE', 'FOUR', 'FIVE', 'SIX', 'SEVEN', 'EIGHT', 'NINE', 'ZERO') +# Numeric order. +NUMBERS_0 = ('ZERO', 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE', 'SIX', 'SEVEN', 'EIGHT', 'NINE') + + +# ------------------------------------------------------------------------------ +# Keymap Item Wrappers + +def op_menu(menu, kmi_args): + return ("wm.call_menu", kmi_args, {"properties": [("name", menu)]}) + + +def op_menu_pie(menu, kmi_args): + return ("wm.call_menu_pie", kmi_args, {"properties": [("name", menu)]}) + + +def op_panel(menu, kmi_args, kmi_data=()): + return ("wm.call_panel", kmi_args, {"properties": [("name", menu), *kmi_data]}) + + +def op_tool(tool, kmi_args): + return ("wm.tool_set_by_id", kmi_args, {"properties": [("name", tool)]}) + + +def op_tool_cycle(tool, kmi_args): + return ("wm.tool_set_by_id", kmi_args, {"properties": [("name", tool), ("cycle", True)]}) + + +# ------------------------------------------------------------------------------ +# Keymap Templates + + +def _template_items_object_subdivision_set(): + return [ + ("object.subdivision_set", + {"type": NUMBERS_0[i], "value": 'PRESS', "ctrl": True}, + {"properties": [("level", i), ("relative", False)]}) + for i in range(6) + ] + + +def _template_items_gizmo_tweak_value(): + return [ + ("gizmogroup.gizmo_tweak", {"type": 'LEFTMOUSE', "value": 'PRESS', "any": True}, None), + ] + + +def _template_items_animation(): + return [ + ("screen.frame_offset", {"type": 'LEFT_ARROW', "value": 'PRESS'}, + {"properties": [("delta", -1)]}), + ("screen.frame_offset", {"type": 'RIGHT_ARROW', "value": 'PRESS'}, + {"properties": [("delta", 1)]}), + ("screen.frame_jump", {"type": 'RIGHT_ARROW', "value": 'PRESS', "ctrl": True}, + {"properties": [("end", True)]}), + ("screen.frame_jump", {"type": 'LEFT_ARROW', "value": 'PRESS', "ctrl": True}, + {"properties": [("end", False)]}), + + ] + + +def _template_items_gizmo_tweak_modal(): + return [ + ("CANCEL", {"type": 'ESC', "value": 'PRESS', "any": True}, None), + ("CANCEL", {"type": 'RIGHTMOUSE', "value": 'PRESS', "any": True}, None), + ("CONFIRM", {"type": 'RET', "value": 'PRESS', "any": True}, None), + ("CONFIRM", {"type": 'NUMPAD_ENTER', "value": 'PRESS', "any": True}, None), + ("PRECISION_ON", {"type": 'RIGHT_SHIFT', "value": 'PRESS', "any": True}, None), + ("PRECISION_OFF", {"type": 'RIGHT_SHIFT', "value": 'RELEASE', "any": True}, None), + ("PRECISION_ON", {"type": 'LEFT_SHIFT', "value": 'PRESS', "any": True}, None), + ("PRECISION_OFF", {"type": 'LEFT_SHIFT', "value": 'RELEASE', "any": True}, None), + ("SNAP_ON", {"type": 'RIGHT_CTRL', "value": 'PRESS', "any": True}, None), + ("SNAP_OFF", {"type": 'RIGHT_CTRL', "value": 'RELEASE', "any": True}, None), + ("SNAP_ON", {"type": 'LEFT_CTRL', "value": 'PRESS', "any": True}, None), + ("SNAP_OFF", {"type": 'LEFT_CTRL', "value": 'RELEASE', "any": True}, None), + ] + +# Tool System Templates + +def _template_items_basic_tools(*, connected=False): + return [ + op_tool("builtin.select_box", {"type": 'Q', "value": 'PRESS'}), + op_tool("builtin.move", {"type": 'W', "value": 'PRESS'}), + op_tool("builtin.rotate", {"type": 'E', "value": 'PRESS'}), + op_tool("builtin.scale", {"type": 'R', "value": 'PRESS'}), + op_tool("builtin.scale_cage", {"type": 'R', "value": 'PRESS', "shift": True}), + op_tool("builtin.transform", {"type": 'T', "value": 'PRESS'}), + op_tool("builtin.measure", {"type": 'M', "value": 'PRESS'}), + ] + +def _template_items_tool_select(params, operator, cursor_operator): + return [(operator, {"type": 'LEFTMOUSE', "value": 'PRESS'}, None)] + + +def _template_items_tool_select_actions(operator, *, type, value): + kmi_args = {"type": type, "value": value} + return [ + (operator, kmi_args, None), + (operator, {**kmi_args, "shift": True}, + {"properties": [("mode", 'ADD')]}), + (operator, {**kmi_args, "ctrl": True}, + {"properties": [("mode", 'SUB')]}), + (operator, {**kmi_args, "shift": True, "ctrl": True}, + {"properties": [("mode", 'AND')]}), + ] + + +# This could have a more generic name, for now use for circle select. +def _template_items_tool_select_actions_simple(operator, *, type, value, properties=[]): + kmi_args = {"type": type, "value": value} + return [ + # Don't define 'SET' here, take from the tool options. + (operator, kmi_args, + {"properties": properties}), + (operator, {**kmi_args, "shift": True}, + {"properties": [*properties, ("mode", 'ADD')]}), + (operator, {**kmi_args, "ctrl": True}, + {"properties": [*properties, ("mode", 'SUB')]}), + ] + + +# ------------------------------------------------------------------------------ +# Window, Screen, Areas, Regions + +def km_window(params): + items = [] + keymap = ( + "Window", @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs