WM: check missing space-data & constraints in poll functions
Without this, menu search prints many errors in some contexts.
This commit is contained in:
parent
eaf3160f13
commit
4402c3006b
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue