Skip to content

Commit 842629a

Browse files
authored
Merge pull request #33 from stdweird/fix_MTDMotionEvent
Some touch EventMotion instances (like MTDMotionEvent) do not have a button
2 parents e3923d4 + c1ef53c commit 842629a

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

backend_kivy.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ def on_touch_down(self, touch):
10791079
self.motion_notify_event(x, y, guiEvent=None)
10801080

10811081
touch.grab(self)
1082-
if(touch.button == "scrollup" or touch.button == "scrolldown"):
1082+
if 'button' in touch.profile and touch.button in ("scrollup", "scrolldown",):
10831083
self.scroll_event(x, y, 5, guiEvent=None)
10841084
else:
10851085
self.button_press_event(x, y, self.get_mouse_button(touch),
@@ -1114,12 +1114,13 @@ def get_mouse_button(self, touch):
11141114
into matplotlib int values: 1 for left, 2 for middle and 3 for
11151115
right.
11161116
'''
1117-
if touch.button == "left":
1118-
return 1
1119-
elif touch.button == "middle":
1120-
return 2
1121-
elif touch.button == "right":
1122-
return 3
1117+
if 'button' in touch.profile:
1118+
if touch.button == "left":
1119+
return 1
1120+
elif touch.button == "middle":
1121+
return 2
1122+
elif touch.button == "right":
1123+
return 3
11231124
return -1
11241125

11251126
def on_touch_up(self, touch):
@@ -1130,7 +1131,7 @@ def on_touch_up(self, touch):
11301131
x = newcoord[0]
11311132
y = newcoord[1]
11321133
if touch.grab_current is self:
1133-
if touch.button == "scrollup" or touch.button == "scrolldown":
1134+
if 'button' in touch.profile and touch.button in ("scrollup", "scrolldown",):
11341135
self.scroll_event(x, y, 5, guiEvent=None)
11351136
else:
11361137
self.button_release_event(x, y, self.get_mouse_button(touch), guiEvent=None)

0 commit comments

Comments
 (0)