-
Notifications
You must be signed in to change notification settings - Fork 2
/
tab_panel.py
69 lines (52 loc) · 4.24 KB
/
tab_panel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from kivy.gesture import Gesture, GestureDatabase
from kivy.graphics import Line
from kivy.uix.tabbedpanel import TabbedPanel
from main import RfAttendance
class TabPannel(TabbedPanel):
def __init__(self, *args, **kwargs):
super(TabPannel, self).__init__(*args, **kwargs)
self.app = RfAttendance.get_running_app()
self.gdb = GestureDatabase()
self.left_to_right_gesture = self.gdb.str_to_gesture(left_to_right_gesture)
self.right_to_left_gesture = self.gdb.str_to_gesture(right_to_left_gesture)
self.gdb.add_gesture(self.left_to_right_gesture)
self.gdb.add_gesture(self.right_to_left_gesture)
def on_touch_down(self, touch):
touch.ud['line'] = Line(points=(touch.x, touch.y))
return super(TabPannel, self).on_touch_down(touch)
def on_touch_move(self, touch):
try:
touch.ud['line'].points += [touch.x, touch.y]
return super(TabbedPanel, self).on_touch_move(touch)
except KeyError:
pass
def on_touch_up(self, touch):
g = Gesture()
g.add_stroke(list(zip(
touch.ud['line'].points[::2],
touch.ud['line'].points[1::2]
)))
g.normalize()
g.name = ''
g2 = self.gdb.find(g, minscore=0.70)
if g2 and g2[1] == self.left_to_right_gesture:
self.switch_to_left()
elif g2 and g2[1] == self.right_to_left_gesture:
self.switch_to_right()
return super(TabPannel, self).on_touch_up(touch)
def switch_to_right(self):
current_tab_index = self.tab_list.index(self.current_tab)
if current_tab_index == 0:
return
try:
self.switch_to(self.tab_list[current_tab_index - 1])
except IndexError:
pass
def switch_to_left(self):
current_tab_index = self.tab_list.index(self.current_tab)
try:
self.switch_to(self.tab_list[current_tab_index + 1])
except IndexError:
pass
left_to_right_gesture = 'eNq1l91u4jAQhe/9IuVmoxnPj+0XoLcr9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