python - Defining view elements from dictionary elements in TraitsUI -


is there way reference items in dictionary in traitsui views?

in other words, there way mean following, using dict trait:

from traits.api import * traitsui.api import * traitsui.ui_editors.array_view_editor import arrayvieweditor import numpy np  class smallpartoflargeapplication(hastraits):   a=dict    def _a_default(self):     return {'a_stat':np.random.random((10,1)),             'b_stat':np.random.random((10,10))}    traits_view=view(     item('a.a_stat',editor=arrayvieweditor()))  smallpartoflargeapplication().configure_traits() 

this worked me.

from traits.api import * traitsui.api import * traitsui.ui_editors.array_view_editor import arrayvieweditor import numpy np  class dcontainer(hastraits):     _dict=dict     def __getattr__(self, k):         if k in self._dict:             return self._dict[k]  class smallpartoflargeapplication(hastraits):   d=instance(dcontainer)    def _d_default(self):     d=dcontainer()     d._dict={'a_stat':np.random.random((10,1)),             'b_stat':np.random.random((10,10))}      return d    def traits_view(self):     v=view(         item('object.d.a_stat',editor=arrayvieweditor()))     return v  smallpartoflargeapplication().configure_traits() 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -