omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Another block challenge

    Pythonista
    2
    4
    1671
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mikael
      mikael last edited by

      Sorry to be so hopeless, but now I have this signature:

      (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString *result))completionHandler;

      Thus I should call the block with a pointer to an NSString as an argument. How do I get one from the Python string I have at hand, and what should I have as the ctypes argument - probably c_void_p?

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        NSString is an object, so would be c_void_p. if you have a python string, you can use ns( your_string ) to convert to an NSString. Actually, the ObjCBlock's call method might already be calling ns() on each argument to do all the the conversions for you (at least, ObjCMethod does), but I'm not 100% sure. ns() handles many common types.

        To get a python string from NSString, iirc str(your_ns_string_objc_instance) works.

        1 Reply Last reply Reply Quote 1
        • JonB
          JonB last edited by

          btw, despite the seemingly extra pointer, you would pass the output of ns() directly -- that creates the ibject, the. the ObjCInstance's from_param passes the .objc_ptr.

          mikael 1 Reply Last reply Reply Quote 1
          • mikael
            mikael @JonB last edited by

            @JonB, thanks, that was too easy!

            blk.invoke(_completion_handler, ns(python_string))

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors