MCPcopy Index your code
hub / github.com/rawpython/remi / populate_folder_items

Method populate_folder_items

remi/gui.py:3764–3807  ·  view source on GitHub ↗
(self, directory)

Source from the content-addressed store, hash-verified

3762 return self.selectionlist
3763
3764 def populate_folder_items(self, directory):
3765 def _sort_files(a, b):
3766 if os.path.isfile(a) and os.path.isdir(b):
3767 return 1
3768 elif os.path.isfile(b) and os.path.isdir(a):
3769 return -1
3770 else:
3771 try:
3772 if a[0] == '.':
3773 a = a[1:]
3774 if b[0] == '.':
3775 b = b[1:]
3776 return (1 if a.lower() > b.lower() else -1)
3777 except (IndexError, ValueError):
3778 return (1 if a > b else -1)
3779
3780 log.debug("FileFolderNavigator - populate_folder_items")
3781
3782 if pyLessThan3:
3783 directory = directory.decode('utf-8')
3784
3785 l = os.listdir(directory)
3786 l.sort(key=functools.cmp_to_key(_sort_files))
3787
3788 # used to restore a valid path after a wrong edit in the path editor
3789 self._last_valid_path = directory
3790 # we remove the container avoiding graphic update adding items
3791 # this speeds up the navigation
3792 self.remove_child(self.itemContainer)
3793 # creation of a new instance of a itemContainer
3794 self.itemContainer = Container(width='100%', height='100%')
3795 self.itemContainer.style.update({'overflow-y': 'scroll', 'overflow-x': 'hidden'})
3796
3797 for i in l:
3798 full_path = os.path.join(directory, i)
3799 is_folder = not os.path.isfile(full_path)
3800 if (not is_folder) and (not self.allow_file_selection):
3801 continue
3802 fi = FileFolderItem(full_path, i, is_folder)
3803 fi.onclick.connect(self.on_folder_item_click) # navigation purpose
3804 fi.onselection.connect(self.on_folder_item_selected) # selection purpose
3805 self.folderItems.append(fi)
3806 self.itemContainer.append(fi)
3807 self.append(self.itemContainer, key='items') # replace the old widget
3808
3809 def dir_go_back(self, widget):
3810 curpath = os.getcwd() # backup the path

Callers 1

chdirMethod · 0.95

Calls 6

ContainerClass · 0.85
FileFolderItemClass · 0.85
connectMethod · 0.80
remove_childMethod · 0.45
updateMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected