Forum Archive

filenav - a simple file navigator

dgelessus

(no, I couldn't think of a more original name.)

https://github.com/dgelessus/filenav

What is there to say? It's a file navigator with UI and a few neat features:

  • Quick access to a customizable list of favorite folders, including normally inaccessible ones
  • Automatic file icons based on extension
  • Thumbnails for most image files
  • Display of basic file attributes, such as size, creation/open/modification dates, owner/group
  • Analysis of file flags in a very derpy way
  • Easy opening of any file in Quick Look, the Pythonista editor, or any compatible app
  • Optional copying of files to a temporary folder before editing to avoid "accidents"
  • Optional renaming of files after copying to allow editing of unknown text files

Contributions are, of course, always welcome.

(Old link: http://github.com/dgelessus/pythonista-scripts/blob/master/filenav.py )

omz

This is quite impressive already!

briarfox

Looks great. Thanks for sharing it.

beer2011

Very useful.Thanks!
But.... Is this script too powerful?

briarfox

As a bonus it also seems to unlock pythonista's file browser. After running FileNav I can browse anywhere in pythonistas file viewer.

dgelessus

Wait, you can access other apps' data with it? Aren't they supposed to be sandboxed or something? I was aware of how to open the app bundle in Pythonista's file list (open a file outside the script library, quit the app and relaunch) but this is new to me.

briarfox

@dgelessus Sorry to mislead you. It just unlocks browsing in pythonista's folders. I was unaware that was possible.

dgelessus

Ah okay, that makes sense.

Anyway, update:

  • Added Quick Look and Open In to file actions menu
  • Added option to open a folder in Shellista (most forks work)
  • Added dynamic thumbnail icons for images (doesn't work with certain PNG files for unknown reasons)
  • Finished flag analysis for files and folders
  • Made external access easier and created a ShellistaExt plugin
  • Started work on caching file properies to improve efficiency, not yet fully implemented
  • Various minor additions, optimizations and fixes

As usual, the current version can be found here.

Also filenav seems to load large folders much faster than Pythonista's built-in browser.

briarfox

@dgelessus you may want to hold off on the shellistaExt plugin, Transistor1 is in the process of pushing the dev branch in shellista. This has a similar plugin system that I've updated shellistaExt's plugins for.

BTW great job.

dgelessus

New update:

  • Finished implementing file property caching system
  • Large folders take noticeably longer to load the first time, but are much faster afterwards
  • Fixed some PNG files not getting thumbnails
  • Thumbnails are now also cached
  • Added subtitles to file list entries, which contain file type and size
  • Used appropriate cell styles for stat views
  • Added formatting of file sizes and display of user names to stat views
  • Various minor fixes and improvements

As usual, the current version can be found here.

Also filenav no longer loads large folder much faster than Pythonista's built-in browser.

beer2011

@dgelessus

By 'Preview' operation, the following error was given.
Would you confirm it?

AttributeError: 'StatDataSource'
object has no attribute 'type'.

And it is hope for 'filenav', sorry....
I want a function such as 'the open file recently'.

Thank you.

dgelessus

Thanks for telling me, will fix that now. Looks like I forgot to change a few small things.

dgelessus

A few commits later:

  • A bunch of internal optimizations, thanks @ccc!
  • Special support for opening HTML, audio and image files
  • Conditional default actions depending on file type
  • Activity indicator while loading folders

(filenav.py)

dgelessus

http://github.com/dgelessus/filenav

After five months of doing nothing with it I got around to rearranging filenav's internals into a separate module, hopefully this will make writing a full iPad version easier. Few visible changes have happened, though there are a few new things:

  • The starting folder is a favorites list loaded from a JSON file, which has a few common locations in it by default.
  • Favorites can be moved and deleted from the UI, new ones can currently only be added by editing the JSON directly.
  • This once again makes it possible to access the Pythonista.app bundle, even in the 1.6 beta!
  • Slightly better command line support.

Under-the-hood changes:

  • No more use of globals, instead a FilenavApp object is used to store data and is available under the app attribute of all data sources.
  • FilenavApp also serves as a common interface to the two versions of filenav (once both of them exist).
  • The FileItem class should be slightly cleaner, there were a few things I wrote strangely...
  • And the usual uninteresting improvements and fixes here and there.

There's probably still the odd bug here and there, if you happen to find one, please report it here or on GitHub. Pull requests are also welcome, as usual.

mncfre

Hi @dgelessus I put all the files in a folder called filename but when I hit play it say "ImportError: No module named filenav" when trying to import common

mncfre

Hi @dgelessus forget it, I didn't import all the files

mncfre

@dgelessus I don't know how the edit button works, I press it and then press a file or folder an nothing happens, i'm on an iphone 5

dgelessus

At the moment the edit button does nothing in folder view. In the favorites list you can use it to move and delete favorites.

mncfre

Thanks @dgelessus, it would be great add the possibility of delete and move files and folders, zip and unzip files. Great software congrats

wradcliffe

I love the full 'panel" view implementation. I would be cool if you could find a way to auto scroll to any newly opened views.

Bug: Quick Look Preview "Done" button does nothing and system is hung.

I tried switching slim over to 'panel' and it does not work the same. I got it to crash once.

Thanks also for providing litenav. This is a really great example app for the NavigationView.

dgelessus

I'm aware that Quick Look (or any other function that overlays a second UI) causes Pythonista to hang in panel view, but there's unfortunately nothing I can do about that. Views presented in panel mode do not respond to the close method as they should, so there is no way to hide filenav before opening the quick look sheet.

Automatic scrolling is a good idea and should be easy to add, thanks for the suggestion.

dgelessus

The favorites list now has a "plus" button to add new favorites from the UI, no need to edit favorites.json anymore. It shouldn't be too hard to implement this for folder views as well to create new files/folders.

Known problem - it is impossible to use list reordering controls in a panel view. Dragging a move handle is registered as a horizontal swipe to switch between console and editor, which cancels the list item dragging. @omz this is most likely bug in Pythonista, I've experienced it previously with table views in sidebar mode.

cynicuss

Zip files on Ipad?

I am using Pythonista on an Ipad Air for an introductory Python course. I am new to programming and to apple products (the tablet is my wife's) and am bewildered by the lack of a file handling utility. I am stubbornly determined to figure this all out.

I attempted to download the following in order access a problem set for the course:

https://courses.edx.org/c4x/MITx/6.00.1x_5/asset/ProblemSet4.zip

No sucess to either Dropbox or Google Drive. Would filenav be able to do that? Or do I need to get an app like Goodreader? And please let me know if this is the right forum to be asking this.
Thank you @dgelessus

JonB

Dgelessus- yeah, that's a pet peeve of mine (I wish just the title bar switched to editor, since touch_moved are off limits in panel. ) I have noticed some other components, like scrollbar do correctly capture the touch move, as long as the touch is a certain distance away from the edge of the screen. Have you tried moving the component away from the edge ?

JonB

Cynicuss:
I'd recommend installing stash, by copying the getstash script and running it. If you add at all comfortable with the commandline, this has a ton of feature.

Otherwise, you can always download a file using urllib.urlretrieve, and use other python libs to unzip...

In stash, downloading from a url would be

wget https://courses.edx.org/c4x/MITx/6.00.1x_5/asset/ProblemSet4.zip

After which you can use the unzip command on the downloaded file.

dgelessus

Filenav doesn't have any un/zipping capabilities at the moment, though there are a few other scripts that can do that. If you know the basics of how to use a shell, StaSh is probably the easiest way. An external app like GoodReader is usually not a good choice if you want to get the files back into Pythonista - there's no way to pass entire folders or multiple files between apps, and Pythonista is not allowed to accept files via "open in" because of Apple's app review guidelines.

ccc

@cynicuss, I used StaSH:

Just copy and paste the get_stash.py code into Pythonista and run it to download and build StaSH. Then run stash.py and...

StaSh v0.4.0
[~/Documents]$ mkdir MITx
[~/Documents]$ cd MITx
[MITx]$ wget https://courses.edx.org/c4x/MITx/6.00.1x_5/asset/ProblemSet4.zip
[MITx]$ unzip *
[MITx]$ cd ProblemSet4
[ProblemSet4]$ ls
ps4a.py ps4b.py test_ps4a.py words.txt
cynicuss

Thank you people. I installed StaSH and am reminded of how ignorant I am of the cmd line. The blessing is that this amazing piece of work will force me to figure it out. Live, lose, and learn!
Thanks again.

dgelessus

So I just updated filenav to be compatible with Pythonista 3. Hopefully it'll be useful for snooping around in Pythonista internals until stash is updated (which might take a while, considering how much more complex it is).

Phuket2

@dgelessus , just installed in on v2.x , it's very impressive and really a must have if you are new to this file system.
However the name is very unassuming for how full featured it is.

ywangd

@dgelessus said:

So I just updated filenav to be compatible with Pythonista 3. Hopefully it'll be useful for snooping around in Pythonista internals until stash is updated (which might take a while, considering how much more complex it is).

It may take a while before StaSh is ready for Python 3. Honestly I am not even sure I want to do that. So far I have zero use case for Python 3. I am lack of both experience and incentive ...

Webmaster4o

@ywangd I really think you should try to make it Python 3 ready. It's really an essential and very useful tool for Pythonista. Even if you don't plan to migrate to Pythonista 3, I think most of the community does. I would be willing, as I'm sure most would, to help in some small way. Much of the problems with Python 3 StaSh could be fixed by lib2to3

dgelessus

@ywangd There's no excuse for staying on Python 2 now that Pythonista supports Python 3. ;) Okay, most user scripts are not Python 3-compatible, but in most cases it isn't hard to "update" a script to Python 3. There is also lib2to3 which can do most of the work for you. Stash is one of the largest Pythonista projects out there, so that will of course be a little more difficult than the average script.

wradcliffe

We need to figure this out since Stash is now a vital component of Pythonista IMHO. I really believe that it should be included with the core package since it is that important to everyday workflow. There are just some many simple things your can do in Stash that could take hours to accomplish in the UI.

ywangd

I read a bit on how to port Python 2 code. It seems that 2to3 is a convenient tool to make the code Python 3 compatible, but the code will then become not compatible with Python 2.

Ideally, I'd like to have a single code base that is compatible for both Python 2 and 3. There are tools as well but needs more human intervention. Anyway I'll attempt to have single code base first. If this proves to be difficult, I'll fall back to have separate code base for 2 and 3.

JonB

Supposedly the six module is a good way to help keep one codebase that works with 2.x and 3.x..

though, this was always my fear with a too early switch to 3.x though.... rather than fix bugs or adding new features it seems like omz, ywangd and others will have to expend a certain amount of energy getting things to work with 3.x and maintaining possibly multiple codebases.

One crucial question: will the pythonista modules have the same api in both versions? Will there be differences in ctypes, objc, etc?

dgelessus

A while back I think I tried to make stash use Unicode strings whereever possible, so non-ASCII characters are handled correctly and for eventual Python 3 forward compatibility. I think I got stuck when ConfigParser was unable to work with Unicode in Python 2. I'm trying to look into this again, though the stash codebase has grown and changed a lot since I last worked on it, so I may be the wrong person to attempt this.

ywangd

I have passed all the files through two porting tools, futurize and python-modernize and the code is now pushed as the py3 branch.

The codebase is mostly just processed by tools without any manual checking. So I doubt it would just run with Python 3 or even Python 2. But it serves as a starting point nonetheless.

@dgelessus sorry for hijack your thread. I'll post update on this thread onwards.