You can provide the list of ObjectColumns
as a trait on your ModelList
class. Instead of defining the columns
list on the TableEditor
factory object, use columns_name
argument instead to point to the name of the trait on ModelList
. Whenever you update the list on ModelList
, the TableEditor
implementation should follow along.
class ModelList(HasTraits):
models = List(Instance(Model))
columns = List(Instance(ObjectColumn))
variables = ...
traits_view = View(UItem('variables',
editor=TableEditor(columns_name='columns')))
def update(self):
columns = []
for model in self.models :
columns.append(ObjectColumn(..some stuff..))
self.columns = columns
This is a common pattern in Traits UI. In many places, you have a choice between giving the Editor
an explicit value (which is then usually static), or giving the Editor
the name of a trait on the edited object that holds the (usually dynamic) value.