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.
Traceback using Gestures module
-
@mikael a little more fiddling around, and looking at how other people have used objc_util and ObjCInstance's, it seems I can just stash a reference to the Gestures object instance for my control in the actual delegate instance created for that control:
self._delegate = PythonistaGestureDelegate.new() self._delegate._gestures = self
and then I can safely access that reference in the objc callbacks:
def gestureRecognizer_shouldRecognizeSimultaneouslyWithGestureRecognizer_(_self, _sel, gr, other_gr): import objc_util delegate_instance = objc_util.ObjCInstance(_self) gestures_instance = delegate_instance._gestures return gestures_instance.objc_should_recognize_simultaneously(self.recognize_simultaneously, gr, other_gr)
so now only one actual delegate class definition is created in objective-c, and the delegate instances for each control are all separately able to access the Gestures instance they use. I'll have to make sure I break the cyclic reference between the gesture delegate instance and the Gestures instance, but I can do that via a weakref or explicitly removing the cycle when I get rid of the control.
-
@shinyformica, thanks, I will implement this. Does this option suffer from the vanishing Gestures class?
I will also check this with an iPad.
-
@mikael thankfully it does not suffer from that strange vanishing-definitions thing. Though I am now locally importing objc_util anyplace I try to use ObjCInstance() or ObjCClass(), which appears to prevent it from showing up and causing trouble.
I tested the above technique using weakref to hold the reference to the Gestures object and it worked fine, so that will prevent a cyclic-reference:
self._delegate = PythonistaGestureDelegate.new() import weakref self._delegate._gestures = weakref.ref(self)
-
hey, have you copies objc_util and made edits? objc_util should actually never be cleared after it is loaded, so unless you are manually del'ing sys.modules['objc_util'] it should not be getting cleared out from under you. But, if you had a shadow copy on your path, it would.
import objc_util print(objc_util.__file__)
i have an older version of gestures, but i also could not reproduce your issues
-
@shinyformica, thanks. I will include the weakref version.
I was also wondering if you had some globals-clearing code somewhere. Remembering some previous threads where the goal was to make Pythonista act like a fresh interpreter starting every time you run a script.