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.
Problems when using objc_util()
-
@rozaimech said:
cui=ui.View(bg_color='#ffffff',farme=(0,0,500,500))
Small typing error: farme ipo frame 🙄
-
@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()
-
@rozaimech first of all, did you read objc_util doc in Pythonista?
Then, there are a lot of examples in the forum.
Last, I'll try to do it, I just read your request. -
@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. -
@rozaimech ok and Sorry, I'm still busy with your problem.
A block is ok but loadObjectsOfClass_completion_ is not a method for session... -
@rozaimech I'be done a step more but not yet ok
def dropInteraction_performDrop_(_m,_c,interaction,session): session=ObjCInstance(session) print('dropInteraction_performDrop_ called') '''object c: [session loadObjectsOfClass:[NSString class] completion:^(NSArray<__kindof id<NSItemProviderReading>> * _Nonnull objects) { self.dropLabel.text = objects.firstObject;}]; ''' def handler(_cmd):#,obj1_ptr,_error): print('block called') handler_block = ObjCBlock(handler, restype=None, argtypes=[c_void_p])#, c_void_p, c_void_p]) for item in session.items(): print(item) itemProvider = item.itemProvider() print(itemProvider) ret = itemProvider.loadObjectsOfClass_completion_(NSString, handler_block)
-
@rozaimech we will win, I hope.
You did a small error in loadObjectOfClass_completionHandler_def dropInteraction_performDrop_(_m,_c,interaction,session): session=ObjCInstance(session) print('dropInteraction_performDrop_ called') '''object c: [session loadObjectsOfClass:[NSString class] completion:^(NSArray<__kindof id<NSItemProviderReading>> * _Nonnull objects) { self.dropLabel.text = objects.firstObject;}]; ''' def handler(_cmd,obj1_ptr,_error): print('block called') obj1 = ObjCInstance(obj1_ptr) print(obj1) handler_block = ObjCBlock(handler, restype=None, argtypes=[c_void_p, c_void_p, c_void_p]) for item in session.items(): print(item) itemProvider = item.itemProvider() print(itemProvider) #print(dir(itemProvider)) itemProvider.loadObjectOfClass_completionHandler_(NSString, handler_block)
-
@rozaimech I don't know what you want to drop.
I try with a photo (with the Photos app in split view with Pythonista) and, if you comment the print(obj1) line,- we see that the dropped item is a public.jpeg
- the block is called
Up to here, it is ok but there is still work (for you?) th analyze the droped item. I've tried but not yet solved...
-
@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) -
-
@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 -
@rozaimech said:
I can realize the clipboard of iPad
sorry,it's mean “can realize the global clipboard of iPad”
-
@rozaimech I'm sincerely sorry, perhaps due to my poor English, but I can't understand this "realize"
-
@cvp
I should have misused my words..
realize..
implements..
implementation ...
implementation function? xd -
@rozaimech do you know the
clipboard
Pythonista module? -
@rozaimech If you only want to drop a text in a Pythonista script, you don't need Objectivec, you can drop any text in a ui.TextField
-
-
@rozaimech Nice, seriously
-
@zrzka wrote a drag script
-
This post is deleted!