1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#------------------------------------------------------------------------------
# Copyright (c) 2005, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
# Thanks for using Enthought open source!
#
# Author: Enthought, Inc.
# Description: <Enthought pyface package component>
#------------------------------------------------------------------------------
""" Abstract base class for a node in a preferences dialog. """
# Enthought library imports.
from traits.api import Delegate, Instance, Str
# Local imports.
from i_preferences_page import IPreferencesPage
from tree_item import TreeItem
class PreferencesNode(TreeItem):
""" Abstract base class for a node in a preferences dialog.
A preferences node has a name and an image which are used to represent the
node in a preferences dialog (usually in the form of a tree).
"""
#### 'PreferenceNode' interface ###########################################
# The page's help identifier (optional). If a help Id *is* provided then
# there will be a 'Help' button shown on the preference page.
help_id = Delegate('page')
# The page name (this is what is shown in the preferences dialog.
name = Delegate('page')
# The page that we are a node for.
page = Instance(IPreferencesPage)
###########################################################################
# 'object' interface.
###########################################################################
def __str__(self):
""" Returns the string representation of the item. """
if self.page is None:
s = 'root'
else:
s = self.page.name
return s
__repr__ = __str__
###########################################################################
# 'PreferencesNode' interface.
###########################################################################
def create_page(self, parent):
""" Creates the preference page for this node. """
return self.page.create_control(parent)
def lookup(self, name):
""" Returns the child of this node with the specified Id.
Returns None if no such child exists.
"""
for node in self.children:
if node.name == name:
break
else:
node = None
return node
###########################################################################
# Debugging interface.
###########################################################################
def dump(self, indent=''):
""" Pretty-print the node to stdout. """
print indent, 'Node', str(self)
for child in self.children:
child.dump(indent+' ')
return
#### EOF ######################################################################
|