enthought / enthought/traitsui
Range trait's "high name" and "low name" connect to wrong object in ModelView
- Dominant language
- Python
- Stars
- 306
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
This may actually be a bug in traits.
A range trait can have it's high and low values delegated to other traits by giving strings for high and low instead of numerical values:
```
from traits.api import HasTraits, Int, Range
class TestRange(HasTraits):
low = Int(0)
high = Int(100)
value = Range('low', 'high', default=50)
```
However, when using a `ModelView` to display an instance of the above object, you might write something like this:
```
from traitsui.api import ModelView, View, Item
class TestView(ModelView):
view = View(
Item('value', object='model')
)
test = TestView(model=TestRange())
test.configure_traits()
```
As you can see, the above generates an exception, because the default `RangeEditor` instance looks for traits called `low` and `high` on the `TestView` instance, rather than the `TestRange` instance. This is probably a consequence of the way that the `Range` trait creates its default editor (it passes the high and low trait names directly to the `high_name` and `low_name` arguments)
This is actually going to occur in any case where a Range trait's default editor is created when the instance is not the View's default object.
The work around is simple - create a `RangeEditor` which points to the correct things:
```
class TestView(ModelView):
view = View(
Item('value', object='model',
editor=RangeEditor(low_name='model.low',
high_name='model.high'))
)
```
but it would be nice if we didn't have to do this.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.