I've found that I can apply a format to ALL the columns in a TabularAdapter by adding a statement like this to the TabularAdapter declaration: format = '%7.4f'.
However, I'd like to have different formatting for each column in the table...is this possible? I've tried to specify the format for just column index 2 (as seen in the example below), but it doesn't apply to just that column. I've been searching for how to do this correctly, but so far have found nothing.
Here's a little example file:
from traits.api import HasTraits, Array
from traitsui.api import View, Group,Item, TabularEditor
from traitsui.tabular_adapter import TabularAdapter
from numpy import dtype
test_dtype = dtype([('Integer#1', 'int'), ('Integer#2', 'int'), ('Float', 'float')])
class testArrayAdapter(TabularAdapter):
columns = [('Col1 #', 0), ('Col2', 1), ('Col3', 2)]
even_bg_color = 0xf4f4f4 # very light gray
width = 125
class test(HasTraits):
test_array = Array(dtype=test_dtype)
view = View(
Item(name = 'test_array',
show_label = False,
editor = TabularEditor(adapter = testArrayAdapter()),
),
Item(name = 'test_array',
show_label = False,
editor = TabularEditor(adapter = testArrayAdapter(column=2, format='%.4f')),
),
)
Test = test()
Test.test_array.resize(5, refcheck = False)
Test.configure_traits()
What I'd like to see is to have the 3rd column have the 4 decmals (it is a float after all), while columns 1 & 2 are presented as just integers.