Skip to content

Commit

Permalink
Added _dir_mode option to AttrTrees
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Apr 20, 2016
1 parent ca4cc61 commit e73333a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions holoviews/core/tree.py
Expand Up @@ -32,6 +32,17 @@ def merge(cls, trees):
first.update(tree)
return first

def __dir__(self):
"""
The _dir_mode may be 'default' or 'user' in which case only the
child nodes add by the user are listed.
"""
dict_keys = self.__dict__.keys()
if self.__dict__['_dir_mode'] == 'user':
return self.__dict__['children']
else:
return dir(type(self)) + list(dict_keys)

def __init__(self, items=None, identifier=None, parent=None):
"""
identifier: A string identifier for the current node (if any)
Expand All @@ -46,6 +57,7 @@ def __init__(self, items=None, identifier=None, parent=None):
self.__dict__['identifier'] = util.sanitize_identifier(identifier, escape=False)
self.__dict__['children'] = []
self.__dict__['_fixed'] = False
self.__dict__['_dir_mode'] = 'default' # Either 'default' or 'user'

fixed_error = 'No attribute %r in this AttrTree, and none can be added because fixed=True'
self.__dict__['_fixed_error'] = fixed_error
Expand Down Expand Up @@ -218,6 +230,7 @@ def __getattr__(self, identifier):
self.children.append(identifier)
child_tree = self.__class__(identifier=identifier, parent=self)
self.__dict__[identifier] = child_tree
child_tree.__dict__['_dir_mode'] = self.__dict__['_dir_mode']
return child_tree
else:
raise AttributeError
Expand Down

0 comments on commit e73333a

Please sign in to comment.