I think Pythonista is really missing something very beneficial in a built-in scriptable file navigator. The one that's inside the "move" dialog is really nice, but only supports folders, and plus, it's not user-accessible.
I think Pythonista should have a
filenav module that allows for easy creation of nice file navigators. They're pretty hard to write, IMHO, and so could benefit from being built-in. How I envision this is as follows:
filenav module that provides file browsers and navigators.
- Higher-level functions for picking files with callbacks. A function that would allow for picking files and folders. Something like:
def pick_file(start_dir, folders_only=False, select_multiple=False, should_pick="both")
should_pick is a string that describes what should be selectable,
folders_only is whether the file picker should only display folders, and hide files from view.
2. A subclassable class like
filenav.FilePicker. This would serve important functions:
- Allow users to implement custom methods for file browsing. Users could define methods for listing directories, etc. A (far from complete) example:
'''Should return a list of files and directories below a directory as a dictionary'''
list = os.listdir(dir)
dirs = [f for f in list if os.path.isdir(os.path.abspath(f))]
files = set(list)-set(dirs)
'''Called with the path of a file whenever a file is selected'''
'''Called with the path of a directory whenever a directory is selected'''
#Picked will be a list of both files and directories that the user picked out of test_dir/a/b/c
picked = a.pick_file(multiple=True,should_pick='both')
This doesn't immediately seem useful, but has tons of practical applications. For example, it would be easy, using a class like this, to create methods that would make a file browser for zip files. Using
zipfile, custom methods could be created that allowed browsing through zip files without extracting first. This would allow a pythonista app to let users to pick certain files to extract from a zip.
These two functionalities combined could help create a scriptable file browser that's easy for beginners, yet hugely powerful for more advanced users.
I'd very much like to see a built-in file browser with these features in a future release.
P.S. I actually have struggled to create a zip file browser in Pythonista in the past. I've gotten this far on GitHub, and Here's a sideways YouTube video