diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-04-24 10:19:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-04-24 10:19:28 +0300 |
commit | 3581b997d4793e8fd9ad7be7722b01edb2d75287 (patch) | |
tree | f7ebc91cce9d508aea5aa695531d37f368c21a59 /release/scripts | |
parent | 4b544e857c94118ff3957d7fa15758507fd94181 (diff) |
UI: use icons for the toolbar
Diffstat (limited to 'release/scripts')
-rw-r--r-- | release/scripts/startup/bl_ui/space_toolsystem_common.py | 55 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_toolsystem_toolbar.py | 44 |
2 files changed, 68 insertions, 31 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index aff9a8d6170..db35ab27506 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -27,6 +27,9 @@ __all__ = ( ) +# (filename -> icon_value) map +_icon_cache = {} + class ToolSelectPanelHelper: """ Generic Class, can be used for any toolbar. @@ -52,6 +55,28 @@ class ToolSelectPanelHelper: """ @staticmethod + def _icon_value_from_icon_handle(icon_name): + import os + if icon_name is not None: + assert(type(icon_name) is str) + icon_value = _icon_cache.get(icon_name) + if icon_value is None: + dirname = bpy.utils.resource_path('SYSTEM') + filename = os.path.join(dirname, "datafiles", "icons", icon_name + ".dat") + try: + icon_value = bpy.app.icons.new_triangles_from_file(filename) + except Exception as ex: + if os.path.exists(filename): + print("Missing icons:", filename, ex) + else: + print("Corrupt icon:", filename, ex) + icon_value = 0 + _icon_cache[icon_name] = icon_value + return icon_value + else: + return 0 + + @staticmethod def _tool_is_group(tool): return type(tool[0]) is not str @@ -68,9 +93,9 @@ class ToolSelectPanelHelper: @classmethod def _tool_vars_from_def(cls, item): - text, mp_idname, actions = item + text, icon_name, mp_idname, actions = item km, km_idname = (None, None) if actions is None else cls._tool_keymap[text] - return (km_idname, mp_idname) + return (km_idname, mp_idname), icon_name @staticmethod def _tool_vars_from_active_with_index(context): @@ -89,7 +114,7 @@ class ToolSelectPanelHelper: ) @classmethod - def _km_actionmouse_simple(cls, kc, text, actions): + def _km_actionmouse_simple(cls, kc, text, icon_name, actions): # standalone def props_assign_recursive(rna_props, py_props): @@ -135,9 +160,9 @@ class ToolSelectPanelHelper: return for item in ToolSelectPanelHelper._tools_flatten(cls.tools_all()): - text, mp_idname, actions = item + text, icon_name, mp_idname, actions = item if actions is not None: - km, km_idname = cls._km_actionmouse_simple(kc, text, actions) + km, km_idname = cls._km_actionmouse_simple(kc, text, icon_name, actions) cls._tool_keymap[text] = km, km_idname def draw(self, context): @@ -151,12 +176,16 @@ class ToolSelectPanelHelper: tool_def_active, index_active = self._tool_vars_from_active_with_index(context) layout = self.layout + scale_y = 2.0 + for tool_items in self.tools_from_context(context): if tool_items: col = layout.column(align=True) + col.scale_y = scale_y for item in tool_items: if item is None: col = layout.column(align=True) + col.scale_y = scale_y continue if self._tool_is_group(item): @@ -165,7 +194,7 @@ class ToolSelectPanelHelper: for i, sub_item in enumerate(item): if sub_item is None: continue - tool_def = self._tool_vars_from_def(sub_item) + tool_def, icon_name = self._tool_vars_from_def(sub_item) is_active = (tool_def == tool_def_active) if is_active: index = i @@ -184,21 +213,23 @@ class ToolSelectPanelHelper: index = -1 use_menu = False - tool_def = self._tool_vars_from_def(item) + tool_def, icon_name = self._tool_vars_from_def(item) is_active = (tool_def == tool_def_active) - + icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(icon_name) if use_menu: props = col.operator_menu_hold( "wm.tool_set", text=item[0], depress=is_active, menu="WM_MT_toolsystem_submenu", + icon_value=icon_value, ) else: props = col.operator( "wm.tool_set", text=item[0], depress=is_active, + icon_value=icon_value, ) props.keymap = tool_def[0] or "" @@ -231,7 +262,7 @@ class WM_MT_toolsystem_submenu(Menu): if (item_group is not None) and ToolSelectPanelHelper._tool_is_group(item_group): if index_button < len(item_group): item = item_group[index_button] - tool_def = cls._tool_vars_from_def(item) + tool_def, icon_name = cls._tool_vars_from_def(item) is_active = (tool_def == tool_def_button) if is_active: return cls, item_group, index_button @@ -239,6 +270,8 @@ class WM_MT_toolsystem_submenu(Menu): def draw(self, context): layout = self.layout + layout.scale_y = 2.0 + cls, item_group, index_active = self._tool_group_from_button(context) if item_group is None: # Should never happen, just in case @@ -250,10 +283,12 @@ class WM_MT_toolsystem_submenu(Menu): if item is None: layout.separator() continue - tool_def = cls._tool_vars_from_def(item) + tool_def, icon_name = cls._tool_vars_from_def(item) + icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(icon_name) props = layout.operator( "wm.tool_set", text=item[0], + icon_value=icon_value, ) props.keymap = tool_def[0] or "" props.manipulator_group = tool_def[1] or "" diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py index d08c7cd8815..77708a3ee5c 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -53,34 +53,36 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): # for reuse _tools_transform = ( - ("Translate", "TRANSFORM_WGT_manipulator", + ("Translate", "ops.transform.translate", "TRANSFORM_WGT_manipulator", (("transform.translate", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')),)), - ("Rotate", "TRANSFORM_WGT_manipulator", + ("Rotate", "ops.transform.rotate", "TRANSFORM_WGT_manipulator", (("transform.rotate", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')),)), - ("Scale", "TRANSFORM_WGT_manipulator", - (("transform.resize", dict(release_confirm=True), dict(type='EVT_TWEAK_A', value='ANY')),)), - ("Scale Cage", "VIEW3D_WGT_xform_cage", None), + ( + ("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), + ), None, - ("Ruler/Protractor", "VIEW3D_WGT_ruler", + ("Ruler/Protractor", None, "VIEW3D_WGT_ruler", (("view3d.ruler_add", dict(), dict(type='EVT_TWEAK_A', value='ANY')),)), ) _tools = { None: [ - ("Cursor", None, + ("Cursor", "ops.generic.cursor", None, (("view3d.cursor3d", dict(), dict(type='ACTIONMOUSE', value='CLICK')),)), # 'Select' Group ( - ("Select Border", None, ( + ("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", None, ( + ("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", None, ( + ("Select Lasso", "ops.generic.select_lasso", None, ( ("view3d.select_lasso", dict(deselect=False), dict(type='EVT_TWEAK_A', value='ANY')), ("view3d.select_lasso", @@ -97,28 +99,28 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): ], 'EDIT_ARMATURE': [ *_tools_transform, - ("Roll", None, ( + ("Roll", None, None, ( ("transform.transform", dict(release_confirm=True, mode='BONE_ROLL'), dict(type='EVT_TWEAK_A', value='ANY')), )), None, - ("Extrude Cursor", None, + ("Extrude Cursor", None, None, (("armature.click_extrude", dict(), dict(type='ACTIONMOUSE', value='PRESS')),)), ], 'EDIT_MESH': [ *_tools_transform, None, - ("Rip Region", None, ( + ("Rip Region", None, None, ( ("mesh.rip_move", dict(TRANSFORM_OT_translate=dict(release_confirm=True)), dict(type='ACTIONMOUSE', value='PRESS')), )), - ("Rip Edge", None, ( + ("Rip Edge", None, None, ( ("mesh.rip_edge_move", dict(TRANSFORM_OT_translate=dict(release_confirm=True)), dict(type='ACTIONMOUSE', value='PRESS')), )), - ("Poly Build", None, ( + ("Poly Build", None, None, ( ("mesh.polybuild_face_at_cursor_move", dict(TRANSFORM_OT_translate=dict(release_confirm=True)), dict(type='ACTIONMOUSE', value='PRESS')), @@ -132,30 +134,30 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): # Knife Group ( - ("Knife", None, ( + ("Knife", None, None, ( ("mesh.knife_tool", dict(wait_for_input=False, use_occlude_geometry=True, only_selected=False), dict(type='ACTIONMOUSE', value='PRESS')),)), - ("Knife (Selected)", None, ( + ("Knife (Selected)", None, None, ( ("mesh.knife_tool", dict(wait_for_input=False, use_occlude_geometry=False, only_selected=True), dict(type='ACTIONMOUSE', value='PRESS')),)), None, - ("Bisect", None, ( + ("Bisect", None, None, ( ("mesh.bisect", dict(), dict(type='EVT_TWEAK_A', value='ANY')),)), ), # End group. - ("Extrude Cursor", None, + ("Extrude Cursor", None, None, (("mesh.dupli_extrude_cursor", dict(), dict(type='ACTIONMOUSE', value='PRESS')),)), ], 'EDIT_CURVE': [ *_tools_transform, None, - ("Draw", None, + ("Draw", None, None, (("curve.draw", dict(wait_for_input=False), dict(type='ACTIONMOUSE', value='PRESS')),)), - ("Extrude Cursor", None, + ("Extrude Cursor", None, None, (("curve.vertex_add", dict(), dict(type='ACTIONMOUSE', value='PRESS')),)), ], } |