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:   10/13/2004
15
#
16
# ------------------------------------------------------------------------------
17

18 11
""" Defines the UIInfo class used to represent the object and editor content of
19
    an active Traits-based user interface.
20
"""
21

22 11
from traits.api import HasPrivateTraits, Instance, Constant, Bool
23

24

25 11
class UIInfo(HasPrivateTraits):
26
    """ Represents the object and editor content of an active Traits-based
27
    user interface
28
    """
29

30
    # -------------------------------------------------------------------------
31
    #  Trait definitions:
32
    # -------------------------------------------------------------------------
33

34
    #: Bound to a UI object at UIInfo construction time
35 11
    ui = Instance("traitsui.ui.UI", allow_none=True)
36

37
    #: Indicates whether the UI has finished initialization
38 11
    initialized = Bool(False)
39

40 11
    def bind_context(self):
41
        """ Binds all of the associated context objects as traits of the
42
            object.
43
        """
44 11
        for name, value in self.ui.context.items():
45 8
            self.bind(name, value)
46

47 11
    def bind(self, name, value, id=None):
48
        """ Binds a name to a value if it is not already bound.
49
        """
50 11
        if id is None:
51 8
            id = name
52

53 11
        if not hasattr(self, name):
54 8
            self.add_trait(name, Constant(value))
55 11
            if id != "":
56 8
                self.ui._names.append(id)

Read our documentation on viewing source code .

Loading