zoukankan      html  css  js  c++  java
  • 科学计算三维可视化---TraitsUI(Group对象组织界面)

    使用Group对象组织界面

    将一组相关的Item对象组织在一起
    from traitsui.api import Group

    from traits.api import HasTraits,Int,Str
    from traitsui.api import View,Item,Group
    #View描述了界面的视图类,Item模块描述了界面中的控件类
    
    class ModelManager(HasTraits):
        model_name = Str
        category = Str
        model_file = Str
        model_number = Int
        vertices = Int
    
        view1 = View(
            Group(
                Item("model_name", label=u"模型名称"),
                Item("model_file", label=u"文件名"),
                Item("category", label=u"模型类型"),
                label=u"模型信息",
                show_border=True
            ),
            Group(
                Item("model_number", label=u"模型数量"),
                Item("vertices", label=u"顶点数量"),
                label=u"统计数据",
                show_border=True
            ),
        )
    
    model = ModelManager()
    model.configure_traits()

        view1 = View(
            Group(  
                Group(
                    Item("model_name", label=u"模型名称"),
                    Item("model_file", label=u"文件名"),
                    Item("category", label=u"模型类型"),
                    label=u"模型信息",
                    show_border=True
                ),
                Group(
                    Item("model_number", label=u"模型数量"),
                    Item("vertices", label=u"顶点数量"),
                    label=u"统计数据",
                    show_border=True
                ),
            )
        )

     

        view1 = View(
            Group(
                Group(
                    Item("model_name", label=u"模型名称"),
                    Item("model_file", label=u"文件名"),
                    Item("category", label=u"模型类型"),
                    label=u"模型信息",
                    show_border=True
                ),
                Group(
                    Item("model_number", label=u"模型数量"),
                    Item("vertices", label=u"顶点数量"),
                    label=u"统计数据",
                    show_border=True
                ),
                orientation="horizontal"
            ),
        )

     

    Group派生类(对很多属性值进行默认设置)

     

        view1 = View(
            HSplit(  #大布局水平
                VGroup(  #小布局内部垂直
                    Item("model_name", label=u"模型名称"),
                    Item("model_file", label=u"文件名"),
                    Item("category", label=u"模型类型"),
                    label=u"模型信息",
                    show_border=True
                ),
                VGroup(
                    Item("model_number", label=u"模型数量"),
                    Item("vertices", label=u"顶点数量"),
                    label=u"统计数据",
                    show_border=True
                ),
                orientation="horizontal"
            ),
        )

     内外部视图

    from traits.api import Property,HasTraits,Float,cached_property,Int,Str,Event,on_trait_change
    from traitsui.api import View,Item,Group,HSplit,VGroup
    #View描述了界面的视图类,Item模块描述了界面中的控件类
    
    g1 = [
        Item("model_name", label=u"模型名称"),
        Item("category", label=u"模型类型"),
    ]
    g2 = [
        Item("model_number", label=u"模型数量"),
        Item("vertices", label=u"顶点数量"),
    ]
    
    
    class ModelManager(HasTraits):
        model_name = Str
        category = Str
        model_number = Int
        vertices = Int
    
        traits_view = View(
            Group(*g1,label=u"模型信息",show_border=True),
            Group(*g2,label=u"统计数据",show_border=True),
            title=u"内部视图"
        )
    
    global_view = View(
        Group(*g1,label=u"模型信息",show_border=True),
        Group(*g2,label=u"统计数据",show_border=True),
        title=u"外部视图"
    )
    
    model = ModelManager()
    >>> model.configure_traits()  #默认是内部视图

    >>> model.configure_traits(view="traits_view")  #有选择的选中某个内部视图

     

    >>> model.configure_traits(view=global_view)  #直接将外部视图赋给view

  • 相关阅读:
    176. Second Highest Salary
    175. Combine Two Tables
    172. Factorial Trailing Zeroes
    171. Excel Sheet Column Number
    169. Majority Element
    168. Excel Sheet Column Title
    167. Two Sum II
    160. Intersection of Two Linked Lists
    个人博客记录
    <meta>标签
  • 原文地址:https://www.cnblogs.com/ssyfj/p/9309900.html
Copyright © 2011-2022 走看看