| 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 |
# ------------------------------------------------------------------------- |
| 12 |
# Imports: |
| 13 |
# ------------------------------------------------------------------------- |
| 14 |
|
| 15 |
|
| 16 |
from traits.api import Enum, List |
| 17 |
|
| 18 |
from traitsui.api import Handler, View, Item, CheckListEditor |
| 19 |
|
| 20 |
# ------------------------------------------------------------------------- |
| 21 |
# Constants: |
| 22 |
# ------------------------------------------------------------------------- |
| 23 |
|
| 24 |
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'] |
| 25 |
|
| 26 |
numbers = [ |
| 27 |
'one', |
| 28 |
'two', |
| 29 |
'three', |
| 30 |
'four', |
| 31 |
'five', |
| 32 |
'six', |
| 33 |
'seven', |
| 34 |
'eight', |
| 35 |
'nine', |
| 36 |
'ten', |
| 37 |
] |
| 38 |
|
| 39 |
# ------------------------------------------------------------------------- |
| 40 |
# 'CheckListTest' class: |
| 41 |
# ------------------------------------------------------------------------- |
| 42 |
|
| 43 |
|
| 44 |
class CheckListTest(Handler): |
| 45 |
|
| 46 |
# ------------------------------------------------------------------------- |
| 47 |
# Trait definitions: |
| 48 |
# ------------------------------------------------------------------------- |
| 49 |
|
| 50 |
case = Enum('Colors', 'Numbers') |
| 51 |
value = List(editor=CheckListEditor(values=colors, cols=5)) |
| 52 |
|
| 53 |
# ------------------------------------------------------------------------- |
| 54 |
# Event handlers: |
| 55 |
# ------------------------------------------------------------------------- |
| 56 |
|
| 57 |
def object_case_changed(self, info): |
| 58 |
if self.case == 'Colors': |
| 59 |
info.value.factory.values = colors |
| 60 |
else: |
| 61 |
info.value.factory.values = numbers |
| 62 |
|
| 63 |
|
| 64 |
# ------------------------------------------------------------------------- |
| 65 |
# Run the tests: |
| 66 |
# ------------------------------------------------------------------------- |
| 67 |
|
| 68 |
if __name__ == '__main__': |
| 69 |
clt = CheckListTest() |
| 70 |
clt.configure_traits(view=View('case', '_', Item('value', id='value'))) |
| 71 |
print('value:', clt.value) |
| 72 |
clt.configure_traits(view=View('case', '_', Item('value@', id='value'))) |
| 73 |
print('value:', clt.value) |