Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDFileManager sort_by function #1672

Open
grekichi opened this issue Apr 12, 2024 · 0 comments
Open

MDFileManager sort_by function #1672

grekichi opened this issue Apr 12, 2024 · 0 comments
Labels
Status: Needs analysis Issue needs to be analyzed if it's real

Comments

@grekichi
Copy link

Description of the Bug

Hi there !

I try to use MDFilemanager's 'sort_by' fucntion for file open command creation.
But I cannnot open files when I set 'date' and 'size' for 'sort_by'.
'name' and 'type' are no problem.

So I checked source data of 'MDFileManager'.
And I found out this cause as follows.
Return object are file name, not file path.

Is this the intended design or bug ?

Thanks in advance
Grekichi

Code and Logs

# About kivymd/uix/filemanager/filemanager.py

# from row no. 810

    def __sort_files(self, files):
        def sort_by_name(files):
            files.sort(key=locale.strxfrm)
            files.sort(key=str.casefold)
            return files

        if self.sort_by == "name":
            sorted_files = sort_by_name(files)
        elif self.sort_by == "date":
            _files = sort_by_name(files)
            _sorted_files = [os.path.join(self.current_path, f) for f in _files]
            _sorted_files.sort(key=os.path.getmtime, reverse=True)
            **sorted_files = [os.path.basename(f) for f in _sorted_files]** ←
        elif self.sort_by == "size":
            _files = sort_by_name(files)
            _sorted_files = [os.path.join(self.current_path, f) for f in _files]
            _sorted_files.sort(key=os.path.getsize, reverse=True)
            **sorted_files = [os.path.basename(f) for f in _sorted_files]** ←
        elif self.sort_by == "type":
            _files = sort_by_name(files)
            sorted_files = sorted(
                _files,
                key=lambda f: (os.path.splitext(f)[1], os.path.splitext(f)[0]),
            )
        else:
            sorted_files = files

# my idea:  "sorted_files = _sorted_files" instead of target rows

Versions

  • OS: macOS Monterey 12.7.4
  • Python: 3.10
  • KivyMD: 2.0.1.dev0
@HeaTTheatR HeaTTheatR added the Status: Needs analysis Issue needs to be analyzed if it's real label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs analysis Issue needs to be analyzed if it's real
Projects
None yet
Development

No branches or pull requests

2 participants