fix: Run `active_kind` updator after socket init.

Without propagation, of course; this ensures that the display shape is correctly set.

Closes #2.
main
Sofus Albert Høgsbro Rose 2024-05-04 16:02:50 +02:00
parent 3c00530524
commit ea8e4104ff
Signed by: so-rose
GPG Key ID: AD901CB0F3701434
1 changed files with 11 additions and 13 deletions

View File

@ -45,6 +45,7 @@ class SocketDef(pyd.BaseModel, abc.ABC):
bl_socket: The Blender node socket to alter using data from this SocketDef. bl_socket: The Blender node socket to alter using data from this SocketDef.
""" """
bl_socket.initializing = False bl_socket.initializing = False
bl_socket.on_active_kind_changed()
@abc.abstractmethod @abc.abstractmethod
def init(self, bl_socket: bpy.types.NodeSocket) -> None: def init(self, bl_socket: bpy.types.NodeSocket) -> None:
@ -221,21 +222,18 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
#################### ####################
# - Property Event: On Update # - Property Event: On Update
#################### ####################
def _on_active_kind_changed(self) -> None: def on_active_kind_changed(self) -> None:
"""Matches the display shape to the active `FlowKind`. """Matches the display shape to the active `FlowKind`.
Notes: Notes:
Called by `self.on_prop_changed()` when `self.active_kind` was changed. Called by `self.on_prop_changed()` when `self.active_kind` was changed.
""" """
self.display_shape = ( self.display_shape = {
'SQUARE' ct.FlowKind.Value: 'CIRCLE',
if self.active_kind == ct.FlowKind.LazyArrayRange ct.FlowKind.Array: 'SQUARE',
else ('DIAMOND' if self.active_kind == ct.FlowKind.Array else 'CIRCLE') ct.FlowKind.LazyArrayRange: 'SQUARE',
) + ( ct.FlowKind.LazyValueFunc: 'DIAMOND',
'_DOT' }[self.active_kind]
if hasattr(self, 'physical_type') and self.physical_type is not None
else ''
)
def on_socket_prop_changed(self, prop_name: str) -> None: def on_socket_prop_changed(self, prop_name: str) -> None:
"""Called when a property has been updated. """Called when a property has been updated.
@ -243,8 +241,8 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
Notes: Notes:
Can be overridden if a socket needs to respond to a property change. Can be overridden if a socket needs to respond to a property change.
**Always prefer using node events when possible**. **Always prefer using node events instead of overriding this in a socket**.
Think very carefully before using this, and use it with the greatest of care. Think **very carefully** before using this, and use it with the greatest of care.
Attributes: Attributes:
prop_name: The name of the property that was changed. prop_name: The name of the property that was changed.
@ -274,7 +272,7 @@ class MaxwellSimSocket(bpy.types.NodeSocket):
# Property Callbacks: Active Kind # Property Callbacks: Active Kind
if prop_name == 'active_kind': if prop_name == 'active_kind':
self._on_active_kind_changed() self.on_active_kind_changed()
# Property Callbacks: Per-Socket # Property Callbacks: Per-Socket
self.on_socket_prop_changed(prop_name) self.on_socket_prop_changed(prop_name)