enthought / enthought/traitsui
Pass the object to InstanceChoiceItem.get_view
- Dominant language
- Python
- Stars
- 306
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
One use-case for `InstanceChoiceItem` subclasses is to provide different views based on the class or other characteristics of an object when there is no combobox by overriding `is_compatible` and having `is_selectable` always return `False`. The view can be composed dynamically using `get_view()`, but the method only has the `InstanceChoiceItem` as context, not the actual object being viewed, so the view cannot use any information from the object to do things like set titles or vary the view depending on the object state.
It would be good if the object being viewed were available, which could be achieved by changing the `get_view()` method's signature to: `get_view(self, object)`
The only place that the method is called is here (and the equivalent in the wx backend):
https://github.com/enthought/traitsui/blob/79b66f5670e3de2b73529db5c29b3d216f0a2389/traitsui/qt4/instance_editor.py#L243
and the `object` is available at that point.
This is not a heavily used part of the codebase, so this change would not be particularly disruptive, but we could still support the no-parameter version with a deprecation warning, doing something like:
```
try:
item.get_view(object)
except TypeError:
item.get_view()
# also issue a deprecation warning
```
Note that there are other ways of doing this, such as defining `trait_view_for_...` methods on the handler for the UI.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.