@mikael
@cvp
Thank you. I'm working on finishing my clipboard plan now. Thank you for your help. I have learned a lot!
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.
Posts made by rozaimech
-
RE: Problems when using objc_util()
-
RE: Problems when using objc_util()
@cvp
Usually the second run has an error,maybe it's after first completion...... -
RE: Problems when using objc_util()
@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. -
RE: Problems when using objc_util()
@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()
-
RE: Problems when using objc_util()
@cvp
jonb said :
the Pythonista hava two threads
1.The main thread, or ui thread
2.The interpreter threadI 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..
-
RE: Problems when using objc_util()
@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()
-
RE: Problems when using objc_util()
@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........ -
RE: Problems when using objc_util()
@cvp
The first call successfully gets the dragged data, but the second flash back. I'm trying to resolve this error.The error log isFatal Python error: Segmentation fault Thread 0x000000016fc77000 (most recent call first):
-
RE: Problems when using objc_util()
@cvp
drag already written
and drop already written, too
but Random crashes have no error log -
RE: Problems when using objc_util()
@cvp
I should have misused my words..
realize..
implements..
implementation ...
implementation function? xd -
RE: Problems when using objc_util()
@rozaimech said:
I can realize the clipboard of iPad
sorry,it's mean “can realize the global clipboard of iPad”
-
RE: Problems when using objc_util()
@cvp
I haven't used objc_util too much before in pythonista, and I have learned a lot recently, including the pythonista pointer you told me, the syntax of Object C, and the current problem is that I'm not familiar with the use of block as a parameter. Next, I will continue to study it -
RE: Problems when using objc_util()
@cvp
I made a program to synchronize the clipboard of PC and iPad, but it can only run in pythonista. If I use drop and drag, I can realize the clipboard of iPad (pythonista runs as a window) -
RE: Problems when using objc_util()
@cvp
I'm sorry to make you feel like I'm a lazy kid to sit idle and enjoy the fruits of other's work .I have read Pythonista documents and source code many times, but there are not many similar examples about objc_util. I can't master English very well, but thank you very much for your help! I'm also trying to find relevant solutions. -
RE: Problems when using objc_util()
@cvp hello..do you know how to create a block in the dropInteraction_performDrop_?
# 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): #UIDropOperationCancel = 0, #UIDropOperationForbidden = 1, #UIDropOperationCopy = 2, #UIDropOperationMove = 3, return ObjCClass('UIDropProposal').alloc().initWithDropOperation(2).ptr def dropInteraction_performDrop_(_m,_c,interaction,session): session=ObjCInstance(session) '''object c: [session loadObjectsOfClass:[NSString class] completion:^(NSArray<__kindof id<NSItemProviderReading>> * _Nonnull objects) { self.dropLabel.text = objects.firstObject;}]; ''' session.loadObjectsOfClass_completion_(NSString,) 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()
-
RE: Problems when using objc_util()
@mikael thanks ,but how to find these hidden interfaces....I want to learn
-
RE: Problems when using objc_util()
@JonB Thank you for your help! I should continue to sleep now.
-
RE: Problems when using objc_util()
@mikael This code should work on iphones. This feature is turned off by default on iphones, but as obj_draginter.setEnabled (True) is turned on, it can be used.