Forum Archive

Problem with UIBezierPath and CGPath

Webmaster4o

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?

JonB

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.

Webmaster4o

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!