Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-06-24 18:06:09 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-06-24 18:08:13 +0300
commit4fcc3b8ba20f34ba92f9ad90463502c96426df2e (patch)
tree75e0cb53c0d443d6c0fbe46c116f45b8f6d4d2ad /release/scripts/startup/bl_ui/space_toolsystem_common.py
parentd61a9b297b7f7851f4a4a88e02b3ce2eff812bd2 (diff)
WM: add operator to set the tool by it's index
Needed for 2.7x brush switching keys.
Diffstat (limited to 'release/scripts/startup/bl_ui/space_toolsystem_common.py')
-rw-r--r--release/scripts/startup/bl_ui/space_toolsystem_common.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index 1d401ebd2c9..e7e95c26b55 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -296,6 +296,45 @@ class ToolSelectPanelHelper:
return None, None, -1
@staticmethod
+ def _tool_get_by_flat_index(context, space_type, tool_index):
+ """
+ Return the active Python tool definition and index (if in sub-group, else -1).
+
+ Return the index of the expanded list.
+ """
+ cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type)
+ if cls is not None:
+ i = 0
+ for item, index in ToolSelectPanelHelper._tools_flatten_with_tool_index(cls.tools_from_context(context)):
+ if item is not None:
+ if i == tool_index:
+ return (cls, item, index)
+ i += 1
+ return None, None, -1
+
+ @staticmethod
+ def _tool_get_by_index(context, space_type, tool_index):
+ """
+ Return the active Python tool definition and index (if in sub-group, else -1).
+
+ Return the index of the list without expanding.
+ """
+ cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type)
+ if cls is not None:
+ i = 0
+ for item in cls.tools_from_context(context):
+ if item is not None:
+ if i == tool_index:
+ if type(item) is tuple:
+ index = cls._tool_group_active.get(item[0].idname, 0)
+ item = item[index]
+ else:
+ index = -1
+ return (cls, item, index)
+ i += 1
+ return None, None, -1
+
+ @staticmethod
def _tool_active_from_context(context, space_type, mode=None, create=False):
if space_type == 'VIEW_3D':
if mode is None:
@@ -772,6 +811,16 @@ def item_from_id(context, space_type, idname):
return item
+def item_from_flat_index(context, space_type, index):
+ _cls, item, _index = ToolSelectPanelHelper._tool_get_by_flat_index(context, space_type, index)
+ return item
+
+
+def item_from_index(context, space_type, index):
+ _cls, item, _index = ToolSelectPanelHelper._tool_get_by_index(context, space_type, index)
+ return item
+
+
def keymap_from_id(context, space_type, idname):
# Used directly for tooltips.
_cls, item, _index = ToolSelectPanelHelper._tool_get_by_id(context, space_type, idname)