Skip to content

Commit

Permalink
Merge pull request #22 from percival-detector/parameter_tree_list
Browse files Browse the repository at this point in the history
Updated parameter tree to support explicit lists
  • Loading branch information
timcnicholls committed Apr 18, 2017
2 parents bbef84b + 0b22235 commit e5437a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ ENV/
# CTAGS tags files
tags
.tags
/.project
/.pydevproject
19 changes: 16 additions & 3 deletions odin/adapters/parameter_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
James Hogge, Tim Nicholls, STFC Application Engineering Group.
"""


class ParameterTreeError(Exception):
"""Simple error class for raising parameter tree parameter tree exceptions."""

Expand Down Expand Up @@ -203,13 +202,20 @@ def __recursive_build_tree(self, node, path=''):

# Convert list or non-callable tuple to enumerated dict ; TODO - remove this?
if isinstance(node, list) or isinstance(node, tuple):
node = {str(i): node[i] for i in range(len(node))}
#print "BUILD 1 I AM AT ", type(node), "node", node, "path", path

return [self.__recursive_build_tree(elem, path=path) for elem in node]
#node = {str(i): node[i] for i in range(len(node))}

# Recursively check child elements
if isinstance(node, dict):
#print "BUILD 2 I AM AT ", type(node), "node", node, "path", path
return {k: self.__recursive_build_tree(
v, path=path + k + '/') for k, v in node.items()}


#if isinstance(node, list) or isinstance(node, tuple):
#print "BUILD 3 I AM AT ", type(node), "node", node, "path", path

return node

def __recursive_populate_tree(self, node):
Expand All @@ -224,13 +230,20 @@ def __recursive_populate_tree(self, node):
"""
# If this is a branch node recurse down the tree
if isinstance(node, dict):
#print "POPULATE 1 I AM AT", type(node), "node", node
return {k: self.__recursive_populate_tree(v) for k, v in node.items()}

if isinstance(node, list) or isinstance(node, tuple):
#print "POPULATE 2 I AM AT", type(node), "node", node
return [self.__recursive_populate_tree(item) for item in node]

# If this is a leaf node, check if the leaf is a r/w tuple and substitute the
# read element of that tuple into the node
if isinstance(node, ParameterAccessor):
#print "POPULATE 3 I AM AT", type(node), "node", node
return node.get()

#print "POPULATE 4 I AM AT", type(node), "node", node
return node

# Replaces values in data_tree with values from new_data
Expand Down

0 comments on commit e5437a5

Please sign in to comment.