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.
File Browser question
-
Hi all, do you know a way to open Pythonista’s File Browser in a specific folder definied by user in the same way user can force Pythonista to open its python console directly from iphone home screen or to open a blank file to start writing a new script, regardless of the last Pythonista active window?
Thank you
Bye -
You could create a script that closes each tab, and place in pythonista_startup...
-
@Matteo Of course, it is more than possible that I don't understand your question, as usual 😢, but is this script, placed in startup, not helpful?
import editor,os local_path = os.path.expanduser('~/Documents/MyFolder/MyFile.py' editor.make_new_file(local_path)
-
@JonB Hi, I don't know which kind of commands could close tabs in Pythonista, but I don't want to close any opened tab because I might need them, I'm searching for a way to open file browser in a specific path defined by me in an external file in order to perform some quick operations on the files inside that folder/path using a key programmed with your great work on user_buttons bar. Can you give me some hints?
@cvp Hi, sorry but I don't want to edit any file, I ask if I can open Pythonista from iphone home screen (home shortcut) to open directly the Pythonista built-in file browser and go automatically in a specific path/folder where I find some useful files for my purposes (aka: I don't want to search for that folder, I want to go inside it with one single touch)
Thank you both,
Bye -
@Matteo I'm sure it should be possible because when we tap on
we set the File Browser in the folder of the edited file -
@cvp Hi thank you, sorry but I can't see the key number 2 of your image ( I have Pythonista 3.1) and I'd like to open only file browser in a specified path without opening any file (so without creating any new tab).
Thank you
Bye -
@Matteo The key 2 appears after having tapped key 1.
And it's only to show it should be possible because a key can do it. I don't say it's the solution of your problem -
@cvp ok, thank you for reply, unfortunately key #2 is not present in Pythonista I use : after touching key #1 I can only rename the file. Am I wrong with something?
And I understand your idea that if a built-in button/key can perform a task, this task should be performed also with a user script/key. At least in Pythonista app.Bye
-
@Matteo Here's a simple method to open a folder in the file browser programmatically:
import webbrowser webbrowser.open('pythonista3://Examples')
If your folder name includes characters that aren't allowed in a URL (e.g. spaces), you'll have to percent-encode them using
urllib.parse.quote()
. If your folder is in iCloud, append?root=icloud
at the end of the URL. -
@Matteo You're right, I'm in Pythonista V3.2, sorry. Hoping the answer of omz will help you.
-
@omz Hi thank you for your help, interesting use of webbrowser, unfortunately when I run the script it opens the Example folder but it is empty, no files inside, but I know that inside that folder I find all Pythonista built-in example scripts. I run your script with python 3.5.1.
Have you some ideas about this?
Thank you
Bye -
@Matteo Strange, with Pythonista 3.2, all is ok
-
@cvp So it is a feature of the new version 3.2, the 3.1 version has not this feature. Is it right?
As I do not want to update Pythonista for now, do you know some workaround using obj-c?
Note that I use Pythonista 3.1
Thank you
Bye -
-
@cvp Ok no problem, I was hoping my request was easy and available in version 3.1.
To upgrade to version 3.2 I'd like to know the name and version of each preinstalled library in 3.2, compared to 3.1. Sorry for this, but usually I don't upgrade any software/app if I don't know precisely what I will find in new version compared to old version. Even more if the app that I update is not uninstallable and replaceable with the old version, if I want to go back to the old version.
Thanks
Bye -
@Matteo Try, it's ok for me in V3.2
import webbrowser webbrowser.open('pythonista3://Examples/.')
-
Hi @cvp, thank you but it doesn't work in v3.1. Maybe no solution with 3.1.
Bye -
@Matteo 😢
-
@cvp No problem cvp, thank you anyway 😉😊
-
Hi, I was curious about the dot in your code and I ask if you know other symbols that have some similar effect, for example the symbol * (I don’t know if it exists in url scheme of Pythonista) for opening all files in a folder. The code could be:
import webbrowser webbrowser.open('pythonista://my-folder/*')
and this script could open all files .py inside my-folder (as result user will see each new tab for each file opened in the Pythonista text editor).
So do you know some other symbols and their effect in Pythonista url scheme like the dot
'.'
?I ask this because I discovered, based on your post, that if I have the following script in a folder named for example
'Documents/my-folder_01/my-folder_11/my-folder_12/'
('Documents' is the main folder of Pythonista, where user finds built-in folders like 'Examples' or 'Modules & Templates'):import webbrowser webbrowser.open('pythonista://.')
and I run this script, Pythonista v3.1 opens file browser and goes in the path where this script is saved.
Based on this, I tried to write this piece of code (script 'A'):
import webbrowser import os folder_path = os.path.expanduser('~/Documents/my-folder_01/my-folder_11/my-folder_12/') content_file = ''' import webbrowser webbrowser.open('pythonista://.') ''' with open(folder_path + '.folder.py', 'w') as f: f.write(content_file) webbrowser.open('pythonista://my-folder_01/my-folder_11/my-folder_12/.folder.py?action=run')
I saved this script in a folder named ‘Documents/Tests/’ (as example).
I tried to run it and magically (at least for me) Pythonista v3.1 opens instantly the folder
'Documents/my-folder_01/my-folder_11/my-folder_12/'
with its built-in file browser, allowing me to perform all the operation on files I need without searching manually that folder touching several times the screen of my iphone. To perform operation on files in the folder I use the JonB's user_key_bar script that allows user to create own keys in the top bar of Pythonista.
Obviously this method is good for me only if the folder doesn’t change, so when I don’t need to change path of 'folder_path' in script 'A'. But for now I need to perform the same file operations always in a constant folder.I know I could write a script that perform all this automatically, but I prefer to use file browser and JonB user_key_bar with my own actions because it is faster for me (I'm trying to use Pythonista also like a powerful programmable file browser, like a quite full and complete OS inside the quite closed and restricted iOS of iphone).
About what I discovered I ask:
- How can user show in Pythonista file browser all hidden file starting with a dot , like '.folder.py' in script 'A'? Maybe with an option in settings? Or a piece of code?
- How can user open a file (or several files at once) from file browser or from home screen of idevice without closing the current opened file in the active tab? I noticed that when I open a script, Pythonista opens it for editing closing the existing active tab (so no tab replacing but tab adding).
- How user can open and close tabs in editor programmatically (which commands)?
- How can user programmatically delete hidden files after the last line of code in script 'A' (in the example the hidden file is '.folder.py') inside the same script 'A'?
Note that I still use Pythonista v3.1.
Thank you
Bye