• cvp

    @ihf V01.04 and outline.versions with

    Version V01.04
      - correction of bug "keyboard was disappearing after an enter 
        to create a new outline row"
    

    This bug was not so old, it should have appeared from V00.96 when I removed the undo/redo process and a part of this process variables is checked for cursor process.

    posted in Pythonista read more
  • cvp

    @ihf said:

    when I type a new outline item, and I hit the return, the keyboard disappears. I think it would be better if the keyboard remained so that you could continue typing since you are positioned on the next outline line. Does that make sense?

    Yes sir. I had remarked this problem yesterday, sorry for you. I'll try to correct it tomorrow.
    That should be an old bug and I can't remember if I have already tried to solve it, and if yes, obviously without success

    posted in Pythonista read more
  • cvp

    @sgspecker This allows to create a new photo with updated caption in camera roll if you share an existing photo which has already a caption

    import appex
    import console
    import os
    import photos
    
    def main():
        if appex.is_running_extension():
            fil = appex.get_attachments()[0]
        else:
            fil = 'a.jpg' 
        with open(fil, mode='rb') as fin:
            b = fin.read()
            #b'\xff\xed\xllllPhotoshop 3.0\x00' = marker APP1 
            #           -----
            #b'8BIM\x04\x04\x00\x00\x00\x00\x00\x17\x1c\x01Z\x00\x03\x1b%G\x1c\x02\x0\x0\x02
            #                                   ---
            #b'\x00\x02\x1c\x02x\x00\x03Cap\x00
            ip = b.find(b'Photoshop')
            if ip >= 0:
                #print(b[ip-6:ip+100])
                lip = int.from_bytes(b[ip-2:ip], "big")   
                i8 = b.find(b'8BIM',ip)
                if i8 >= 0:
                        l8 = int.from_bytes(b[i8+10:i8+12], "big")   
                        i = b.find(b'\x1c\x02x', i8)                    
                        # caption field identified by x'1c0278' then length in 2 bytes x'0005' = 5
                        l = int.from_bytes(b[i+3:i+5], "big")   
                        caption = b[i+5:i+5+l].decode("utf-8") 
                        #print(caption)
                        #return # if no update
                        # 
                        caption = console.input_alert('new caption?','', caption, 'ok', hide_cancel_button=True)
                        lu = len(caption)
                        bl = lu.to_bytes(2,'big')   # x'000l'
                        # store new caption
                        b = b[:i+3] + bl + caption.encode('utf-8') + b[i+5+l:]
                        # change length of 8BIM marker
                        l8aft = l8 - l + lu
                        bl8aft = l8aft.to_bytes(2,'big')    # x'000l'
                        b = b[:i8+10] + bl8aft + b[i8+12:]
                        # change length of Photoshop marker at ip-2
                        lipaft = lip - l + lu
                        blaft = lipaft.to_bytes(2,'big')    # x'000l'
                        b = b[:ip-2] + blaft + b[ip:]
        tmp = '_temp.jpg'
        with open(tmp, mode='wb') as fout:
            fout.write(b)
        asset = photos.create_image_asset(tmp)
        os.remove(tmp)
        appex.finish()
    
    if __name__ == '__main__':
        main()
    

    posted in Pythonista read more
  • cvp

    @JonB said:

    are you holding onto a reference to the text view itself?

    No but I store the TableView row into the InputAccessoryView. Then, when a key is pressed in the supplementary keyboard row, I can call textview_should_change with the right row which is the index in TableView. And I don't need anything more, even the TextView it-self.

    posted in Pythonista read more
  • cvp

    @JonB sorry, never seen this post. I'm in holidays for some days. i'll answer this weekend

    posted in Pythonista read more
  • cvp

    @sgspecker here how to get the caption

    from PIL import Image
    import appex
    fil = appex.get_attachments()[0]
    with Image.open(fil) as im:
        for segment, content in im.applist:
            if content.startswith(b'Photoshop'):
                # caption field identified by x1c0278 then length in 2 bytes x'0005' = 5
                i = content.find(b'\x1c\x02\x78')
                l = int.from_bytes(content[i+3:i+5], "big")   
                caption = content[i+5:i+5+l].decode("utf-8") 
                print(caption)
                break
    

    posted in Pythonista read more
  • cvp

    @JonB I didn't think to update it, I was already happy to find a begin of way to get the caption.

    I think these infos are not stored in the photo file.
    If I import the same photo in Pythonista, these data are no more there.

    posted in Pythonista read more
  • cvp

    @sgspecker First of all, I don't know anything about this matter, BUT, after some Google searches and a lot of tests, I've discovered that the caption is passed into the shared asset.
    Try to share a photo where you have typed a caption to this little Pythonista script.

    @JonB never say never 😀

    For your info, it is not stored in the EXIF's but in the IPTC fields.

    from PIL import Image
    import appex
    fil = appex.get_attachments()[0]
    with Image.open(fil) as im:
        for segment, content in im.applist:
            if content.startswith(b'Photoshop'):
                print(f"segment={segment}, content=Photoshop...")
                ls = content.split(b'\x00')
                for l in ls:
                    print(l)
    

    You will find in the output the caption you typed. I don't yet know how to identify the right field where it is stored, but it should be possible to do it.

    posted in Pythonista read more
  • cvp

    @ihf said:

    The menu that permits setting bold, italic, etc. is no longer coming up.

    You know that some text needs to be selected first.
    If so, and you select "bold..." in the popup menu, that works.
    But the "bold" key does not work.

    It seems that from V01.01 where I had put a modification to share the same InputAccessoryView for all rows prevents the keys of keyboard extra row to work. Not only the "bold" key but also promote
    and demote keys.

    Thus next version will remove this modification.

    V01.03 and outline.versions with

    Version V01.03
      - remove sharing of one InputAccessoryView (set V01.01) which prevent keys of
        keyboard extra row to work
    

    posted in Pythonista read more
  • cvp

    @ihf V01.02 and outline.versions with

    Version V01.02
      - check if all imported modules exist and, if not, print their list
        and url's where to find them
    

    Not sure all are there but wait and see with first new user.

    Added in my todo list to automatically download missing ones but not for coming days.

    List is

    Needed files
    ============
    SetTextFieldPad.py at https://github.com/cvpe/Pythonista-scripts/blob/master/SetTextFieldPad.py
    File_Picker.py     at https://github.com/cvpe/Pythonista-scripts/blob/master/File_Picker.py
    gestures.py        at https://github.com/mikaelho/pythonista-gestures/blob/master/gestures.py
    blackmamba folder  at https://github.com/zrzka/blackmamba/tree/master/blackmamba
    swizzle.py         at https://github.com/jsbain/objc_hacks/blob/master/swizzle.py
    
    all previous modules should be copied in site-packages
    
    outline.versions   at https://github.com/cvpe/Pythonista-scripts/blob/master/Gists/outline.versions
    
    previous file should be copied in same folder as outline.py
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!