The list is populated fine and to test if the the tree item is pointing to the right directory, I'm passing a string containing the path to a method attached to the control. The string is printed when the tree item is selected but I'm getting the last value assigned in the loop instead. I have this same path set to be printed during the for loop that adds the items to the treeView and that output is correct but not when called from interacting with the UI? Am I making a noobie mistake?
Code:
# Other class methods above def folderContents(self , parentLayout): ''' loops through all tabs in list, creating folder trees ''' # let's start looping through tab list for label in self.tabs: self.tabForm = mc.formLayout(p = parentLayout) self.masterTab = mc.tabLayout(parentLayout, e = True , tl = (self.tabForm, label)) self.folderTree = mc.treeView((label + "_scrollList") ,numberOfButtons = 1 , arp = 0 , enk = 1) mc.formLayout(self.tabForm , e = 1 , af = [(self.folderTree , "left" , 0), (self.folderTree , "right" , 0), (self.folderTree , "top" , 0), (self.folderTree , "bottom" , 0)]) # get all files and subfolders for dirName, subdirList, fileList in os.walk(self.mainPath + label): # get folder name to use as label for tree item self.folderName = os.path.basename(os.path.normpath(dirName)) # however, if the the folder name starts with a . or _ , ommit it if not (self.folderName.startswith('.') or self.folderName.startswith('_')): # check if there is already an item with that name, if true, prefix lable with parent folder's name self.parentName = os.path.basename(os.path.dirname(dirName)) if mc.treeView(self.folderTree , q = 1 , iex = self.folderName): self.folderName = (self.parentName "_" + self.folderName) # going to be passing folder path to method that creates folder's content ctrls self.path = (dirName + "\\") # now let's start adding items to the treeView mc.treeView( self.folderTree, e = 1 , ai = (self.folderName , self.parentName)) # edit the tree entry after establishing it or face errors yay - adding select change command and icon mc.treeView( self.folderTree, e = 1 , i = [self.folderName, 1, self.folderIcon ] , scc = lambda:self.updateThumbList(self.path , self.folderName)) # tidy things up a bit ,collapse subfolders of the parent category if not self.folderName in self.tabs: mc.treeView( self.folderTree, e = 1 , ei = [self.folderName, 0]) # making sure tree item points to correct path print("folder \"" + self.folderName + "\" is at " + self.path) def updateThumbList(self , path , folderName): ''' populates thumbnail layout for a given folder >.> if it ever works for now, test if ctrl points to right path ''' print("folder " + folderName + " is at " + path) return ""