From 4ea79bbc82af8ac82bec086d820bef87e28efcdb Mon Sep 17 00:00:00 2001 From: Hans Meine Date: Wed, 23 May 2012 10:58:21 +0200 Subject: [PATCH 1/2] fix exceptions in qt4 backend with extra mouse buttons --- lib/matplotlib/backends/backend_qt4.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/backends/backend_qt4.py b/lib/matplotlib/backends/backend_qt4.py index 623b245ef7da..dd16de466300 100644 --- a/lib/matplotlib/backends/backend_qt4.py +++ b/lib/matplotlib/backends/backend_qt4.py @@ -165,9 +165,10 @@ def mousePressEvent( self, event ): x = event.pos().x() # flipy so y=0 is bottom of canvas y = self.figure.bbox.height - event.pos().y() - button = self.buttond[event.button()] - FigureCanvasBase.button_press_event( self, x, y, button ) - if DEBUG: print 'button pressed:', event.button() + button = self.buttond.get(event.button()) + if button is not None: # only three buttons supported by MouseEvent + FigureCanvasBase.button_press_event( self, x, y, button ) + if DEBUG: print('button pressed:', event.button()) def mouseMoveEvent( self, event ): x = event.x() @@ -180,9 +181,10 @@ def mouseReleaseEvent( self, event ): x = event.x() # flipy so y=0 is bottom of canvas y = self.figure.bbox.height - event.y() - button = self.buttond[event.button()] - FigureCanvasBase.button_release_event( self, x, y, button ) - if DEBUG: print 'button released' + button = self.buttond.get(event.button()) + if button is not None: # only three buttons supported by MouseEvent + FigureCanvasBase.button_release_event( self, x, y, button ) + if DEBUG: print('button released') def wheelEvent( self, event ): x = event.x() From 518b9a9ddd793792116012386ee8c465710da780 Mon Sep 17 00:00:00 2001 From: Hans Meine Date: Wed, 23 May 2012 11:10:24 +0200 Subject: [PATCH 2/2] backend_qt4: make button mapping definition use Qt's constants --- lib/matplotlib/backends/backend_qt4.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/backend_qt4.py b/lib/matplotlib/backends/backend_qt4.py index dd16de466300..99d2813260f4 100644 --- a/lib/matplotlib/backends/backend_qt4.py +++ b/lib/matplotlib/backends/backend_qt4.py @@ -122,8 +122,13 @@ class FigureCanvasQT( QtGui.QWidget, FigureCanvasBase ): QtCore.Qt.Key_Alt : 'alt', QtCore.Qt.Key_Return : 'enter' } - # left 1, middle 2, right 3 - buttond = {1:1, 2:3, 4:2} + # map Qt button codes to MouseEvent's ones: + buttond = {QtCore.Qt.LeftButton : 1, + QtCore.Qt.MidButton : 2, + QtCore.Qt.RightButton : 3, + # QtCore.Qt.XButton1 : None, + # QtCore.Qt.XButton2 : None, + } def __init__( self, figure ): if DEBUG: print 'FigureCanvasQt: ', figure _create_qApp()