[Bf-blender-cvs] [4402c3006be] master: WM: check missing space-data & constraints in poll functions

Campbell Barton noreply at git.blender.org
Tue May 18 12:58:55 CEST 2021


Commit: 4402c3006be5bac4debcc121047175db27476ec9
Author: Campbell Barton
Date:   Tue May 18 20:00:51 2021 +1000
Branches: master
https://developer.blender.org/rB4402c3006be5bac4debcc121047175db27476ec9

WM: check missing space-data & constraints in poll functions

Without this, menu search prints many errors in some contexts.

===================================================================

M	release/scripts/modules/bpy_extras/asset_utils.py
M	release/scripts/startup/bl_operators/clip.py
M	release/scripts/startup/bl_operators/constraint.py
M	release/scripts/startup/bl_operators/node.py
M	release/scripts/startup/bl_operators/view3d.py

===================================================================

diff --git a/release/scripts/modules/bpy_extras/asset_utils.py b/release/scripts/modules/bpy_extras/asset_utils.py
index db982e119d4..1656c21a137 100644
--- a/release/scripts/modules/bpy_extras/asset_utils.py
+++ b/release/scripts/modules/bpy_extras/asset_utils.py
@@ -34,7 +34,7 @@ __all__ = (
 class SpaceAssetInfo:
     @classmethod
     def is_asset_browser(cls, space_data: bpy.types.Space):
-        return space_data.type == 'FILE_BROWSER' and space_data.browse_mode == 'ASSETS'
+        return space_data and space_data.type == 'FILE_BROWSER' and space_data.browse_mode == 'ASSETS'
 
     @classmethod
     def is_asset_browser_poll(cls, context: Context):
diff --git a/release/scripts/startup/bl_operators/clip.py b/release/scripts/startup/bl_operators/clip.py
index 0470f542c63..45d1ea98a8a 100644
--- a/release/scripts/startup/bl_operators/clip.py
+++ b/release/scripts/startup/bl_operators/clip.py
@@ -206,8 +206,8 @@ class CLIP_OT_filter_tracks(Operator):
 
     @classmethod
     def poll(cls, context):
-        space = context.space_data
-        return (space.type == 'CLIP_EDITOR') and space.clip
+        sc = context.space_data
+        return sc and (sc.type == 'CLIP_EDITOR') and sc.clip
 
     def execute(self, context):
         num_tracks = self._filter_values(context, self.track_threshold)
@@ -221,8 +221,8 @@ class CLIP_OT_set_active_clip(Operator):
 
     @classmethod
     def poll(cls, context):
-        space = context.space_data
-        return space.type == 'CLIP_EDITOR' and space.clip
+        sc = context.space_data
+        return sc and (sc.type == 'CLIP_EDITOR') and sc.clip
 
     def execute(self, context):
         clip = context.space_data.clip
@@ -268,8 +268,8 @@ class CLIP_OT_track_to_empty(Operator):
 
     @classmethod
     def poll(cls, context):
-        space = context.space_data
-        return space.type == 'CLIP_EDITOR' and space.clip
+        sc = context.space_data
+        return sc and (sc.type == 'CLIP_EDITOR') and sc.clip
 
     def execute(self, context):
         sc = context.space_data
@@ -293,7 +293,7 @@ class CLIP_OT_bundles_to_mesh(Operator):
     @classmethod
     def poll(cls, context):
         sc = context.space_data
-        return (sc.type == 'CLIP_EDITOR') and sc.clip
+        return sc and (sc.type == 'CLIP_EDITOR') and sc.clip
 
     def execute(self, context):
         from bpy_extras.io_utils import unpack_list
@@ -341,12 +341,8 @@ class CLIP_OT_delete_proxy(Operator):
 
     @classmethod
     def poll(cls, context):
-        if context.space_data.type != 'CLIP_EDITOR':
-            return False
-
         sc = context.space_data
-
-        return sc.clip
+        return sc and (sc.type == 'CLIP_EDITOR') and sc.clip
 
     def invoke(self, context, event):
         wm = context.window_manager
@@ -424,12 +420,8 @@ class CLIP_OT_set_viewport_background(Operator):
 
     @classmethod
     def poll(cls, context):
-        if context.space_data.type != 'CLIP_EDITOR':
-            return False
-
         sc = context.space_data
-
-        return sc.clip
+        return sc and (sc.type == 'CLIP_EDITOR') and sc.clip
 
     def execute(self, context):
         sc = context.space_data
@@ -563,13 +555,11 @@ class CLIP_OT_setup_tracking_scene(Operator):
     @classmethod
     def poll(cls, context):
         sc = context.space_data
-
-        if sc.type != 'CLIP_EDITOR':
-            return False
-
-        clip = sc.clip
-
-        return clip and clip.tracking.reconstruction.is_valid
+        if sc and sc.type == 'CLIP_EDITOR':
+            clip = sc.clip
+            if clip and clip.tracking.reconstruction.is_valid:
+                return True
+        return False
 
     @staticmethod
     def _setupScene(context):
@@ -1018,13 +1008,11 @@ class CLIP_OT_track_settings_as_default(Operator):
     @classmethod
     def poll(cls, context):
         sc = context.space_data
-
-        if sc.type != 'CLIP_EDITOR':
-            return False
-
-        clip = sc.clip
-
-        return clip and clip.tracking.tracks.active
+        if sc and sc.type == 'CLIP_EDITOR':
+            clip = sc.clip
+            if clip and clip.tracking.tracks.active:
+                return True
+        return False
 
     def execute(self, context):
         sc = context.space_data
@@ -1068,11 +1056,12 @@ class CLIP_OT_track_settings_to_track(Operator):
 
     @classmethod
     def poll(cls, context):
-        space = context.space_data
-        if space.type != 'CLIP_EDITOR':
-            return False
-        clip = space.clip
-        return clip and clip.tracking.tracks.active
+        sc = context.space_data
+        if sc and sc.type == 'CLIP_EDITOR':
+            clip = sc.clip
+            if clip and clip.tracking.tracks.active:
+                return True
+        return False
 
     def execute(self, context):
         space = context.space_data
diff --git a/release/scripts/startup/bl_operators/constraint.py b/release/scripts/startup/bl_operators/constraint.py
index 49fc6a04112..f18f3bb3a49 100644
--- a/release/scripts/startup/bl_operators/constraint.py
+++ b/release/scripts/startup/bl_operators/constraint.py
@@ -33,6 +33,11 @@ class CONSTRAINT_OT_add_target(Operator):
     bl_label = "Add Target"
     bl_options = {'UNDO', 'INTERNAL'}
 
+    @classmethod
+    def poll(cls, context):
+        constraint = getattr(context, "constraint", None)
+        return constraint
+
     def execute(self, context):
         context.constraint.targets.new()
         return {'FINISHED'}
@@ -46,6 +51,11 @@ class CONSTRAINT_OT_remove_target(Operator):
 
     index: IntProperty()
 
+    @classmethod
+    def poll(cls, context):
+        constraint = getattr(context, "constraint", None)
+        return constraint
+
     def execute(self, context):
         tgts = context.constraint.targets
         tgts.remove(tgts[self.index])
@@ -58,6 +68,11 @@ class CONSTRAINT_OT_normalize_target_weights(Operator):
     bl_label = "Normalize Weights"
     bl_options = {'UNDO', 'INTERNAL'}
 
+    @classmethod
+    def poll(cls, context):
+        constraint = getattr(context, "constraint", None)
+        return constraint
+
     def execute(self, context):
         tgts = context.constraint.targets
         total = sum(t.weight for t in tgts)
diff --git a/release/scripts/startup/bl_operators/node.py b/release/scripts/startup/bl_operators/node.py
index e0d0fc1e145..6150789ea10 100644
--- a/release/scripts/startup/bl_operators/node.py
+++ b/release/scripts/startup/bl_operators/node.py
@@ -120,7 +120,7 @@ class NodeAddOperator:
     def poll(cls, context):
         space = context.space_data
         # needs active node editor and a tree to add nodes to
-        return ((space.type == 'NODE_EDITOR') and
+        return (space and (space.type == 'NODE_EDITOR') and
                 space.edit_tree and not space.edit_tree.library)
 
     # Default execute simply adds a node
@@ -265,7 +265,7 @@ class NODE_OT_collapse_hide_unused_toggle(Operator):
     def poll(cls, context):
         space = context.space_data
         # needs active node editor and a tree
-        return ((space.type == 'NODE_EDITOR') and
+        return (space and (space.type == 'NODE_EDITOR') and
                 (space.edit_tree and not space.edit_tree.library))
 
     def execute(self, context):
@@ -296,7 +296,7 @@ class NODE_OT_tree_path_parent(Operator):
     def poll(cls, context):
         space = context.space_data
         # needs active node editor and a tree
-        return (space.type == 'NODE_EDITOR' and len(space.path) > 1)
+        return (space and (space.type == 'NODE_EDITOR') and len(space.path) > 1)
 
     def execute(self, context):
         space = context.space_data
@@ -315,6 +315,8 @@ class NODE_OT_active_preview_toggle(Operator):
     @classmethod
     def poll(cls, context):
         space = context.space_data
+        if space is None:
+            return False
         if space.type != 'NODE_EDITOR':
             return False
         if space.edit_tree is None:
diff --git a/release/scripts/startup/bl_operators/view3d.py b/release/scripts/startup/bl_operators/view3d.py
index ff5bcdb034f..0fa82e36d20 100644
--- a/release/scripts/startup/bl_operators/view3d.py
+++ b/release/scripts/startup/bl_operators/view3d.py
@@ -208,7 +208,8 @@ class VIEW3D_OT_transform_gizmo_set(Operator):
 
     @classmethod
     def poll(cls, context):
-        return context.area.type == 'VIEW_3D'
+        area = context.area
+        return area and (area.type == 'VIEW_3D')
 
     def execute(self, context):
         space_data = context.space_data



More information about the Bf-blender-cvs mailing list