Wanted to add simple swipe-gesture recognition to a custom View I was writing, so I thought I'd try out the utterly fantastic Gestures module by @mikael, which seemed like it had exactly what I needed...
...and it worked! ...the first time I run my code. The second time, and any time thereafter, until I force-quit Pythonista and restart, it gives the following traceback when detecting my gesture:
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 315, in 'calling callback function'
File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents.../Gestures.py", line 154, in gestureRecognizer_shouldRequireFailureOfGestureRecognizer_
return self.objc_should_require_failure(self.fail_other, gr, other_gr)
File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents.../Gestures.py", line 157, in objc_should_require_failure_default
return simplify(func, gr, other_gr)
File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/.../Gestures.py", line 133, in simplify
gr_o = ObjCInstance(gr)
TypeError: 'NoneType' object is not callable
My project is python2.7, and Gestures is really python3 code, though the only incompatibility I found was this import of a python3-only module which isn't even used in the Gestures code:
from types import SimpleNamespace
So I commented that line out and it worked fine...until this issue. To reiterate: I can run my code once, load the pyui, my custom View shows up, and reacts to the swipe as expected. Then I exit my script, and run it again, and the second time around it gives this traceback...it seemed like it was holding a reference to the gesture recognizer instance from one run to the next, so I tried both:
class MyView(ui.View):
def did_load(self):
import Gestures
Gestures.Gestures(retain_global_reference=True).add_swipe(self, self._handleSwipe,
direction=[Gestures.Gestures.LEFT, Gestures.Gestures.RIGHT])
and also:
class MyView(ui.View):
def did_load(self):
import Gestures
self._gr = Gestures.Gestures(retain_global_reference=False)
self._gr.add_swipe(self, self._handleSwipe, direction=[Gestures.Gestures.LEFT, Gestures.Gestures.RIGHT])
Thinking maybe it was the "retain_global_reference" which was causing this...but either way I get the same result.
Anyone ever see this before? Any ideas?