我想使用BoundsEditor(在TraitsUI中)进行范围选择。如何访问“高”和“低”值?为了测试我使用RangeEditor - 它按预期工作(在移动滑块时打印当前值)。但我无法从BoundsEditor中获取任何值。任何指针都表示赞赏。
我使用以下(简化代码):
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()
答案 0 :(得分:2)
我刚刚开始学习Traits,所以我相信其他人可以比我更好地解释这一点。我正在使用http://blog.enthought.com/enthought-tool-suite/traits/new-double-slider-editor/#.VgFbYLTgtWQ中的示例。我声明了低值和高值的变量,并将它们传递给BoundsEditor()。然后我声明了那些值发生变化时运行的函数。我得到了我认为接近你正在寻找的东西。
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()