def __update_directory_list(self, update_layout=True): directory_path = self._current_path filenames = [] for ext in self._extensions.split(";"): pattern = "*" if ext == "*" else "*.{}".format(ext) names = glob( Filename(join(directory_path, pattern)).to_os_specific_w()) filenames.extend( Filename.from_os_specific_w(name).get_basename() for name in names if not Filename(name).is_directory()) dirlist = self._file_sys.scan_directory(directory_path) self._path_handler(directory_path) subdirnames = [] if dirlist: for item in dirlist: if item.is_directory(): subdirnames.append(item.get_filename().get_basename()) self._btns = btns = [] sizer = self.get_sizer() sizer.clear(destroy_items=True) FileButton.set_selected_filebutton(None) f = lambda x, y: (x.casefold() > y.casefold()) - (x.casefold() < y. casefold()) def get_command(dir_path): return lambda: self.set_directory(dir_path) for name in sorted(subdirnames, key=cmp_to_key(f)): path = join(directory_path, name) command = get_command(path) btns.append(FileButton(self, name, command=command, is_dir=True)) for name in sorted(filenames, key=cmp_to_key(f)): btns.append( FileButton(self, name, self._file_selection_handler, self._file_command)) count = Skin["options"]["file_row_count"] for column in (btns[i:i + count] for i in range(0, len(btns), count)): column_sizer = Sizer("vertical") sizer.add(column_sizer) for btn in column: column_sizer.add(btn, expand=True) if update_layout: self.update_layout()
def __update_directory_list(self, update_layout=True): directory_path = self._current_path filenames = [] for ext in self._extensions.split(";"): pattern = "*" if ext == "*" else f"*.{ext}" names = glob(Filename(join(directory_path, pattern)).to_os_specific_w()) filenames.extend(Filename.from_os_specific_w(name).get_basename() for name in names if not Filename(name).is_directory()) dirlist = self._file_sys.scan_directory(directory_path) self._path_handler(directory_path) subdirnames = [] if dirlist: for item in dirlist: if item.is_directory(): subdirnames.append(item.get_filename().get_basename()) self._btns = btns = [] sizer = self._btn_sizer sizer.clear(destroy_cells=True) FileButton.set_selected_filebutton(None) f = lambda x, y: (x.casefold() > y.casefold()) - (x.casefold() < y.casefold()) for name in sorted(subdirnames, key=cmp_to_key(f)): path = join(directory_path, name) command = lambda p=path: self.set_directory(p) btns.append(FileButton(self, name, command=command, is_dir=True)) for name in sorted(filenames, key=cmp_to_key(f)): btns.append(FileButton(self, name, self._file_selection_handler, self._file_command)) for btn in btns: sizer.add(btn) if update_layout: self.update_layout()