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?
-
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?
-
@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)
-
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 FilesAnd 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...
-
-
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. -
-
@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.
-
Thanks for all the answers! I will try out the different ones and see which one works best. Cheers!
-
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?