Added support for setting ObjectSelector.objects
Addresses https://github.com/holoviz/param/issues/398 and possibly https://github.com/holoviz/param/issues/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 objects argument to the constructor, but then extracted only the objects and stored it in self.objects, while storing the mapping in self.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
self.param.x.names = new_opts
self.param.x.objects = list(new_opts.values())
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?
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. :-(
Superseded by https://github.com/holoviz/param/pull/598