[英]Usage of BoundsEditor in TraitsUI
I want to use the BoundsEditor (in TraitsUI) for a range selection.我想使用 BoundsEditor(在 TraitsUI 中)进行范围选择。 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).
为了测试,我使用 RangeEditor - 它按预期工作(在移动滑块时打印当前值)。 But I cannot get any values out of the BoundsEditor.
但是我无法从 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.我刚刚开始学习 Traits,所以我相信其他人可以比我更好地解释这一点。 I am using an example from http://blog.enthought.com/enthought-tool-suite/traits/new-double-slider-editor/#.VgFbYLTgtWQ .
我正在使用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().
我声明了低值和高值的变量,并将它们传递给 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.