| 1 |
# (C) Copyright 2004-2023 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
|
| 11 |
""" TableEditor test case for Traits UI which tests editing of lists instead |
| 12 |
of editing of objects.""" |
| 13 |
|
| 14 |
# ------------------------------------------------------------------------- |
| 15 |
# Imports: |
| 16 |
# ------------------------------------------------------------------------- |
| 17 |
|
| 18 |
from traits.api import HasStrictTraits, List |
| 19 |
|
| 20 |
from traitsui.api import View, Item, TableEditor |
| 21 |
|
| 22 |
from traitsui.table_column import ListColumn |
| 23 |
|
| 24 |
from traitsui.table_filter import TableFilter |
| 25 |
|
| 26 |
# ------------------------------------------------------------------------- |
| 27 |
# Sample data: |
| 28 |
# ------------------------------------------------------------------------- |
| 29 |
|
| 30 |
people = [ |
| 31 |
['Dave', 39, '555-1212'], |
| 32 |
['Mike', 28, '555-3526'], |
| 33 |
['Joe', 34, '555-6943'], |
| 34 |
['Tom', 22, '555-7586'], |
| 35 |
['Dick', 63, '555-3895'], |
| 36 |
['Harry', 46, '555-3285'], |
| 37 |
['Sally', 43, '555-8797'], |
| 38 |
['Fields', 31, '555-3547'], |
| 39 |
] |
| 40 |
|
| 41 |
# ------------------------------------------------------------------------- |
| 42 |
# Table editor definition: |
| 43 |
# ------------------------------------------------------------------------- |
| 44 |
|
| 45 |
table_editor = TableEditor( |
| 46 |
columns=[ |
| 47 |
ListColumn(index=0, label='Name'), |
| 48 |
ListColumn(index=1, label='Age'), |
| 49 |
ListColumn(index=2, label='Phone'), |
| 50 |
], |
| 51 |
editable=False, |
| 52 |
show_column_labels=True, # |
| 53 |
) |
| 54 |
|
| 55 |
# ------------------------------------------------------------------------- |
| 56 |
# 'TableTest' class: |
| 57 |
# ------------------------------------------------------------------------- |
| 58 |
|
| 59 |
|
| 60 |
class TableTest(HasStrictTraits): |
| 61 |
|
| 62 |
# ------------------------------------------------------------------------- |
| 63 |
# Trait definitions: |
| 64 |
# ------------------------------------------------------------------------- |
| 65 |
|
| 66 |
people = List() |
| 67 |
|
| 68 |
# ------------------------------------------------------------------------- |
| 69 |
# Traits view definitions: |
| 70 |
# ------------------------------------------------------------------------- |
| 71 |
|
| 72 |
traits_view = View( |
| 73 |
[Item('people', editor=table_editor, resizable=True), '|[]<>'], |
| 74 |
title='Table Editor Test', |
| 75 |
width=0.17, |
| 76 |
height=0.23, |
| 77 |
buttons=['OK', 'Cancel'], |
| 78 |
kind='live', |
| 79 |
) |
| 80 |
|
| 81 |
|
| 82 |
# ------------------------------------------------------------------------- |
| 83 |
# Run the tests: |
| 84 |
# ------------------------------------------------------------------------- |
| 85 |
|
| 86 |
if __name__ == '__main__': |
| 87 |
tt = TableTest(people=people) |
| 88 |
tt.configure_traits() |
| 89 |
for p in tt.people: |
| 90 |
print(p) |
| 91 |
print('--------------') |