By default, the editor calls the string method capitalize
on the text. I don't know why; perhaps the author thought this would help enforce a consistent style in the UI.
You can override this behavior with the format_func
argument of the CheckListEditor
. Here's an example. (I also used the label
argument of the Item
to override the capitalization of the editor's label.)
from traits.api import HasTraits, List, on_trait_change
from traitsui.api import Item, View, CheckListEditor
class Foo(HasTraits):
stuff = List()
traits_view = View(Item('stuff', style='custom', label='stuff',
editor=CheckListEditor(values=['.state.First', '.state.Last', '.state.Any'],
format_func=lambda x: x)))
@on_trait_change('stuff[]')
def show_stuff(self):
print "stuff =", self.stuff
if __name__ == "__main__":
f = Foo()
f.configure_traits()
Alternatively, you can give the values
as a list of tuples. Each tuple has the form (obj, label)
, where label
is the string that is displayed in the UI and obj
is the object added to the list. When this form is used, the label is left unchanged in the UI. For example,
traits_view = View(Item('stuff', style='custom', label='stuff',
editor=CheckListEditor(values=[('.state.First',)*2,
('.state.Last',)*2,
('.state.Any',)*2])))