def main(self): F = npyscreen.Form(name="Testing Tree class", ) #wgtree = F.add(npyscreen.MLTree) wgtree = F.add(npyscreen.MLTreeMultiSelect) treedata = npyscreen.TreeData(content='Root', selectable=True, ignore_root=False) c1 = treedata.new_child(content='Child 1', selectable=True, selected=True) c2 = treedata.new_child(content='Child 2', selectable=True) g1 = c1.new_child(content='Grand-child 1', selectable=True) g2 = c1.new_child(content='Grand-child 2', selectable=True) g3 = c1.new_child(content='Grand-child 3') gg1 = g1.new_child(content='Great Grand-child 1', selectable=True) gg2 = g1.new_child(content='Great Grand-child 2', selectable=True) gg3 = g1.new_child(content='Great Grand-child 3') wgtree.values = treedata F.edit() global RETURN #RETURN = wgtree.values RETURN = wgtree.get_selected_objects()
def make_tree(self, parent=None, tree_dict=None, root_content='root'): root = parent or npyscreen.TreeData( content=root_content, selectable=True, ignore_root=False) parent = parent or root if not isinstance(tree_dict, dict): return root for key, value in tree_dict.iteritems(): if isinstance(value, dict): new_node = parent.new_child(content=key) self.make_tree(parent=new_node, tree_dict=value) elif isinstance(value, list): new_node = parent.new_child(content=key) for element in value: self.make_tree(parent=new_node, tree_dict=element) else: new_node = parent.new_child(content=key) return root
def create(self): super(SelectForm, self).create() self.tree = self.add(SelectFormTree) td = npyscreen.TreeData(content='Select one:', selectable=False, ignore_root=False) cobj = td.new_child(content='Contacts:', selectable=False) contacts = self.parentApp.configData.contacts for c in contacts: cobj.new_child(content='{} ({})'.format(c['name'], c['number'])) gobj = td.new_child(content='Groups:', selectable=True) groups = self.parentApp.configData.groups for g in groups: gobj.new_child( content='{} ({})'.format(g['name'], ', '.join(g['members']))) self.tree.values = td
def create(self): self.localTreeData = npyscreen.TreeData() walkToTree('.', self.localTreeData) self.localTree = self.add(npyscreen.MLTreeMultiSelect, name='Local Tree', value=self.localTreeData)