@@ -122,8 +122,13 @@ class FigureCanvasQT( QtGui.QWidget, FigureCanvasBase ):
122
122
QtCore .Qt .Key_Alt : 'alt' ,
123
123
QtCore .Qt .Key_Return : 'enter'
124
124
}
125
- # left 1, middle 2, right 3
126
- buttond = {1 :1 , 2 :3 , 4 :2 }
125
+ # map Qt button codes to MouseEvent's ones:
126
+ buttond = {QtCore .Qt .LeftButton : 1 ,
127
+ QtCore .Qt .MidButton : 2 ,
128
+ QtCore .Qt .RightButton : 3 ,
129
+ # QtCore.Qt.XButton1 : None,
130
+ # QtCore.Qt.XButton2 : None,
131
+ }
127
132
def __init__ ( self , figure ):
128
133
if DEBUG : print 'FigureCanvasQt: ' , figure
129
134
_create_qApp ()
@@ -165,9 +170,10 @@ def mousePressEvent( self, event ):
165
170
x = event .pos ().x ()
166
171
# flipy so y=0 is bottom of canvas
167
172
y = self .figure .bbox .height - event .pos ().y ()
168
- button = self .buttond [event .button ()]
169
- FigureCanvasBase .button_press_event ( self , x , y , button )
170
- if DEBUG : print 'button pressed:' , event .button ()
173
+ button = self .buttond .get (event .button ())
174
+ if button is not None : # only three buttons supported by MouseEvent
175
+ FigureCanvasBase .button_press_event ( self , x , y , button )
176
+ if DEBUG : print ('button pressed:' , event .button ())
171
177
172
178
def mouseMoveEvent ( self , event ):
173
179
x = event .x ()
@@ -180,9 +186,10 @@ def mouseReleaseEvent( self, event ):
180
186
x = event .x ()
181
187
# flipy so y=0 is bottom of canvas
182
188
y = self .figure .bbox .height - event .y ()
183
- button = self .buttond [event .button ()]
184
- FigureCanvasBase .button_release_event ( self , x , y , button )
185
- if DEBUG : print 'button released'
189
+ button = self .buttond .get (event .button ())
190
+ if button is not None : # only three buttons supported by MouseEvent
191
+ FigureCanvasBase .button_release_event ( self , x , y , button )
192
+ if DEBUG : print ('button released' )
186
193
187
194
def wheelEvent ( self , event ):
188
195
x = event .x ()
0 commit comments