• benwiggy

    Brilliant! I told you I was confused about Path !!

    Excellent. Hopefully I should now be able to modify all my MacOS python scripts for PDFs along the same lines.

    Many thanks.

    posted in Pythonista read more
  • benwiggy

    import os
    from objc_util import *
    from pathlib import Path
    import dialogs
    PDFDocument = ObjCClass('PDFDocument')
    NSURL = ObjCClass('NSURL')
    home = "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/"
    def rotate(filename):
            shortName = Path(filename).stem
            outFilename = home + shortName + "+90.pdf"
            pdfURL = NSURL.fileURLWithPath_(filename)
            pdfDoc = PDFDocument.alloc().initWithURL_(pdfURL)
            if pdfDoc:
                pages = pdfDoc.pageCount()
                for p in range(0, pages):
                    page = pdfDoc.pageAtIndex_(p)
                    existingRotation = page.rotation()
                    newRotation = existingRotation + 90
                outFilename = Path(outFilename)
                print (outFilename)
    if __name__ == '__main__':
            filename = dialogs.pick_document(types=['public.data'])

    posted in Pythonista read more
  • benwiggy


    It's complaining about NSURL not having a string parameter for initFileURLWithPath when it crashes, but it doesn't complain about when writeToFile is commented out, which is weird.

    I'm trying to convert some MacOS PyObjC code into something that'll work here.

    Thanks for the example: I'll give it a try.

    posted in Pythonista read more
  • benwiggy

    I don't know what the cause is, but it only happens when I uncomment the writeToFile line.

    Is there a log somewhere?

    posted in Pythonista read more
  • benwiggy

    Ah. It's still crashing the app, though.

    posted in Pythonista read more
  • benwiggy

    Ah, I suspected that iOS's restrictions would be the cause. Yes, it's a tmp location path similar to yours.

    I suppose I'll just have to save everything to:

    /private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents

    posted in Pythonista read more
  • benwiggy

    I'm having trouble with the Path concept. I'm using the ObjC PDFDocument.writeToFile method, but it just crashes Pythonista.

    The relevant bit of code is:

            outFilename = pathlib.Path(outFilename)

    pdfDoc is a valid PDFDocument object, and outFilename is a path as a string. The location is Pythonistas own iCloud folder, copied from a dialogs.pick_document thing.

    posted in Pythonista read more
  • benwiggy

    Hello, I've just heard about Pythonista, and it sounds very exciting. I'm sure these are basic questions.

    It seems that you can import modules using pip, which is amazing.

    I use pyObjC on MacOS a lot. Will that code work (for APIs that are in both iOS and MacOS) if I import the pyObjC module? Or is pythonista's objc_util broadly compatible?


    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!