pythontraitsenthoughttraitsui

How to make user interface for a HasTraits class using the Enthought Tool Suite


I have two class, it is child class of HasTraits. this case:

  view =View(
    VGroup(
        HGroup(
            Label(u' '),
            Item(
                "bt_import", label=' '
            ),
            Item(
                "bt_export", label=' '
            ),
            show_left=False
        ),
        HGroup(
            Label(u' '),
            Item(
                "signalplot",
                editor=ComponentEditor(size=(600, 300)),
                show_label=False
            ),
            Label(u' '),
        ),
        HGroup(
            Label(u' '),
            Item(
                "spectrumplot",
                editor=ComponentEditor(size=(600, 300)),
                show_label=False
            ),
            Label(u' '),
        ),
   ),
    width=600,
    height=800,
    resizable=False,
    title=u"FFT 过滤"
)

In here, I will put two class. signalplot<-signal class and spectrumplot<-spectrum class two class:

class Signal(HasTraits):
     view = View()
.......

class Spectrum(HasTraits):
       view = View()
.......

This case, How to make two class? and How to put two class in interface?


Solution

  • The pattern you're looking for is this:

    class MySignalSpectrumView(HasTraits):
        sig = Instance(Signal)
        spec = Instance(Spectrum)
    
    if __name__ == "__main__":
        mssv = MySignalSpectrumView()
        mssv.configure_traits(view=view)
    

    That is, you are calling edit_traits or configure_traits on the model class and passing it the view you want to use. Defining a traits_view = View(...) will provide the view used by default. There are lots of good examples in the docs and the demos directory that ships with Traits, TraitsUI, and Chaco.