fix(select_nodes): log error when a previously selected node cannot be reselected - #331
Open
vincentullmann wants to merge 1 commit into
Open
Conversation
Member
|
I would do explicit QUESTION: Could we do something like this? @contextlib.contextmanager
def maintained_selection(exclude_nodes=None):
"""Maintain selection during context
Maintain selection during context and unselect
all nodes after context is done.
Arguments:
exclude_nodes (list[nuke.Node]): list of nodes to be unselected
before context is done
Example:
>>> with maintained_selection():
... node["selected"].setValue(True)
>>> print(node["selected"].value())
False
"""
if exclude_nodes:
for node in exclude_nodes:
node["selected"].setValue(False)
selected_nodes = nuke.selectedNodes()
node_ids = set()
for node in selected_nodes:
node["selected"].setValue(False)
node_ids.add(id(node))
try:
yield
finally:
# unselect all selection in case there is some
reset_selection()
# and select all previously selected nodes if were not removed
for node in nuke.allNodes()
if not node_ids:
break
if id(node) in node_ids:
node_ids.discard(id(node))
node["selected"].setValue(True)Not sure how slower this might be... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog Description
avoid crashing if a node cannot be selected
Additional review information
as mentioned in #329, there can be cases where
select_nodesmay get called with a list of invalid nodes. For example when using amaintained_selectioncontext manager and one of the previous selected nodes got deleted within the block.Testing notes: