Question

I came across the behavior that RangeEditor does not work properly inside a TableEditor.

from traits.api import *
from traitsui.api import *

class TableItem(HasTraits):
    r=Range(1,6)

class Table(HasTraits):
    t=List(Instance(TableItem))
    def _t_default(self):
        return [TableItem()]

    traits_view=View(
        Item(name='t',
            editor=TableEditor( columns=[
                ObjectColumn(label='Number',editor=RangeEditor(mode='spinner'),
                name='r',editable=True)
            ]
        ),height=250,width=250,show_label=False))

Table().configure_traits()

The behavior resulting from this program is that the range can only be adjusted between 0 and 1. If mode='spinner' is not specified it acts like the range is an float between 0 and 1. Of course, in the above example, whenever the range is set to 0 an error is spit out because the trait doesn't accept any values other than the interval [1,6].

This behavior is very clearly a bug and probably won't ever be fixed as enaml moves forward. But is there a simple workaround?

Was it helpful?

Solution

I found a workaround:

from traits.api import *
from traitsui.api import *

class TableItem(HasTraits):
    r=Range(1,6)
    _integer_value_one=Constant(1)
    _integer_value_six=Constant(6)

class Table(HasTraits):
    t=List(Instance(TableItem))
    def _t_default(self):
        return [TableItem()]

    traits_view=View(
        Item(name='t',
            editor=TableEditor( columns=[
                ObjectColumn(label='Number',editor=RangeEditor(mode='spinner',
                    high_name='_integer_value_six',low_name='_integer_value_one'),
                name='r',editable=True)
            ]
        ),height=250,width=250,show_label=False))

Table().configure_traits()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top