omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    4
    27
    16340
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Matteo
      Matteo @omz last edited by

      @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

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @Matteo last edited by

        @Matteo Strange, with Pythonista 3.2, all is ok

        Matteo 1 Reply Last reply Reply Quote 0
        • Matteo
          Matteo @cvp last edited by

          @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 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @Matteo last edited by

            @Matteo I think I can't help you because I don't have anymore 3.1 and I think (not sure) that objective-c could not not help because Pythonista web/file browser is Pythonista feature.
            Of course, @omz could help you a million times better than me.

            Matteo 1 Reply Last reply Reply Quote 0
            • Matteo
              Matteo @cvp last edited by

              @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

              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @Matteo last edited by cvp

                @Matteo Try, it's ok for me in V3.2

                import webbrowser
                webbrowser.open('pythonista3://Examples/.')
                
                Matteo 1 Reply Last reply Reply Quote 0
                • Matteo
                  Matteo @cvp last edited by

                  Hi @cvp, thank you but it doesn't work in v3.1. Maybe no solution with 3.1.
                  Bye

                  cvp 1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @Matteo last edited by

                    @Matteo 😢

                    Matteo 1 Reply Last reply Reply Quote 0
                    • Matteo
                      Matteo @cvp last edited by

                      @cvp No problem cvp, thank you anyway 😉😊

                      1 Reply Last reply Reply Quote 0
                      • Matteo
                        Matteo last edited by Matteo

                        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:

                        1. 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?
                        2. 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).
                        3. How user can open and close tabs in editor programmatically (which commands)?
                        4. 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

                        cvp 3 Replies Last reply Reply Quote 0
                        • cvp
                          cvp @Matteo last edited by cvp

                          @Matteo Every directory contains a . and a .. entry. (in Unix, Windows, etc...)

                          . means the directory itself. It is called the current directory.

                          .. means the directory's parent directory, that is, the directory that contains it.

                          1 Reply Last reply Reply Quote 0
                          • cvp
                            cvp @Matteo last edited by

                            @Matteo to delete the file at end of your script

                            Import os
                            os.remove(folder_path+'.folder.py')
                            
                            1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @Matteo last edited by

                              @Matteo I think that it is not "magically". When you run a script, Pythonista opens its folder, thus...

                              Matteo 1 Reply Last reply Reply Quote 0
                              • Matteo
                                Matteo @cvp last edited by Matteo

                                @cvp Hi , thank you for reply: 'magically' because in previous posts we read that omz solution works only in version 3.2, when I run it in v3.1 I obtain a blank folder, even if I'm sure I have some files inside it.

                                After my last post I can open any folder programmatically also in v3.1 (it is not elegant because the solution I found needs to create a new file inside the folder where I want to go with file browser and in order to not see it I must hide it with a dot at the beginning of filename).

                                Thank you also for deleting hint, unfortunately when I add:

                                import os
                                os.remove(folder_path + '.folder.py')
                                

                                after

                                
                                webbrowser.open('pythonista://my-folder_01/my-folder_11/my-folder_12/.folder.py?action=run')
                                

                                of script 'A', the script doesn't work as expected, because it deletes the file '.folder.py' even before that the istruction

                                webbrowser.open('pythonista://my-folder_01/my-folder_11/my-folder_12/.folder.py?action=run')
                                

                                is executed.

                                Have you some other ideas about deleting a file named 'B' after a webbrowser.open use that needs the file 'B'?

                                Thank you
                                Bye

                                cvp 1 Reply Last reply Reply Quote 0
                                • cvp
                                  cvp @Matteo last edited by cvp

                                  @Matteo The script of omz did open a folder, your script runs a script, that makes the magic difference.

                                  Put a little sleep after webbrowser.open to let it time to perform its action before the remove

                                  import time
                                  time.sleep(0.2)
                                  
                                  Matteo 1 Reply Last reply Reply Quote 1
                                  • Matteo
                                    Matteo @cvp last edited by

                                    @cvp It works! Thank you, sometimes sleeping is good, also for a code ;-)
                                    Bye

                                    cvp 1 Reply Last reply Reply Quote 0
                                    • cvp
                                      cvp @Matteo last edited by

                                      @Matteo Surely when the work is done during your sleep 😂

                                      1 Reply Last reply Reply Quote 0
                                      • First post
                                        Last post
                                      Powered by NodeBB Forums | Contributors