The standard way to do this - use features lowand highand assign them as the limitsRange
from traits.api import HasTraits, Range, Int
class Foo(HasTraits):
high = Int(10)
low = Int(1)
bar = Range(high='high', low='low')
Dynamic characteristics can be assigned dynamically:
>>> f = Foo()
>>> f.bar = 5
>>> f.bar
5
>>> f.bar = 30
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/tim/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/traits/trait_types.py", line 1785, in _set
self.error( object, name, value )
File "/Users/tim/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/traits/trait_handlers.py", line 172, in error value )
traits.trait_errors.TraitError: The 'bar' trait of a Foo instance must be 1 <= a number <= 10, but a value of 30 <type 'int'> was specified.
>>> f.high = 35
>>> f.bar = 30
>>> f.bar
30
source
share