def add_node(self, name=None, id=None, flag=0, expanded_icon=None, collapsed_icon=None, selected=False, expanded=False, full_parent_id=()): """overridden method (Tree)""" Tree.add_node(self, name, id, flag, expanded_icon, collapsed_icon) fullParentPath = self.separater.join(full_parent_id) if fullParentPath not in self.savedNodesMap.keys(): self.savedNodesMap[fullParentPath] = [] savedNode = self._getSavedNode(fullParentPath, name) if savedNode is not None: self.new_nodes[-1].selected = savedNode.selected self.new_nodes[-1].expanded = savedNode.expanded return savedParentNode = self._getSavedNode(self.separater.join(full_parent_id[0:len(full_parent_id) - 1]), full_parent_id[-1]) node = Struct() node.name = name node.expandable = flag node.fullPath = self.separater.join(full_parent_id + (id,)) node.expanded = expanded node.selected = savedParentNode.selected self.savedNodesMap[fullParentPath].append(node) self.new_nodes[-1].selected = node.selected self.new_nodes[-1].expanded = node.expanded
def __init__(self, master, root_id, root_label='', get_contents_callback=None, dist_x=15, dist_y=15, text_offset=10, line_flag=1, expanded_icon=None, collapsed_icon=None, regular_icon=None, plus_icon=None, minus_icon=None, unchecked_icon=None, checked_icon=None, greyed_checked_icon=None,node_class=MultiSelectNode, drop_callback=None, node_select_callback=None, *args, **kw_args): self.separater = ' -> ' self.pos = None self.rootId = root_id self.realDistX = dist_x self.nodeSelectCallback = node_select_callback if checked_icon == None: self.checkedIcon=PhotoImage(file='checkedIcon.gif') else: self.checkedIcon=checked_icon if unchecked_icon == None: self.uncheckedIcon=PhotoImage(file='uncheckedIcon.gif') else: self.uncheckedIcon=unchecked_icon if greyed_checked_icon == None: self.greyedCheckedIcon=PhotoImage(file='greyedIcon.gif') else: self.greyedCheckedIcon=greyed_checked_icon if get_contents_callback == None: get_contents_callback = self._getContents savedNode = Struct() savedNode.name = self.rootId savedNode.expandable = True savedNode.fullPath = self.rootId savedNode.expanded = False savedNode.selected = False # This structure is used to remember selected nodes and their selected/expanded states self.savedNodesMap = {'': [savedNode], savedNode.fullPath: []} Tree.__init__(self, master, root_id, root_label, get_contents_callback, dist_x * 2, dist_y, text_offset, line_flag, expanded_icon, collapsed_icon, regular_icon, plus_icon, minus_icon, node_class, drop_callback, *args, **kw_args)
def createNode(self, name, expandable, parentFullId, expanded, selected): node = Struct() node.name = name node.expandable = expandable node.fullPath = self.separater.join(parentFullId + (node.name,)) node.expanded = expanded node.selected = selected self.savedNodesMap[self.separater.join(parentFullId)].append(node) grandParentPath = self.separater.join(parentFullId[:-1]) parentSavedNode = self._getSavedNode(grandParentPath, parentFullId[-1]) parentSavedNode.expandable = True parentSavedNode.expanded = True self.savedNodesMap[node.fullPath] = []
def createDummyTree(self): node = Struct() node.name = 'Analytics' node.expandable = True node.fullPath = self.separater.join((self.rootId, node.name)) node.expanded = False node.selected = False self.savedNodesMap[self.rootId] = [node] node = Struct() node.name = 'Master Admin' node.expandable = False node.fullPath = self.separater.join((self.rootId, node.name)) node.expanded = False node.selected = False self.savedNodesMap[self.rootId].append(node) self.savedNodesMap[self.separater.join((self.rootId, 'Analytics'))] = [] node = Struct() node.name = 'Some test case' node.fullPath = self.separater.join((self.rootId, 'Analytics', node.name)) node.expandable = False node.expanded = False node.selected = False self.savedNodesMap[self.separater.join((self.rootId, 'Analytics'))].append(node) node = Struct() node.name = 'testing' node.fullPath = self.separater.join((self.rootId, 'Analytics', node.name)) node.expandable = True node.expanded = False node.selected = False self.savedNodesMap[self.separater.join((self.rootId, 'Analytics'))].append(node) node = Struct() node.name = 'Some test case' node.fullPath = self.separater.join((self.rootId, 'Analytics', 'testing', node.name)) node.expandable = False node.expanded = False node.selected = False self.savedNodesMap[self.separater.join((self.rootId, 'Analytics', 'testing'))] = [node]