Skip to content

Commit c1ef53c

Browse files
committed
Some touch EventMotion instances (like MTDMotionEvent) do not have a button attribute.
This fixes crashes like File "/usr/local/lib/python2.7/dist-packages/kivy/uix/widget.py", line 432, in on_touch_down if child.dispatch('on_touch_down', touch): File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (/tmp/pip-build-Q1Kayw/kivy/kivy/_event.c:7699) File "/home/pi/.kivy/garden/garden.matplotlib/backend_kivy.py", line 1067, in on_touch_down if(touch.button == "scrollup" or touch.button == "scrolldown"): AttributeError: 'MTDMotionEvent' object has no attribute 'button'
1 parent 0e549e9 commit c1ef53c

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
@@ -1064,7 +1064,7 @@ def on_touch_down(self, touch):
10641064
self.motion_notify_event(x, y, guiEvent=None)
10651065

10661066
touch.grab(self)
1067-
if(touch.button == "scrollup" or touch.button == "scrolldown"):
1067+
if 'button' in touch.profile and touch.button in ("scrollup", "scrolldown",):
10681068
self.scroll_event(x, y, 5, guiEvent=None)
10691069
else:
10701070
self.button_press_event(x, y, self.get_mouse_button(touch),
@@ -1099,12 +1099,13 @@ def get_mouse_button(self, touch):
10991099
into matplotlib int values: 1 for left, 2 for middle and 3 for
11001100
right.
11011101
'''
1102-
if touch.button == "left":
1103-
return 1
1104-
elif touch.button == "middle":
1105-
return 2
1106-
elif touch.button == "right":
1107-
return 3
1102+
if 'button' in touch.profile:
1103+
if touch.button == "left":
1104+
return 1
1105+
elif touch.button == "middle":
1106+
return 2
1107+
elif touch.button == "right":
1108+
return 3
11081109
return -1
11091110

11101111
def on_touch_up(self, touch):
@@ -1115,7 +1116,7 @@ def on_touch_up(self, touch):
11151116
x = newcoord[0]
11161117
y = newcoord[1]
11171118
if touch.grab_current is self:
1118-
if touch.button == "scrollup" or touch.button == "scrolldown":
1119+
if 'button' in touch.profile and touch.button in ("scrollup", "scrolldown",):
11191120
self.scroll_event(x, y, 5, guiEvent=None)
11201121
else:
11211122
self.button_release_event(x, y, touch.button, guiEvent=None)

0 commit comments

Comments
 (0)