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.


    Problem with UIBezierPath and CGPath

    Pythonista
    2
    3
    2460
    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.
    • Webmaster4o
      Webmaster4o last edited by

      Not sure whether this is directly Pythonista-related, but I'm having some trouble with objc_util. Code that appears to work elsewhere fails in Pythonista, and I don't think I'm doing anything obviously wrong.

      I'm trying to implement a progress bar that strokes along a ui.Path. I think I need to have a CGPath inside a CAShapeLayer, then animate the strokeEnd property, and somehow do all this inside ui.

      But, no matter what I do, I can't get a CGPath from a ui.Path.

      The first thing I tried was this:

      import ui
      from objc_util import *
      
      a = ui.Path()
      a.line_to(10, 0)
      a.line_to(10, 10)
      a.close()
      
      b = ObjCInstance(a)
      print(b.CGPath())
      

      I always get a c_void_p from this. I even get similar results from

      from objc_util import *
      print(UIBezierPath.new().CGPath())
      

      What's going on here?

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

        CGPath is an opaque type, basically a pointer to an object we cannot interpret directly.

        As a more general comment, when you get back c_void_p's, often you can use ObjCInstance on the pointer to get the bridged object.

        >>> ObjCInstance(ObjCInstance(p).CGPath())
        <b'__NSCFType': <CGPath 0x1695a830>>
        

        In this case, since CGPath is opaque, there is not much you do with a CGPath itself. You pass CGPaths to C functions, it does not have methods like an object per se.

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

          Thanks @JonB! As @dgelessus said on Slack, i wad able to pass around that c_void_p even without ObjCInstance and it worked fine. The ObjCInstance trick looks good, though!

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