I am a rookie student using the TraitsUI module to visuanlize an Array traits. I did a slight modification to the demo code in order to update the value of Array, and I am receiving the message "IndexError: invalid index to scalar variable"
BTW, I use the same method in ArrayEditor and it worked...
What is the cause of this error?
Is there a correct way to enable the update of Array value in ArrayViewEditor?
Here is the practice code:
from numpy.random import random
from traits.api import HasTraits, Array,Button
from traitsui.api import View, Item
from traitsui.ui_editors.array_view_editor import ArrayViewEditor
import numpy as np
#-- ShowArray demo class -------------------------------------------------------
class ShowArray(HasTraits):
data = Array(editor = ArrayViewEditor(titles = [ 'x', 'y', 'z' ],
format = '%.4f',
show_index = False
# Font fails with wx in OSX;
# see traitsui issue #13:
# font = 'Arial 8'
))
change = Button()
view = View(
Item('data',show_label = False),
Item('change',show_label = False),
title = 'Array Viewer',
width = 0.3,
height = 0.8,
resizable = True
)
def _change_fired(self):
self.data = np.arange(1,4)
#-- Run the demo ---------------------------------------------------------------
# Create the demo:
demo = ShowArray(data = random((100000, 3)))
# Run the demo (if invoked from the command line):
if __name__ == '__main__':
demo.configure_traits()
I executed the code, and press the "change" button, and there comes the error:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\traitsui\wx\tabular_editor.py", line 167, in OnGetItemText
row, column )
File "C:\Python27\lib\site-packages\traitsui\tabular_adapter.py", line 323, in get_text
return self._result_for( 'get_text', object, trait, row, column )
File "C:\Python27\lib\site-packages\traitsui\tabular_adapter.py", line 574, in _result_for
return handler()
File "C:\Python27\lib\site-packages\traitsui\tabular_adapter.py", line 582, in <lambda>
return lambda: getattr( self, name )
File "C:\Python27\lib\site-packages\traitsui\tabular_adapter.py", line 412, in _get_text
self.object, self.name, self.row, self.column )
File "C:\Python27\lib\site-packages\traitsui\tabular_adapter.py", line 329, in get_content
return self._result_for( 'get_content', object, trait, row, column )
File "C:\Python27\lib\site-packages\traitsui\tabular_adapter.py", line 574, in _result_for
return handler()
File "C:\Python27\lib\site-packages\traitsui\tabular_adapter.py", line 582, in <lambda>
return lambda: getattr( self, name )
File "C:\Python27\lib\site-packages\traitsui\ui_editors\array_view_editor.py", line 53, in _get_content
return self.item[ self.column_id ]
IndexError: invalid index to scalar variable.
Python 2.7.3, 32-bit. traitsui-4.2.0