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
-
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 aCGPath
inside aCAShapeLayer
, then animate thestrokeEnd
property, and somehow do all this insideui
.But, no matter what I do, I can't get a
CGPath
from aui.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 fromfrom objc_util import * print(UIBezierPath.new().CGPath())
What's going on here?
-
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.
-
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!