python - TraitsUI 中 BoundsEditor 的使用

标签 python enthought traits traitsui

我想使用 BoundsEditor(在 TraitsUI 中)进行范围选择。如何访问高值和低值?为了进行测试,我使用 RangeEditor - 它按预期工作(在移动 slider 时打印当前值)。但我无法从 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() 

最佳答案

我刚刚开始学习 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() 

关于python - TraitsUI 中 BoundsEditor 的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32693213/

相关文章:

python - __format__ 方法应该如何用于 int?

python - ipython后面config方法的实现

scala - Scala的MapLike,ListLike,SeqLike等如何分别与Map,List,Seq进行比较?

python - 如何强制caffe读取所有训练数据?

python - 如何在逐行移动时使用 python 中的 apply 函数

python - 如何使用mayavi.tools.pipeline.transform_data完成一个绕x轴的旋转

c++ - 如何从 C++ 模板中的方法类型推断类类型?

php - 为什么使用嵌套特征会改变 PHP 行为?

python - Django ModelForm 可以显示存储值的自定义表示吗?