From 1dfa23bade1bc5d0584c1231e7636e1dd96b164c Mon Sep 17 00:00:00 2001 From: Brady Johnston Date: Mon, 13 Jan 2025 11:22:03 +0800 Subject: [PATCH] fixes menu generation --- molecularnodes/operators/node_add_buttons.py | 9 +++++++++ molecularnodes/ui/menu.py | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/molecularnodes/operators/node_add_buttons.py b/molecularnodes/operators/node_add_buttons.py index 479d367b..69cac00a 100644 --- a/molecularnodes/operators/node_add_buttons.py +++ b/molecularnodes/operators/node_add_buttons.py @@ -96,6 +96,8 @@ def poll(self, context): # is associated with the object / molecule. If there isn't then the assembly # operator will be greyed out and unable to be executed obj = context.active_object + if obj is None: + return False return obj.mn.biological_assemblies != "" def execute(self, context): @@ -135,6 +137,13 @@ class MN_OT_iswitch_custom(Operator): node_name: StringProperty(name="node_name", default="chain") # type: ignore starting_value: IntProperty(name="starting_value", default=0) # type: ignore + @classmethod + def poll(cls, context: Context) -> bool: + obj = context.active_object + if obj is None: + return False + return True + @classmethod def description(cls, context, properties): return properties.description diff --git a/molecularnodes/ui/menu.py b/molecularnodes/ui/menu.py index a20c63b0..72e84de6 100644 --- a/molecularnodes/ui/menu.py +++ b/molecularnodes/ui/menu.py @@ -127,7 +127,11 @@ def menu( else: raise ValueError(f"Data type currently not supported: {self.dtype}") # test if the object has the currently tested property to enable operator - row.enabled = bool(context.active_object.get(self.property_id)) + obj = context.active_object + if obj is None: + row.enabled = False + else: + row.enabled = bool(obj.get(self.property_id)) class Break: