| 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 |
# Test for TextEditor 'invalid' trait. |
| 12 |
# |
| 13 |
# Look for: |
| 14 |
# |
| 15 |
# background color should be correctly to the error indicating color |
| 16 |
# whenever the name is invalid (all whitespace). In particular: |
| 17 |
# |
| 18 |
# background color should be set at initialization. |
| 19 |
|
| 20 |
from traits.api import Bool, HasTraits, Property, Str |
| 21 |
from traitsui.api import Item, View |
| 22 |
from traitsui.api import TextEditor |
| 23 |
|
| 24 |
|
| 25 |
class Person(HasTraits): |
| 26 |
name = Str() |
| 27 |
|
| 28 |
invalid = Property(Bool, observe='name') |
| 29 |
|
| 30 |
def _get_invalid(self): |
| 31 |
# Name is valid iff it doesn't consist entirely of whitespace. |
| 32 |
stripped_name = self.name.strip() |
| 33 |
return stripped_name == '' |
| 34 |
|
| 35 |
traits_view = View( |
| 36 |
Item('name', editor=TextEditor(invalid='invalid')), |
| 37 |
) |
| 38 |
|
| 39 |
|
| 40 |
if __name__ == '__main__': |
| 41 |
Person().configure_traits() |