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.


    Pythonista app saving to iOS 11 Files?

    Pythonista
    4
    9
    11740
    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.
    • superrune
      superrune last edited by

      Hi! Pardon me if this has been asked, I could not find it in the search.

      I have made a drawing app that is working quite well. One thing I have not solved is the loading and saving of images, and instead of loading and saving from Camera Roll, I thought it would be better to save them to iCloud or Dropbox. Can Pythonista open a file requester to let the user save to the new Files system in iOS 11?

      Phuket2 1 Reply Last reply Reply Quote 1
      • Phuket2
        Phuket2 @superrune last edited by

        @superrune , this is not your full answer. But the below is something I did some time ago. I think for the write, gives you an idea. Not sure you are on the beta program or not. But if you are on the beta program the file would be saved to Icloud as the path will exist. Otherwise it will create the image in the script dir.

        This example renders a simple image to a ui.View, console and writes the image to a file. Does not do the read. But this is a basic framework.

        import ui
        import os.path
        
        icloud_path='/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/'
        
        class DrawSomething(ui.View):
            rect = (0, 0, 200, 200)
        
            def draw(self):
                self.my_draw()
        
            def my_draw(self):
                with ui.GState():
                    ui.set_color('deeppink')
                    shape = ui.Path.rect(*self.rect)
                    shape.fill()
        
            def image_get(self):
                with ui.ImageContext(self.rect[2], self.rect[3]) as ctx:
                    self.my_draw()
                    img = ctx.get_image()
                    return img
        
            def image_save(self, path):
                img = self.image_get()
                with open(path, 'wb') as file:
                    file.write(img.to_png())
        
        if __name__ == '__main__':
            img_fn = 'junk.png'
            if os.path.exists(icloud_path):
                img_fn = os.path.join(icloud_path, img_fn)
                
            ds = DrawSomething()
            ds.present('sheet')
            ds.image_save(img_fn)
            ds.image_get().show()
            print(img_fn)
        
        1 Reply Last reply Reply Quote 1
        • cvp
          cvp last edited by

          It's very strange but I have the Pythonista version from the App Store (not the beta);and I've remarked today that I can, in Pythonista, do:
          Edit (in the left browser)
          Select any file, even a .py
          Share
          Save in Files

          And my Pythonista file is really saved where I want, for instance in "On my iPad" or in "iCloud Drive"

          I don't see that before...

          Phuket2 1 Reply Last reply Reply Quote 1
          • Phuket2
            Phuket2 @cvp last edited by

            @cvp , I doubt it's connected. But look at my last post here

            cvp 1 Reply Last reply Reply Quote 0
            • omz
              omz last edited by

              The easiest way to export a file programmatically would be to use console.open_in(some_file). You'll get a menu that includes a “Save to Files” option (on iOS 11 at least). This doesn’t require the beta, and should even work in Pythonista 2.x.

              cvp 1 Reply Last reply Reply Quote 2
              • cvp
                cvp @Phuket2 last edited by

                @Phuket2 It is connected, exactly like @omz explained in his post

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

                  @omz What could be marvelous is to be able to limit the apps list of the "open in" at only one ap, like Workflow already did in the past.

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

                    Thanks for all the answers! I will try out the different ones and see which one works best. Cheers!

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

                      Using console.open_in(filename) worked great. Took some attempts before I realized I had to write the file locally/inside Pythonista first :)

                      Is there an equally simple way to programmatically load a file from a selection of sources, like Dropbox, iCloud etc?

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