tkFileBrowser
tkFileBrowser copied to clipboard
Change the default sort order as a kwarg
The "Name", "Size", and "Modified" headings allow users to sort the displayed files in alphabetical, size, and last-modified date order, respectively. It seems that the default sort when the widget is created is alphabetical. I suggest adding some way to specify a different default sort order through the ask() methods or the FileBrowser constructor.
I am primarily using tkfilebrowser in homemade GUI tools to analyze experimental measurements - it would be much more convenient for me if these files were sorted recent-first. If I wanted an askopenfilenames() that does so, I could do the following to make that happen when the widget first opens up:
dialog = FileBrowser(mode="openfile", multiple_selection=True, title="Example title")
dialog._sort_by_date(reverse=True)
dialog.wait_window(dialog)
res = dialog.get_result()
if not res:
res = ()
but this will revert to alphabetical whenever I change directories. Overall, it would be much more intuitive to pass some default_sort= argument to have these _sort() methods called as needed.