enthought / enthought/traitsui

TabularEditor's columns change

Open
#1,802 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
306
Forks
99
PR merge metrics
No merged PRs in 30d

Description

Hello,

I would like to change the TabularEditor's columns traits.

Here a CME, from Traits UI demos NumPy_array_tabular_editor_demo.py:

from numpy import sqrt
from numpy.random import random

from traits.api import HasTraits, Property, Array, String, Any
from traitsui.api import View, Item, TabularAdapter, TabularEditor, HGroup

class ArrayAdapter(TabularAdapter):

columns = [('i', 'index'), ('x', 0), ('y', 1), ('z', 2)]

font = 'Courier 10'
alignment = 'right'
format = '%.4f'

index_text = Property()
index_image = Property()

def _get_index_text(self):
return str(self.row)

def _get_index_image(self):
x, y, z = self.item
if sqrt((x - 0.5) ** 2 + (y - 0.5) ** 2 + (z - 0.5) ** 2) <= 0.25:
return '@icons:red_ball'

return None

class ShowArray(HasTraits):

data = Array

xlabel, ylabel, zlabel = String, String, String

adapter = Any

def traits_view(self):
view = View(
Item(
'data',
show_label=False,
editor=TabularEditor(
adapter=self.adapter,
auto_resize=True,
# Do not allow any kind of editing of the array:
editable=False,
operations=[],
drag_move=False,
),
),
HGroup(Item('xlabel'),
Item('ylabel'),
Item('zlabel')),
title='Array Viewer',
resizable=True,
)
return (view)

def _adapter_default(self):
return (ArrayAdapter())

def _xlabel_changed(self):
print(self.adapter.columns)
self.adapter.columns[1] = (self.xlabel, 0)
print(self.adapter.columns)

def _ylabel_changed(self):
print(self.adapter.columns)
self.adapter.columns[2] = (self.ylabel, 0)
print(self.adapter.columns)

def _zlabel_changed(self):
print(self.adapter.columns)
self.adapter.columns[3] = (self.zlabel, 0)

demo = ShowArray(data=random((5, 3)))

if __name__ == '__main__':
demo.configure_traits()

If I modify xlabel, self.adapter.columns is modified, ok, but not in the UI.

What am I doing wrong?

Thanks in advance for any help.

Regards.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.