diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-04-26 08:31:39 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-04-26 08:31:39 +0300 |
commit | 37ca6ef7d86c78c135b1bdbc468bf6c04ce63994 (patch) | |
tree | d758a545d2d36530f1a68b1d8a428c4dd3af77ba | |
parent | db68166ed82b51e7d437778dcdb4b6fbe09f5cd9 (diff) |
UI: use dict for tool definitions
Using tuple was becoming too cryptic - new settings needed to be added
last and the purpose of each wasn't very clear.
-rw-r--r-- | release/scripts/startup/bl_ui/space_toolsystem_common.py | 17 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_toolsystem_toolbar.py | 410 |
2 files changed, 306 insertions, 121 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index ae00f3675a0..4b0577729bd 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -81,7 +81,7 @@ class ToolSelectPanelHelper: @staticmethod def _tool_is_group(tool): - return type(tool[0]) is not str + return type(tool) is not dict @staticmethod def _tools_flatten(tools): @@ -96,7 +96,10 @@ class ToolSelectPanelHelper: @classmethod def _tool_vars_from_def(cls, item): - text, icon_name, mp_idname, actions = item + text = item["text"] + icon_name = item["icon"] + mp_idname = item["widget"] + actions = item["keymap"] km, km_idname = (None, None) if actions is None else cls._tool_keymap[text] return (km_idname, mp_idname), icon_name @@ -163,8 +166,10 @@ class ToolSelectPanelHelper: return for item in ToolSelectPanelHelper._tools_flatten(cls.tools_all()): - text, icon_name, mp_idname, actions = item + actions = item["keymap"] if actions is not None: + text = item["text"] + icon_name = item["icon"] km, km_idname = cls._km_actionmouse_simple(kc, text, icon_name, actions) cls._tool_keymap[text] = km, km_idname @@ -215,9 +220,9 @@ class ToolSelectPanelHelper: if is_active: # not ideal, write this every time :S - self._tool_group_active[item[0][0]] = index + self._tool_group_active[item[0]["text"]] = index else: - index = self._tool_group_active.get(item[0][0], 0) + index = self._tool_group_active.get(item[0]["text"], 0) item = item[index] use_menu = True @@ -299,7 +304,7 @@ class WM_MT_toolsystem_submenu(Menu): icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(icon_name) props = layout.operator( "wm.tool_set", - text=item[0], + text=item["text"], icon_value=icon_value, ) props.keymap = tool_def[0] or "" diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py index 34a757ad161..8cffc49b68e 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -53,18 +53,47 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): # for reuse _tools_transform = ( - ("Translate", "ops.transform.translate", "TRANSFORM_WGT_manipulator", - (("transform.translate", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')),)), - ("Rotate", "ops.transform.rotate", "TRANSFORM_WGT_manipulator", - (("transform.rotate", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')),)), + dict( + text="Translate", + icon="ops.transform.translate", + widget="TRANSFORM_WGT_manipulator", + keymap=( + ("transform.translate", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')), + ), + ), + dict( + text="Rotate", + icon="ops.transform.rotate", + widget="TRANSFORM_WGT_manipulator", + keymap=( + ("transform.rotate", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')), + ), + ), ( - ("Scale", "ops.transform.resize", "TRANSFORM_WGT_manipulator", - (("transform.resize", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')),)), - ("Scale Cage", "ops.transform.resize.cage", "VIEW3D_WGT_xform_cage", None), + dict( + text="Scale", + icon="ops.transform.resize", + widget="TRANSFORM_WGT_manipulator", + keymap=( + ("transform.resize", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')), + ), + ), + dict( + text="Scale Cage", + icon="ops.transform.resize.cage", + widget="VIEW3D_WGT_xform_cage", + keymap=None, + ), ), None, - ("Ruler/Protractor", "ops.view3d.ruler", "VIEW3D_WGT_ruler", - (("view3d.ruler_add", dict(), dict(type='EVT_TWEAK_A', value='ANY')),)), + dict( + text="Ruler/Protractor", + icon="ops.view3d.ruler", + widget="VIEW3D_WGT_ruler", + keymap=( + ("view3d.ruler_add", dict(), dict(type='EVT_TWEAK_A', value='ANY')), + ), + ), # DEBUGGING ONLY # ("Pixel Test", "tool_icon.pixeltest", None, (("wm.splash", dict(), dict(type='ACTIONMOUSE', value='PRESS')),)), @@ -72,25 +101,56 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): _tools = { None: [ - ("Cursor", "ops.generic.cursor", None, - (("view3d.cursor3d", dict(), dict(type='ACTIONMOUSE', value='CLICK')),)), + dict( + text="Cursor", + icon="ops.generic.cursor", + widget=None, + keymap=( + ("view3d.cursor3d", dict(), dict(type='ACTIONMOUSE', value='CLICK')), + ), + ), # 'Select' Group ( - ("Select Border", "ops.generic.select_border", None, ( - ("view3d.select_border", dict(deselect=False), dict(type='EVT_TWEAK_A', value='ANY')), - ("view3d.select_border", dict(deselect=True), dict(type='EVT_TWEAK_A', value='ANY', ctrl=True)), - )), - ("Select Circle", "ops.generic.select_circle", None, ( - ("view3d.select_circle", dict(deselect=False), dict(type='ACTIONMOUSE', value='PRESS')), - ("view3d.select_circle", dict(deselect=True), dict(type='ACTIONMOUSE', value='PRESS', ctrl=True)), - )), - ("Select Lasso", "ops.generic.select_lasso", None, ( - ("view3d.select_lasso", - dict(deselect=False), dict(type='EVT_TWEAK_A', value='ANY')), - ("view3d.select_lasso", - dict(deselect=True), dict(type='EVT_TWEAK_A', value='ANY', ctrl=True)), - )), + dict( + text="Select Border", + icon="ops.generic.select_border", + widget=None, + keymap=( + ("view3d.select_border", + dict(deselect=False), + dict(type='EVT_TWEAK_A', value='ANY')), + ("view3d.select_border", + dict(deselect=True), + dict(type='EVT_TWEAK_A', value='ANY', ctrl=True)), + ), + ), + dict( + text="Select Circle", + icon="ops.generic.select_circle", + widget=None, + keymap=( + ("view3d.select_circle", + dict(deselect=False), + dict(type='ACTIONMOUSE', value='PRESS')), + ("view3d.select_circle", + dict(deselect=True), + dict(type='ACTIONMOUSE', value='PRESS', ctrl=True)), + ), + ), + dict( + text="Select Lasso", + icon="ops.generic.select_lasso", + widget=None, + keymap=( + ("view3d.select_lasso", + dict(deselect=False), + dict(type='EVT_TWEAK_A', value='ANY')), + ("view3d.select_lasso", + dict(deselect=True), + dict(type='EVT_TWEAK_A', value='ANY', ctrl=True)), + ), + ), ), # End group. ], @@ -103,140 +163,260 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): 'PAINT_WEIGHT': [ # TODO, override brush events ( - ("Linear Gradient", None, None, ( - ("paint.weight_gradient", dict(type='LINEAR'), - dict(type='EVT_TWEAK_A', value='ANY')), - )), - ("Radial Gradient", None, None, ( - ("paint.weight_gradient", dict(type='RADIAL'), - dict(type='EVT_TWEAK_A', value='ANY')), - )), + dict( + text="Linear Gradient", + icon=None, + widget=None, + keymap=( + ("paint.weight_gradient", dict(type='LINEAR'), + dict(type='EVT_TWEAK_A', value='ANY')), + ), + ), + dict( + text="Radial Gradient", + icon=None, + widget=None, + keymap=( + ("paint.weight_gradient", + dict(type='RADIAL'), + dict(type='EVT_TWEAK_A', value='ANY')), + ), + ), ), ], 'EDIT_ARMATURE': [ *_tools_transform, - ("Roll", None, None, ( - ("transform.transform", - dict(release_confirm=True, mode='BONE_ROLL'), - dict(type='EVT_TWEAK_A', value='ANY')), - )), + dict( + text="Roll", + icon=None, + widget=None, + keymap=( + ("transform.transform", + dict(release_confirm=True, mode='BONE_ROLL'), + dict(type='EVT_TWEAK_A', value='ANY'),), + ), + ), None, - ("Extrude Cursor", "ops.armature.extrude", None, - (("armature.click_extrude", dict(), dict(type='ACTIONMOUSE', value='PRESS')),)), + dict( + text="Extrude Cursor", + icon="ops.armature.extrude", + widget=None, + keymap=( + ("armature.click_extrude", dict(), dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), ], 'EDIT_MESH': [ *_tools_transform, None, ( - ("Rip Region", "ops.mesh.rip", None, ( - ("mesh.rip_move", dict(), - dict(type='ACTIONMOUSE', value='PRESS')), - )), - ("Rip Edge", "ops.mesh.rip_edge", None, ( - ("mesh.rip_edge_edge_move", dict(), - dict(type='ACTIONMOUSE', value='PRESS')), - )), + dict( + text="Rip Region", + icon="ops.mesh.rip", + widget=None, + keymap=( + ("mesh.rip_move", dict(), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), + dict( + text="Rip Edge", + icon="ops.mesh.rip_edge", + widget=None, + keymap=( + ("mesh.rip_edge_edge_move", dict(), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), ), - ("Poly Build", "ops.mesh.polybuild_hover", None, ( - ("mesh.polybuild_face_at_cursor_move", - dict(TRANSFORM_OT_translate=dict(release_confirm=True)), - dict(type='ACTIONMOUSE', value='PRESS')), - ("mesh.polybuild_split_at_cursor_move", - dict(TRANSFORM_OT_translate=dict(release_confirm=True)), - dict(type='ACTIONMOUSE', value='PRESS', ctrl=True)), - ("mesh.polybuild_dissolve_at_cursor", dict(), dict(type='ACTIONMOUSE', value='CLICK', alt=True)), - ("mesh.polybuild_hover", dict(use_boundary=False), dict(type='MOUSEMOVE', value='ANY', alt=True)), - ("mesh.polybuild_hover", dict(use_boundary=True), dict(type='MOUSEMOVE', value='ANY', any=True)), - )), + dict( + text="Poly Build", + icon="ops.mesh.polybuild_hover", + widget=None, + keymap=( + ("mesh.polybuild_face_at_cursor_move", + dict(TRANSFORM_OT_translate=dict(release_confirm=True)), + dict(type='ACTIONMOUSE', value='PRESS')), + ("mesh.polybuild_split_at_cursor_move", + dict(TRANSFORM_OT_translate=dict(release_confirm=True)), + dict(type='ACTIONMOUSE', value='PRESS', ctrl=True)), + ("mesh.polybuild_dissolve_at_cursor", dict(), dict(type='ACTIONMOUSE', value='CLICK', alt=True)), + ("mesh.polybuild_hover", dict(use_boundary=False), dict(type='MOUSEMOVE', value='ANY', alt=True)), + ("mesh.polybuild_hover", dict(use_boundary=True), dict(type='MOUSEMOVE', value='ANY', any=True)), + ), + ), # 'Slide' Group ( - ("Edge Slide", "ops.transform.edge_slide", None, ( - ("transform.edge_slide", dict(release_confirm=True), - dict(type='ACTIONMOUSE', value='PRESS')), - )), - ("Vertex Slide", "ops.transform.edge_slide", None, ( - ("transform.vert_slide", dict(release_confirm=True), - dict(type='ACTIONMOUSE', value='PRESS')), - )), + dict( + text="Edge Slide", + icon="ops.transform.edge_slide", + widget=None, + keymap=( + ("transform.edge_slide", dict(release_confirm=True), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), + dict( + text="Vertex Slide", + icon="ops.transform.edge_slide", + widget=None, + keymap=( + ("transform.vert_slide", dict(release_confirm=True), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), ), # End group. ( - ("Spin", "ops.mesh.spin", None, ( + dict( + text="Spin", + icon="ops.mesh.spin", + widget=None, + keymap=( ("mesh.spin", dict(), dict(type='ACTIONMOUSE', value='PRESS')), - )), - ("Spin (Duplicate)", "ops.mesh.spin.duplicate", None, ( - ("mesh.spin", dict(dupli=True), - dict(type='ACTIONMOUSE', value='PRESS')), - )), + ), + ), + dict( + text="Spin (Duplicate)", + icon="ops.mesh.spin.duplicate", + widget=None, + keymap=( + ("mesh.spin", dict(dupli=True), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), ), - ("Inset Faces", "ops.mesh.inset", None, ( - ("mesh.inset", dict(), - dict(type='ACTIONMOUSE', value='PRESS')), - )), + dict( + text="Inset Faces", + icon="ops.mesh.inset", + widget=None, + keymap=( + ("mesh.inset", dict(), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), ( - ("Extrude Region", "ops.view3d.edit_mesh_extrude", None, ( - ("view3d.edit_mesh_extrude", dict(), - dict(type='ACTIONMOUSE', value='PRESS')), - )), - ("Extrude Individual", "ops.view3d.edit_mesh_extrude_individual", None, ( - ("mesh.extrude_faces_move", dict(), - dict(type='ACTIONMOUSE', value='PRESS')), - )), + dict( + text="Extrude Region", + icon="ops.view3d.edit_mesh_extrude", + widget=None, + keymap=( + ("view3d.edit_mesh_extrude", dict(), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), + dict( + text="Extrude Individual", + icon="ops.view3d.edit_mesh_extrude_individual", + widget=None, + keymap=( + ("mesh.extrude_faces_move", dict(), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), ), ( - ("Randomize", "ops.transform.vertex_random", None, ( - ("transform.vertex_random", dict(), - dict(type='ACTIONMOUSE', value='PRESS')), - )), - ("Smooth", "ops.mesh.vertices_smooth", None, ( - ("mesh.vertices_smooth", dict(), - dict(type='ACTIONMOUSE', value='PRESS')), - )), + dict( + text="Randomize", + icon="ops.transform.vertex_random", + widget=None, + keymap=( + ("transform.vertex_random", dict(), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), + dict( + text="Smooth", + icon="ops.mesh.vertices_smooth", + widget=None, + keymap=( + ("mesh.vertices_smooth", dict(), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), ), ( - ("Shrink/Fatten", "ops.transform.shrink_fatten", None, ( - ("transform.shrink_fatten", dict(release_confirm=True), - dict(type='ACTIONMOUSE', value='PRESS')), - )), - ("Push/Pull", "ops.transform.push_pull", None, ( - ("transform.push_pull", dict(release_confirm=True), - dict(type='ACTIONMOUSE', value='PRESS')), - )), + dict( + text="Shrink/Fatten", + icon="ops.transform.shrink_fatten", + widget=None, + keymap=( + ("transform.shrink_fatten", dict(release_confirm=True), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), + dict( + text="Push/Pull", + icon="ops.transform.push_pull", + widget=None, + keymap=( + ("transform.push_pull", dict(release_confirm=True), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), ), # Knife Group ( - ("Knife", "ops.mesh.knife_tool", None, ( - ("mesh.knife_tool", - dict(wait_for_input=False, use_occlude_geometry=True, only_selected=False), - dict(type='ACTIONMOUSE', value='PRESS')),)), + dict( + text="Knife", + icon="ops.mesh.knife_tool", + widget=None, + keymap=( + ("mesh.knife_tool", + dict(wait_for_input=False, use_occlude_geometry=True, only_selected=False), + dict(type='ACTIONMOUSE', value='PRESS')),), + ), None, - ("Bisect", "ops.mesh.bisect", None, ( - ("mesh.bisect", - dict(), - dict(type='EVT_TWEAK_A', value='ANY')),)), + dict( + text="Bisect", + icon="ops.mesh.bisect", + widget=None, + keymap=( + ("mesh.bisect", + dict(), + dict(type='EVT_TWEAK_A', value='ANY')),), + ), ), # End group. - ("Extrude Cursor", None, None, - (("mesh.dupli_extrude_cursor", dict(), dict(type='ACTIONMOUSE', value='PRESS')),)), + dict( + text="Extrude Cursor", + icon=None, + widget=None, + keymap=( + ("mesh.dupli_extrude_cursor", dict(), dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), ], 'EDIT_CURVE': [ *_tools_transform, None, - ("Draw", None, None, - (("curve.draw", dict(wait_for_input=False), dict(type='ACTIONMOUSE', value='PRESS')),)), - ("Extrude Cursor", None, None, - (("curve.vertex_add", dict(), dict(type='ACTIONMOUSE', value='PRESS')),)), + dict( + text="Draw", + icon=None, + widget=None, + keymap=( + ("curve.draw", dict(wait_for_input=False), dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), + dict( + text="Extrude Cursor", + icon=None, + widget=None, + keymap=( + ("curve.vertex_add", dict(), dict(type='ACTIONMOUSE', value='PRESS')), + ), + ), ], } |