You simply need to specify to the TextEditor you are creating a couple of keyword arguments auto_set
and enter_set
so that the widget knows when it needs to evaluate your value. Here would be an example implementing a lazy widget:
from traits.api import HasTraits, Int
from traitsui.api import TextEditor, View, Item
class LazyEval(HasTraits):
a = Int
# Additional 'evaluate' is needed to make an int from a string
view = View(Item("a", editor=TextEditor(auto_set=False, enter_set=True,
evaluate=int)))
def _a_changed(self):
print "New value of a is %s" % self.a
l = LazyEval()
l.configure_traits()
This code will print values for a only when you hit enter now. If you removed auto_set and enter_set, it would print it on every keystroke. For more details: http://docs.enthought.com/traitsui/traitsui_user_manual/factories_basic.html#texteditor