diff --git a/ipyfilechooser/filechooser.py b/ipyfilechooser/filechooser.py index 2ea6c50..e63ae5c 100644 --- a/ipyfilechooser/filechooser.py +++ b/ipyfilechooser/filechooser.py @@ -45,6 +45,7 @@ class FileChooser(VBox, ValueWidget): show_hidden: bool = False, select_default: bool = False, dir_icon: Optional[str] = '\U0001F4C1 ', + dir_icon_append: bool = False, show_only_dirs: bool = False, filter_pattern: Optional[Sequence[str]] = None, sandbox_path: Optional[str] = None, @@ -68,6 +69,7 @@ class FileChooser(VBox, ValueWidget): self._change_desc = change_desc self._select_default = select_default self._dir_icon = dir_icon + self._dir_icon_append = dir_icon_append self._show_only_dirs = show_only_dirs self._filter_pattern = filter_pattern self._sandbox_path = normalize_path(sandbox_path) if sandbox_path is not None else None @@ -215,7 +217,7 @@ class FileChooser(VBox, ValueWidget): path, show_hidden=self._show_hidden, show_only_dirs=self._show_only_dirs, - dir_icon='', + dir_icon=None, filter_pattern=self._filter_pattern, top_path=self._sandbox_path ) @@ -226,6 +228,7 @@ class FileChooser(VBox, ValueWidget): show_hidden=self._show_hidden, show_only_dirs=self._show_only_dirs, dir_icon=self._dir_icon, + dir_icon_append=self._dir_icon_append, filter_pattern=self._filter_pattern, top_path=self._sandbox_path ) @@ -445,6 +448,17 @@ class FileChooser(VBox, ValueWidget): self._dir_icon = dir_icon self.refresh() + @property + def dir_icon_append(self) -> bool: + """Get dir icon value.""" + return self._dir_icon_append + + @dir_icon_append.setter + def dir_icon_append(self, dir_icon_append: bool) -> None: + """Prepend or append the dir icon.""" + self._dir_icon_append = dir_icon_append + self.refresh() + @property def rows(self) -> int: """Get current number of rows.""" diff --git a/ipyfilechooser/utils.py b/ipyfilechooser/utils.py index c0aca98..6f6e424 100644 --- a/ipyfilechooser/utils.py +++ b/ipyfilechooser/utils.py @@ -66,6 +66,7 @@ def get_dir_contents( show_hidden: bool = False, show_only_dirs: bool = False, dir_icon: Optional[str] = None, + dir_icon_append: bool = False, filter_pattern: Optional[Sequence[str]] = None, top_path: Optional[str] = None) -> List[str]: """Get directory contents.""" @@ -89,14 +90,19 @@ def get_dir_contents( if has_parent(strip_parent_path(path, top_path)): dirs.insert(0, os.pardir) if dir_icon: - return prepend_dir_icons(sorted(dirs), dir_icon) + sorted(files) + return prepend_dir_icons(sorted(dirs), dir_icon, dir_icon_append) + sorted(files) else: return sorted(dirs) + sorted(files) -def prepend_dir_icons(dir_list: Iterable[str], dir_icon: str) -> List[str]: +def prepend_dir_icons(dir_list: Iterable[str], dir_icon: str, dir_icon_append: bool = False) -> List[str]: """Prepend unicode folder icon to directory names.""" - return [f'{dir_icon}' + dirname for dirname in dir_list] + if dir_icon_append: + str_ = [dirname + f'{dir_icon}' for dirname in dir_list] + else: + str_ = [f'{dir_icon}' + dirname for dirname in dir_list] + + return str_ def get_drive_letters() -> List[str]: