• rozaimech

    @mikael
    @cvp
    Thank you. I'm working on finishing my clipboard plan now. Thank you for your help. I have learned a lot!

    posted in Pythonista read more
  • rozaimech

    @cvp
    Usually the second run has an error,maybe it's after first completion......

    posted in Pythonista read more
  • rozaimech

    @cvp
    This is Apple's UI design. The completion handler is asynchronous and runs immediately.
    "ItemProvider. Loadobjectofclass_completionhandler_()" returns a progress, which can cancel operations or obtain progress data. During this period, developers can design a set of suitable UI animation to reduce the waiting experience of users, or cancel loading.

    posted in Pythonista read more
  • rozaimech

    @cvp
    ok...we won

    # coding: utf-8
    from objc_util import *
    import ui,time
    
    def dropInteraction_canHandleSession_(_m,_c,interaction,session):
        return True
    def dropInteraction_sessionDidUpdate_(_m,_c,interaction,session):
        return ObjCClass('UIDropProposal').alloc().initWithDropOperation(2).ptr
        
    def dropInteraction_performDrop_(_m,_c,interaction,session):
        session=ObjCInstance(session)
        def handler(_cmd,obj_ptr):
            obj=ObjCInstance(obj_ptr)
            print(obj)
            
        handler_block = ObjCBlock(handler, restype=None, argtypes=[c_void_p,c_void_p])
        def ptimer(progress):
            while True:
                if(progress.totalUnitCount()==progress.completedUnitCount()):
                    break
                time.sleep(0.1)
        for item in session.items():
            itemProvider =item.itemProvider()
            uiimage =ObjCClass('UIImage')
            
            if(itemProvider.canLoadObjectOfClass(uiimage)):
                progress=itemProvider.loadObjectOfClass_completionHandler_(ObjCClass('UIImage'),handler_block)
                ptimer(progress)
            elif(itemProvider.canLoadObjectOfClass(NSString)):
                progress=itemProvider.loadObjectOfClass_completionHandler_(NSString,handler_block)
                ptimer(progress)
                
            else:
                print(itemProvider)
                
    methods=[dropInteraction_canHandleSession_,dropInteraction_sessionDidUpdate_,dropInteraction_performDrop_]
    protocols=['UIDropInteractionDelegate']
    dropDelegate=create_objc_class('MydropDelegate',methods=methods,protocols=protocols)
    
    
    Delegate=dropDelegate.alloc().init()
    dropInteraction=ObjCClass('UIDropInteraction').alloc().initWithDelegate(Delegate)
    
    drop_view = ui.View(bg_color='blue')
    drop_view.objc_instance.setUserInteractionEnabled(True)
    drop_view.objc_instance.addInteraction(dropInteraction)
    drop_view.present()
    
    

    posted in Pythonista read more
  • rozaimech

    @cvp
    jonb said :
    the Pythonista hava two threads
    1.The main thread, or ui thread
    2.The interpreter thread

    I don't know if the error is related to IOS thread.
    but I remember that the apple development document said that the NSItemProvider interface should be used in DispatchQueue.main.async { }

    I'm learning something about it..

    posted in Pythonista read more
  • rozaimech

    @cvp
    There will be an error message:TypeError..

    # coding: utf-8
    from objc_util import *
    import ui
    
    def dropInteraction_canHandleSession_(_m,_c,interaction,session):
        return True
    def dropInteraction_sessionDidUpdate_(_m,_c,interaction,session):
        return ObjCClass('UIDropProposal').alloc().initWithDropOperation(2).ptr
        
    def dropInteraction_performDrop_(_m,_c,interaction,session):
        session=ObjCInstance(session)
        def handler(_cmd,obj_ptr):
            obj=ObjCInstance(obj_ptr)
            print(obj)
        handler_block = ObjCBlock(handler, restype=None, argtypes=[c_void_p,c_void_p])
        
        for item in session.items():
            itemProvider =item.itemProvider()
            uiimage =ObjCClass('UIImage')
            nsstring =ObjCClass('NSString')
            if(itemProvider.canLoadObjectOfClass(uiimage)):
                on_main_thread(itemProvider.loadObjectOfClass_completionHandler_(ObjCClass('UIImage'),handler_block))
            elif(itemProvider.canLoadObjectOfClass(nsstring)):
                on_main_thread(itemProvider.loadObjectOfClass_completionHandler_(nsstring,handler_block))
            else:
                continue
                
    methods=[dropInteraction_canHandleSession_,dropInteraction_sessionDidUpdate_,dropInteraction_performDrop_]
    protocols=['UIDropInteractionDelegate']
    dropDelegate=create_objc_class('MydropDelegate',methods=methods,protocols=protocols)
    
    
    Delegate=dropDelegate.alloc().init()
    dropInteraction=ObjCClass('UIDropInteraction').alloc().initWithDelegate(Delegate)
    
    drop_view = ui.View(bg_color='blue',frame=(0,0,500,500))
    drop_view.objc_instance.setUserInteractionEnabled(True)
    drop_view.objc_instance.addInteraction(dropInteraction)
    drop_view.present()
    

    posted in Pythonista read more
  • rozaimech

    @cvp
    ok....I should have avoided this mistake long ago...
    Just let this asynchronous function run on the main thread. Everything is normal, no flashbacks, and no errors........

    posted in Pythonista read more
  • rozaimech

    @cvp
    The first call successfully gets the dragged data, but the second flash back. I'm trying to resolve this error.The error log is

    Fatal Python error: Segmentation fault
    
    Thread 0x000000016fc77000 (most recent call first):
    

    posted in Pythonista read more
  • rozaimech

    @cvp
    drag already written
    and drop already written, too
    but Random crashes have no error log

    posted in Pythonista read more
  • rozaimech

    @cvp
    link img

    This is my work of art. Please don't laugh

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!