• cvp

    @Vile thank only @jonb 😀

    posted in Pythonista read more
  • cvp

    Following @JonB advice, this works

    .
    .
    .
            self.last_t = self.t
            
        def update(self):
            #self.sprite.texture=sprite_sheet[1]
            if (self.t-self.last_t) > 0.05:
                #modify_the_sprite
                self.last_t = self.t
    .
    .
    .
    

    posted in Pythonista read more
  • cvp

    @octoshark see last post of this topic

    posted in Pythonista read more
  • cvp

    Same error and solution here and here

    Found via Google on module 'matplotlib' has no attribute 'cbook'

    posted in Pythonista read more
  • cvp

    And the big script also works....

    posted in Pythonista read more
  • cvp

    For me, this little script works also if in Pythonista iCloud

    import matplotlib.pyplot as plt
    x=[1,2]
    y=[1,2]
    plt.scatter(x,y)
    plt.show()
    

    posted in Pythonista read more
  • cvp

    Or IOS 13 bug

    posted in Pythonista read more
  • cvp

    @average install piexif.py from here
    and try this script

    from   datetime import datetime
    import dialogs
    from   objc_util import ObjCInstance
    import os
    import photos
    import piexif   # https://github.com/hMatoba/Piexif/tree/master/piexif
    
    def exif_as_str(exif_val):
        exif_str = str(exif_val)
        if len(exif_str) >= 3:
            if exif_str[:2] == "b'" and exif_str[-1] == "'":
                exif_str = exif_str[2:-1]
        return exif_str 
    
    def main():
        # select photo
        asset = photos.pick_asset()
        
        # get its path
        path = str(ObjCInstance(asset).pathForOriginalFile())
        #print(path)
    
        # get photo exifs
        exif_info = piexif.load(path)   
        exif_str = exif_as_str(exif_info['Exif'][piexif.ExifIFD.DateTimeOriginal])
        #print('photo taken date/time',exif_str)
    
        # get new taken date-time   
        new_date = dialogs.datetime_dialog(title=str(exif_str))
        dt_str = datetime.strftime(new_date,'%Y:%m:%d %H:%M:%S')
        
        # update exif of taken datetime
        exif_info['Exif'][piexif.ExifIFD.DateTimeOriginal] = dt_str 
        exif_str = exif_as_str(exif_info['Exif'][piexif.ExifIFD.DateTimeOriginal])
        #print('modified photo taken date/time',exif_str)
    
        # create new photo with modified taken date-time    
        exif_bytes = piexif.dump(exif_info)
        new_path = 'temp.jpg'
        piexif.insert(exif_bytes,path,new_file=new_path)
        photos.create_image_asset(new_path)
        os.remove(new_path)
                
    #--- protect for import
    if __name__ == '__main__':
        main()
    

    If any error, please forgive me and don't forget I'm in holidays In Bourgogne (🍷=>bugs)

    posted in Pythonista read more
  • cvp

    @jm2466 this

        # 1) convert PIL Image to ui.Image
        console.hud_alert('convert PIL Image into ui.Image')
        with io.BytesIO() as bIO:
            new_im.save(bIO, 'PNG')
            ui_image = ui.Image.from_data(bIO.getvalue())
        del bIO
        # 2) Create a PHAsset from an ui.Image (not from a PIL Image)
        console.hud_alert('Create a PHAsset from an ui.Image')
        lib = PHPhotoLibrary.sharedPhotoLibrary()
        def change_block():
            req = PHAssetChangeRequest.creationRequestForAssetFromImage_(ui_image)
        def perform_changes():
            lib.performChangesAndWait_error_(change_block, None)
        t = threading.Thread(target=perform_changes)
        t.start()
        t.join()
    

    is about (😀) 1000 x slower than

        path = 'temp.jpg'
        new_im.save(path , quality=95)
        photos.create_image_asset(path)
        os.remove(path)
    

    posted in Pythonista read more
  • cvp

    @jm2466 You could always convert your PIL Image into an ui.Image and use this kind of code to save it in camera roll

    # only to have an ui.Image
    import ui
    img = ui.Image.named('test:Bridge')
    
    # Create a PHAsset from an ui.Image (not from a PIL Image)
    from objc_util import *
    import threading
    
    NSBundle.bundleWithPath_('/System/Library/Frameworks/Photos.framework').load()
    PHPhotoLibrary = ObjCClass('PHPhotoLibrary')
    PHAssetChangeRequest = ObjCClass('PHAssetChangeRequest')
    
    lib = PHPhotoLibrary.sharedPhotoLibrary()
    def change_block():
        req = PHAssetChangeRequest.creationRequestForAssetFromImage_(img)
    def perform_changes():
        lib.performChangesAndWait_error_(change_block, None)
    
    t = threading.Thread(target=perform_changes)
    t.start()
    t.join()
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!