I want to use the BoundsEditor (in TraitsUI) for a range selection. How do I access the High and Low values? For testing I use the RangeEditor - which works as expected (on moving the slider the current value is printed). But I cannot get any values out of the BoundsEditor. Any pointers are appreciated.
I use following (simplified code):
from traits.api \
import HasTraits, Button, Range
from traitsui.api \
import View, Item, Group, RangeEditor
from traitsui.qt4.extra.bounds_editor import BoundsEditor
class Parameters(HasTraits):
rgb_range = Range(0.,1.0)
range1 = rgb_range
range2 = rgb_range
eval_button = Button("Eval")
traits_view= View(
Item('range1')), #editor=RangeEditor()
Item('range2', editor=BoundsEditor()),
Item('eval_button'))
def _range1_changed(self, value):
print(value)
def _range2_changed(self, *arg, **kwargs):
print(arg)
def _range2_changed(self, *arg, **kwargs):
print(arg)
def _range2_low_changed(self, *arg, **kwargs):
print(arg)
def _range2_high_changed(self, *arg, **kwargs):
print(arg)
def _eval_button_fired(self):
print(self.range1)
print(self.range2)
if __name__ == '__main__':
alg = Parameters()
alg.configure_traits()
I am just beginning to learn Traits, so I am sure someone else can explain this better than me. I am using an example from http://blog.enthought.com/enthought-tool-suite/traits/new-double-slider-editor/#.VgFbYLTgtWQ. I declared variables for the low and high values, and passed these into BoundsEditor(). Then I declared functions that run when those values change. I got what I think is close to what you are looking for.
from traits.api \
import HasTraits, Button, Range, Float
from traitsui.api \
import View, Item, Group, RangeEditor
from traitsui.qt4.extra.bounds_editor import BoundsEditor
class Parameters(HasTraits):
rgb_range = Range(0.,1.0)
range1 = rgb_range
range2 = rgb_range
low_val = Float(0.0)
high_val = Float(1.0)
eval_button = Button("Eval")
traits_view= View(
Item('range1', editor=RangeEditor()),
Item('range2', editor=BoundsEditor(low_name = 'low_val', high_name = 'high_val')),
Item('eval_button'))
def _range1_changed(self, value):
print(value)
def _low_val_changed(self):
print(self.low_val)
def _high_val_changed(self):
print(self.high_val)
def _eval_button_fired(self):
print(self.range1)
print(self.low_val)
print(self.high_val)
if __name__ == '__main__':
alg = Parameters()
alg.configure_traits()