1
""" An instance editor that allows total control over widget creation. """
4
# Enthought library imports.
5
from traits.etsconfig.api import ETSConfig
6
from traits.api import Any
7
from traitsui.api import EditorFactory
9
# fixme: We need to import the 'Editor' class from the appropriate toolkit.
10
exec('from traitsui.%s.editor import Editor' % ETSConfig.toolkit)
13
class _WidgetEditor(Editor):
14
""" An instance editor that allows total control over widget creation. """
16
#### '_WidgetEditor' interface ############################################
18
# The toolkit-specific parent of the editor.
21
###########################################################################
22
# '_WidgetEditor' interface.
23
###########################################################################
25
def init(self, parent):
26
""" Initialize the editor. """
30
# fixme: What if there are no pages?!?
31
page = self.object.pages[0]
33
# Create the editor's control.
34
self.control = page.create_control(parent)
36
# Listen for the page being changed.
37
self.object.on_trait_change(self._on_page_changed, 'selected_page')
42
""" Dispose of the editor. """
44
page = self.object.selected_page
45
page.destroy_control()
49
def update_editor(self):
50
""" Update the editor. """
54
###########################################################################
56
###########################################################################
58
def _on_page_changed(self, obj, trait_name, old, new):
59
""" Dynamic trait change handler. """
65
self.control = new.create_control(self.parent)
70
class WidgetEditor(EditorFactory):
71
""" A factory widget editors. """
73
###########################################################################
75
###########################################################################
77
def __call__ (self, *args, **traits):
78
""" Call the object. """
80
return self.set(**traits)
82
###########################################################################
83
# 'EditorFactory' interface.
84
###########################################################################
86
def simple_editor(self, ui, object, name, description, parent):
87
""" Create a simple editor. """
89
editor = _WidgetEditor(
95
description = description
100
custom_editor = simple_editor
101
text_editor = simple_editor
102
readonly_editor = simple_editor
104
#### EOF ######################################################################