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.
Pure Python gestures
-
@Anxietier, little optimization of the ”feel” and code simplification.
import ui import scripter v = ui.View(background_color='black') class Pulled(ui.View): trigger_distance = 30 pull_distance = 80 def touch_moved(self, t): delta_y = ( ui.convert_point(t.location, from_view=self).y - ui.convert_point(t.prev_location, from_view=self).y) diff_fraction = self.y/self.pull_distance try: self.reveal_func(diff_fraction) except AttributeError: pass self.y += delta_y * (1 - min(0.9, diff_fraction) ** 2) self.y = max(0, self.y) def touch_ended(self, t): scripter.y(self, 0, ease_func=scripter.ease_out) try: self.reveal_func(0) except AttributeError: pass if self.y > self.trigger_distance: self.trigger_func() label = ui.Label(text='Release to refresh', text_color='white', flex='LBR', alpha=0, ) label.size_to_fit() label.center = v.bounds.center() label.y = 8 v.add_subview(label) def reveal(fraction): label.alpha = fraction def trigger(): scripter.hide(label) print('refresh') v.add_subview(Pulled( reveal_func=reveal, trigger_func=trigger, frame=v.bounds, flex='WH', background_color='green')) v.present('fullscreen')
-
!!! Removed by poster to not confuse future readers with incorrect Code Examples.. 🤓😉
-
@mikael
thanks for help, i make it
but there's another problem showed up:
i make a main view, then i subclass zoomPanView and add to mainView , after that i add imageView as zoomPanView's subVIew, like what zoomPanDemo did, when i overwrite on_pan method and test it, data.began and data.changed can give me right value, but data.ended not, i dont know why -
@stephen thanks for help!
im would try to understand ur code, im not good in math though :(
btw, i tried mikael's code, and it works fine to me :P -
@Anxietier said:
@mikael
thanks for help, i make it
but there's another problem showed up:
i make a main view, then i subclass zoomPanView and add to mainView , after that i add imageView as zoomPanView's subVIew, like what zoomPanDemo did, when i overwrite on_pan method and test it, data.began and data.changed can give me right value, but data.ended not, i dont know whyone more thing, i overwrote on_pinch too, and i printed data.ended, and got right value, maybe two gesture's ended flag conflict ?
-
@Anxietier, thanks for catching this. Pan end event was not properly handled, fixed now in the version on the repo.
-
@Anxietier said:
@Anxietier said:
@mikael
thanks for help, i make it
but there's another problem showed up:
i make a main view, then i subclass zoomPanView and add to mainView , after that i add imageView as zoomPanView's subVIew, like what zoomPanDemo did, when i overwrite on_pan method and test it, data.began and data.changed can give me right value, but data.ended not, i dont know whyone more thing, i overwrote on_pinch too, and i printed data.ended, and got right value, maybe two gesture's ended flag conflict ?
i resolved this issue
i subclass both view and GestureMixin as new ZoomPanView, then i overwrite touch_ended, so that when i subclass new ZoomPanView i can edit touch_ended,
high encapsulation not always convenient XD -
@mikael said:
@Anxietier, thanks for catching this. Pan end event was not properly handled, fixed now in the version on the repo.
expecting for new version (👍 ͡❛ ͜ʖ ͡❛)👍
-
@Anxietier, is there a specific reason why you are using the Python version instead of the native iOS gestures? Just curious, because I no longer remember why I wrote pygestures. 😁 ... Probably just because I wanted to see if I could do it.
-
@mikael
well, im not good at math, i tried use touch_began\move\ended, and surely i can make simple function, but as it became complex, my brain be in chaos, XD -
@Anxietier, I meant choosing between
gestures.py
(wrapper around iOS native gestures) andpygestures.py
(pure Python gestures built on top of theui.View.touch_x
method ”primitives”.Your answer leads me to guess you might not have been aware of the first option.
-
@mikael oh, i did try gesture.py, got some problems, and you suggested me subclass ZoomPanView instead for my need, then i did and i find it's interesting, so ~~ :))
@mikael said:
@Anxietier, can you subclass
ZoomPanView
instead?If you run
pygestures.py
and swipe from the right, you get the demo picture that you can pan and zoom, and that seems to work ok.The code for it is at the end of the file.
-
@Anxietier, oh, and I thought you were already using the python version, given the title of this discussion thread... 😄
-
do you still need help with drag/friction algorithm ?
-
@stephen
thank you, maybe not, i did solve this problem (probably not yet)
thanks for your help :) -
@mikael
haha, I was trying to make a zoom demo, but the effect is not good, so I googled key words "pythonista 2 finger zoom", then luckily found this XD -
Awesome!
ok well il still working on it because parts of the process are in my todo fo mainproject. ill post finished codebwith coments here when finished
-
@stephen
good luck ! (っ^▿^)۶🍸🌟🍺٩(˘◡˘ ) -
@Anxietier
thanks, i noticed you like those٩(•̮̮̃•̃)۶
faces. idk if you type them everytime but i "buffed" the keyboard example script and gave it more functionality here you will be able to select them from a list that you can add to yourself heres a couple thats included.٩(•̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ ٩(̃•̃•̃)۶ ٩(͡๏̯͡๏)۶ ٩(-̮̮̃•̃)۶ ε(̮̮̃•̮̮̃̃•̃)з (๏̯͡๏) |=_=|
-
@stephen
haha, I would try it