Added support for setting ObjectSelector.objects#440
Closed
jbednar wants to merge 2 commits into
Closed
Conversation
This was referenced Sep 29, 2020
Member
Author
|
I think this PR is a net improvement over the current behavior, but I also think we should consider an alternative approach where we simply accept that .objects will either be a dict or a list, and we consistently handle both those cases separately throughout the code. That way a user could do .append safely as long as they never switched between dict or list, but it would still be confusing, and it's hard to see how to make it backwards compatible because the current workaround relies on people first using a dict and then using a list. :-( |
Member
|
Superseded by #598 |
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.
Addresses #398 and possibly #331 .
ObjectSelector was originally designed only to store a list of objects, which works fine if the objects are strings or have a .name attribute, but otherwise a GUI needs to work with names for the objects, and has to get them somewhere. To support this case, ObjectSelector was previously extended to accept a dict of name,obj pairs as the
objectsargument to the constructor, but then extracted only the objects and stored it inself.objects, while storing the mapping inself.names(a lookup table that needs to be mappable both ways for GUI purposes, to give the label from the current value or the new value from a new label). This worked, but caused problems for anyone who wanted to dynamically adjust the objects after the Parameter was constructed.With this PR, the behavior is the same if a user sets .objects after construction as it is during construction; in both cases the object values are extracted (now storing in ._objects) and the names mapping is stored in
self.names. This way a user can update the objects list whenever they like by passing a new dictionary.It also supports cases where people have done a manual workaround like
by keeping the old names if a list is provided and the old names are compatible (have the same length). This special case could be removed now, but it would affect people who had used the previously required workaround.
Note that this PR does not address people trying to do
self.param.x.objects.append(...). Anyone have ideas about whether that could be made to work?