Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
dialogs.pick_document() with custom file extensions
-
Hi,
in my pythonista app I want to load a file.
I found the pythonista std file picker API in dialogs.pick_document(types=['public.data']).
import dialogs result = dialogs.pick_document(types=['public.data'])
This code opens a file picker diaolog. But unfortunately only certain file types can be selected in this dialog.
I want to select files with the extension '.SID' But these files are grayed out.
How can I achieve this ?
with best regards
-
@mithrendal I personally use this file picker
-
@cvp thank you for your hint. But unfortunately your referenced file picker is not the standard ios file picker. Therefore you can only pick files within the pythonista app itself.
The one in the dialogs package brings up the iOS system wide file picker and it lets you browse throughout all your apps of your iOS-Device even including your iCloud documents.
But I can't select some of them. In fact I don't know how to handle the types parameter from dialogs.pick_document() ... The internal pythonista documentation says
dialogs.pick_document(types=['public.data']) Show the system’s document picker for importing a file, and return the file’s path (or None if the dialog is canceled). types specifies the Universal Type Identifiers (UTIs) that should be selectable in the document picker. The default (['public.data']) makes all regular files selectable. A list of the system-defined UTIs are available in Apple’s Uniform Type Identifiers Reference. The return value is a temporary file. You can read it directly, but to keep a permanent copy, you must move it somewhere else.
Apple has this documentation declaring new type identifiers. But its hard for me to get the clue how that correspondents to the type parameter of dialogs.pick_document(...)
-
@mithrendal Sorry, my fault, forget it
-
hey @cvp your tip was very welcome !! ;-)
in the meantime I did some testing on more devices and it showed that only one iPhone device had this problem. e.g. it can not select certain files for whatever reason ...
I did the test on two other devices and there the standard filepicker worked like a charm. I can pick whatever file type I like and read the file into pythonistas memory, even though it does not reside in pythonistas app document space ...
import dialogs file = dialogs.pick_document() f = open(file,'rb') content = f.read()
-
Does it have something to do with which apps the files are stored in? On my device (iPhone SE, iOS 10.3.3)
dialogs.pick_document()
lets me pick any file from most apps (including files in the "main" iCloud Drive part that is not in any app folder), but in some apps (for example Pages) no files can be selected at all. -
@mithrendal Try, in Pythonista bottom left, the + button, then "import", then "files" and all files are available for importation, even files who are grayed with the "open external files" which is the same as "dialogs.pick_document".
-
@mithrendal Please try
dialogs.pick_document(types=['public.item'])
-
@omz Thank you, that is the solution I was looking for. Now my custom file types can be opened from an iCloud folder from all of my devices.
I just replaced 'public.data' with 'public.item' as Ole said. With 'public.data' it did not work on an icloud drive on some devices.
Thank you so much ;-)