enthought/traitsui — Issue #48: CSVListEditor does not remove the notification hook
Author: itziakos
Created: 2012-01-16 00:18:52+00:00
State: open

The CSVListEditor does not remove the notification hook on the items of the list.

The problem is located in the _make_text_editor method of the CSVListEditor factory. The method first creates a TextEditor
and then externally hooks a change notifier for the editor update method to be called on any item change in the list, However the editor not aware of this additional notification hook and the change notifier is not removed by the editors dispose method. As a result the notifier is called even when the editor is not valid anymore.

The following code sample demonstrates the issue:

from traits.api import HasTraits, List, Float, Instance
from traitsui.api import View, Item, CSVListEditor, ModelView, InstanceEditor

class MyClass(HasTraits):
data = List(Float)

class MyClassModelView(ModelView):
model = Instance(MyClass)

traits_view = View(
Item('model.data', editor = CSVListEditor()),
buttons = ['OK']
)

my_class = MyClass(data=[1,2,3])
my_class_model_view=MyClassModelView(model=my_class)
my_class_model_view.configure_traits() # just close the window no need to make any change
my_class.data.append(2) # this call will raise a trait error
print my_class.data

Running the code with a recent traitsui checkout causes the following traits error:

Exception occurred in traits notification handler.
Please check the log file for details.
Exception occurred in traits notification handler for object: <__main__.MyClass object at 0x05262F60>, trait: data_items, old value: [], new value: [2.0]
Traceback (most recent call last):
File "C:\epd32\71\lib\site-packages\traits\trait_notifiers.py", line 511, in rebind_call_0
self.dispatch( getattr( self.object(), self.name ) )
File "C:\epd32\71\lib\site-packages\traits\trait_notifiers.py", line 454, in dispatch
handler( *args )
File "c:\users\ionnis\projects\traitsui\traitsui\wx\text_editor.py", line 142, in update_editor
user_value = self._get_user_value()
File "c:\users\ionnis\projects\traitsui\traitsui\wx\text_editor.py", line 166, in _get_user_value
value = self.control.GetValue()
AttributeError: 'NoneType' object has no attribute 'GetValue'