enthought / traitsui
1
# ------------------------------------------------------------------------------
2
#
3
#  Copyright (c) 2005, Enthought, Inc.
4
#  All rights reserved.
5
#
6
#  This software is provided without warranty under the terms of the BSD
7
#  license included in LICENSE.txt and may be redistributed only
8
#  under the conditions described in the aforementioned license.  The license
9
#  is also available online at http://www.enthought.com/licenses/BSD.txt
10
#
11
#  Thanks for using Enthought open source!
12
#
13
#  Author: David C. Morrill
14
#  Date:   03/03/2006
15
#
16
# ------------------------------------------------------------------------------
17

18 4
""" Defines the BasicUIEditor class, which allows creating editors that define
19
    their function by creating an embedded Traits UI.
20
"""
21

22 4
from traits.api import Instance
23

24 4
from .ui import UI
25

26 4
from .editor import Editor
27

28
# -------------------------------------------------------------------------
29
#  'UIEditor' base class:
30
# -------------------------------------------------------------------------
31

32

33 4
class UIEditor(Editor):
34
    """ An editor that creates an embedded Traits UI.
35
    """
36

37
    # -------------------------------------------------------------------------
38
    #  Trait definitions:
39
    # -------------------------------------------------------------------------
40

41
    #: The Traits UI created by the editor
42 4
    editor_ui = Instance(UI)
43

44 4
    def init(self, parent):
45
        """ Finishes initializing the editor by creating the underlying toolkit
46
            widget.
47
        """
48 4
        self.editor_ui = self.init_ui(parent).trait_set(parent=self.ui)
49 4
        self.control = self.editor_ui.control
50

51 4
    def init_ui(self, parent):
52
        """ Creates the traits UI for the editor.
53
        """
54 0
        return self.value.edit_traits(
55
            view=self.trait_view(),
56
            context={"object": self.value, "editor": self},
57
            parent=parent,
58
        )
59

60 4
    def update_editor(self):
61
        """ Updates the editor when the object trait changes external to the
62
            editor.
63
        """
64
        # Do nothing, since the embedded traits UI should handle the updates
65
        # itself, without our meddling:
66 4
        pass
67

68 4
    def dispose(self):
69
        """ Disposes of the contents of an editor.
70
        """
71
        # Make sure the embedded traits UI is disposed of properly:
72 4
        if self.editor_ui is not None:
73 4
            self.editor_ui.dispose()
74

75 4
        super(UIEditor, self).dispose()
76

77 4
    def get_error_control(self):
78
        """ Returns the editor's control for indicating error status.
79
        """
80 0
        return self.editor_ui.get_error_controls()
81

82
    # -- UI preference save/restore interface ---------------------------------
83

84 4
    def restore_prefs(self, prefs):
85
        """ Restores any saved user preference information associated with the
86
            editor.
87
        """
88 0
        self.editor_ui.set_prefs(prefs)
89

90 4
    def save_prefs(self):
91
        """ Returns any user preference information associated with the editor.
92
        """
93 0
        return self.editor_ui.get_prefs()

Read our documentation on viewing source code .

Loading