8000 two finger horizontal page · Android-for-Python/gestures4kivy@c02b3fa · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit c02b3fa

Browse files
committed
two finger horizontal page
1 parent 7906ee4 commit c02b3fa

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,22 @@ As usual, `Move`, `Long Press Move`, `Swipe`, and `Long Press` are initiated wit
161161

162162
Two finger pinch/spread uses the cursor location as focus. Note that the cursor may move significantly during a pinch/spread.
163163

164-
A two finger move is interpreted by a touch pad as the equivalent mouse wheel event. A two finger tap generates a `cg_two_finger_tap()` callback.
164+
A two finger move is interpreted by a touch pad as the equivalent mouse wheel event, however a horizontal move used for paging screens may exhibit latency [https://github.com/kivy/kivy/issues/7707](https://github.com/kivy/kivy/issues/7707). A two finger tap generates a `cg_two_finger_tap()` callback.
165165

166166
### Mac
167167

168168
Two finger pinch/spread is not available. Use `Command` and `vertical scroll`.
169169

170170
Force Click (deep press) is reported as a long press, this is a happy coincidence and not by design.
171171

172+
See [https://github.com/kivy/kivy/issues/7708](https://github.com/kivy/kivy/issues/7708).
173+
172174
### iOS
173175
Not tested
174176

175177
### Linux
176178
Not tested
177179

178-
### Rasberry
179-
Not tested
180-
181-
182180

183181
## Acknowledgement
184182

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from setuptools import setup;
2+
3+
setup()

src/gestures4kivy/commongestures.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def __init__(self, **kwargs):
5151
self._SWIPE_TIME = 0.3 # sec
5252
self._SWIPE_VELOCITY = 5 # inches/sec, heuristic
5353
self._WHEEL_SENSITIVITY = 1.1 # heuristic
54+
self._persistent_pos = [(0,0),(0,0)]
55+
self._two_finger_time = 0
56+
5457

5558
#####################
5659
# Kivy Touch Events
@@ -80,8 +83,14 @@ def on_touch_down(self, touch):
8083
scale = self._WHEEL_SENSITIVITY
8184
x, y = self._pos_to_widget(touch.x, touch.y)
8285
if touch.button == 'scrollleft':
86+
if touch.time_start > self._two_finger_time + 0.6 :
87+
self.cg_swipe_horizontal(touch, False)
88+
self._two_finger_time = touch.time_start
8389
self.cg_shift_wheel(touch,1/scale, x, y)
8490
elif touch.button == 'scrollright':
91+
if touch.time_start > self._two_finger_time + 0.6 :
92+
self.cg_swipe_horizontal(touch, True)
93+
self._two_finger_time = touch.time_start
8594
self.cg_shift_wheel(touch,scale, x, y)
8695
else:
8796
if touch.button == 'scrollup':
@@ -113,7 +122,6 @@ def on_touch_down(self, touch):
113122
touch.x, touch.y),
114123
self._DOUBLE_TAP_TIME)
115124

116-
self._persistent_pos = [(0,0),(0,0)]
117125
self._persistent_pos[0] = tuple(touch.pos)
118126
elif len(self._touches) == 2:
119127
self._gesture_state = 'Scale'
@@ -227,8 +235,8 @@ def on_touch_up(self, touch):
227235
### long press clock ###
228236
def _long_press_event(self, touch, x, y, ox, oy, dt):
229237
self._long_press_schedule = None
230-
distance_squared = (x -ox)**2 + (y -oy)**2
231-
if distance_squared < self._DOUBLE_TAP_DISTANCE **2:
238+
distance_squared = (x - ox) ** 2 + (y - oy) ** 2
239+
if distance_squared < self._DOUBLE_TAP_DISTANCE ** 2:
232240
x, y = self._pos_to_widget(x, y)
233241
self.cg_long_press(touch, x, y)
234242
self._gesture_state = 'Long Pressed'
@@ -255,7 +263,7 @@ def _possible_swipe(self, touch):
255263
x, y = touch.pos
256264
ox, oy = touch.opos
257265
period = touch.time_update - touch.time_start
258-
distance = sqrt((x-ox)**2 + (y-oy)**2)
266+
distance = sqrt((x - ox) ** 2 + (y - oy) ** 2)
259267
if period:
260268
velocity = distance / (period * Metrics.dpi)
261269
else:
@@ -280,7 +288,7 @@ def _velocity_start(self, touch):
280288
def _velocity_now(self, touch):
281289
period = touch.time_update - self._velt
282290
x, y = touch.pos
283-
distance = sqrt((x - self._velx)**2 + (y - self._vely)**2)
291+
distance = sqrt((x - self._velx) ** 2 + (y - self._vely) ** 2)
284292
self._velt = touch.time_update
285293
self._velx , self._vely = touch.pos
286294
if period:
@@ -307,8 +315,8 @@ def _scale_distance(self):
307315
def _scale_midpoint(self):
308316
x0, y0 = self._persistent_pos[0]
309317
6465 x1, y1 = self._persistent_pos[1]
310-
midx = abs(x0 - x1)/2 + min(x0, x1)
311-
midy = abs(y0 - y1)/2 + min(y0, y1)
318+
midx = abs(x0 - x1) / 2 + min(x0, x1)
319+
midy = abs(y0 - y1) / 2 + min(y0, y1)
312320
# convert to widget
313321
x = midx - self.x
314322
y = midy - self.y

0 commit comments

Comments
 (0)
0