I am using the views in Enthought Traitsui. Within a view, I am using Item('strings', enabled_when='len(x)>20')
, where 'strings'
is a list of strings and len(x)>20
is never true. If there are more than three strings in the list, I cannot see them all. I would like to be able to scroll through all the strings but at the same time not be allowed to edit the strings. Does anybody know if I can have a readonly AND scrollable item, and if not what are the alternatives?
Thank you.
Asked
Active
Viewed 264 times
2

NightShadeQueen
- 3,284
- 3
- 24
- 37

Antique
- 31
- 2
-
Why is this problematic? `ListEditor` and `ListStrEditor` have readonly styles. What have you tried so far? – aestrivex Jun 30 '15 at 20:12
-
Why would you want `enabled_when='len(x)>20'` if `len(x)>20` is never true? Are you using this as a way to get a readonly editor? – aestrivex Jun 30 '15 at 20:14
-
@aestrivex Thank you for your comments. I had tried several things but not ListEditor. I was using "enabled_when='len(x)>20'" to get a readonly editor. With ListEditor, I am able to get a readonly style AND I am able to scroll through the list. – Antique Jul 07 '15 at 17:31
1 Answers
0
I think you're looking for a way to customize the editor. Here's the general idea in a minimal example:
from traits.api import HasTraits, List
from traitsui.api import View, ListEditor, Group, Item
class Foo(HasTraits):
my_list = List()
def _my_list_default(self):
return [str(n) for n in range(6)]
traits_view = View(
Item('my_list',
style='custom',
editor=ListEditor(
style='text',
),
),
height=100,
)
if __name__ == '__main__':
f = Foo()
f.configure_traits()
You can look in the TraitsUI docs to find lots of ways to customize the view with different editor factories. You can change style='readonly'
for instance to prevent editing.

Tim D
- 1,645
- 1
- 25
- 46