18N for tools definitions: make them resilient to None context.
[blender.git] / release / scripts / startup / bl_ui / space_toolsystem_toolbar.py
index 90a2518..42953a0 100644 (file)
@@ -32,6 +32,12 @@ from .space_toolsystem_common import (
     ToolDef,
 )
 
+from bpy.app.translations import pgettext_iface as iface_
+from bpy.app.translations import pgettext_tip as tip_
+
+
+I18N_CTX_OPERATOR = bpy.app.translations.contexts_C_to_py['BLT_I18NCONTEXT_OPERATOR_DEFAULT']
+
 
 def kmi_to_string_or_none(kmi):
     return kmi.to_string() if kmi else "<none>"
@@ -116,12 +122,14 @@ class _defs_view3d_generic:
                 kmi_add = None
                 kmi_remove = None
             return (
+                tip_(
                 "Measure distance and angles.\n"
                 "\u2022 {} anywhere for new measurement.\n"
                 "\u2022 Drag ruler segment to measure an angle.\n"
                 "\u2022 {} to remove the active ruler.\n"
                 "\u2022 Ctrl while dragging to snap.\n"
                 "\u2022 Shift while dragging to measure surface thickness."
+                )
             ).format(
                 kmi_to_string_or_none(kmi_add),
                 kmi_to_string_or_none(kmi_remove),
@@ -973,6 +981,8 @@ class _defs_vertex_paint:
 
     @staticmethod
     def poll_select_mask(context):
+        if context is None:
+            return True
         ob = context.active_object
         return (ob.type == 'MESH' and
                 (ob.data.use_paint_mask or
@@ -993,6 +1003,8 @@ class _defs_texture_paint:
 
     @staticmethod
     def poll_select_mask(context):
+        if context is None:
+            return True
         ob = context.active_object
         return (ob.type == 'MESH' and
                 (ob.data.use_paint_mask))
@@ -1012,6 +1024,8 @@ class _defs_weight_paint:
 
     @staticmethod
     def poll_select_mask(context):
+        if context is None:
+            return True
         ob = context.active_object
         return (ob.type == 'MESH' and
                 (ob.data.use_paint_mask or
@@ -1072,6 +1086,8 @@ class _defs_image_generic:
 
     @staticmethod
     def poll_uvedit(context):
+        if context is None:
+            return True
         ob = context.edit_object
         if ob is not None:
             data = ob.data
@@ -1870,7 +1886,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
             None,
             lambda context: (
                 (_defs_view3d_generic.cursor,)
-                if context.pose_object
+                if context is None or context.pose_object
                 else ()
             ),
             None,