简体   繁体   English

如何在Enthought Traitsui中使View项变为只读且可滚动?

[英]How can I make a View Item readonly AND scrollable in Enthought Traitsui?

I am using the views in Enthought Traitsui. 我正在使用Enthought Traitsui中的观点。 Within a view, I am using Item('strings', enabled_when='len(x)>20') , where 'strings' is a list of strings and len(x)>20 is never true. 在视图中,我正在使用Item('strings', enabled_when='len(x)>20') ,其中'strings'是字符串列表,而len(x)>20则从不成立。 If there are more than three strings in the list, I cannot see them all. 如果列表中有三个以上的字符串,则无法全部看到。 I would like to be able to scroll through all the strings but at the same time not be allowed to edit the strings. 我希望能够滚动浏览所有字符串,但同时不允许编辑字符串。 Does anybody know if I can have a readonly AND scrollable item, and if not what are the alternatives? 有人知道我是否可以拥有只读且可滚动的项目吗?如果没有,那还有什么替代方法? Thank you. 谢谢。

I think you're looking for a way to customize the editor. 我认为您正在寻找一种自定义编辑器的方法。 Here's the general idea in a minimal example: 这是一个最小示例中的一般思想:

from traits.api import HasTraits, List
from traitsui.api import View, ListEditor, Group, Item


class Foo(HasTraits):
    my_list = List()

    def _my_list_default(self):
        return [str(n) for n in range(6)]

    traits_view = View(
        Item('my_list',
            style='custom',
            editor=ListEditor(
                style='text',
                ),
        ),
        height=100,
    )

if __name__ == '__main__':
    f = Foo()
    f.configure_traits()

范例使用者介面

You can look in the TraitsUI docs to find lots of ways to customize the view with different editor factories. 您可以查看TraitsUI文档,找到许多方法来使用不同的编辑器工厂来自定义视图。 You can change style='readonly' for instance to prevent editing. 您可以更改style='readonly'例如防止编辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM