From: gsal <sal...@gm...> - 2012-03-18 00:22:00
|
o.k., here is some minimal code...what am I doing wrong? Within the picker (def pkr)...I would like to be able to see the mouseevent.key value, but this is always None...is this the expected behaviour? Is mouseevent.key not set at this point? Anye hints would be greatly appreciated. [code] import sys import matplotlib.patches as mpathes import matplotlib.text as mtext import matplotlib.lines as mlines from matplotlib.path import Path from PyQt4.QtGui import * from matplotlib.figure import Figure from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar class AAA(): pass class Qt4MplCanvas(FigureCanvas): """class to represent the FigureCanvas widget""" def __init__(self, parent, data): self.data = data self.fig = Figure() self.axes = self.fig.add_subplot(111) self.axes.set_aspect(1) self.compute_initial_figure() FigureCanvas.__init__(self, self.fig) self.setParent(parent) FigureCanvas.setSizePolicy(self,QSizePolicy.Expanding,QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) class MagnedMplCanvas(Qt4MplCanvas): """Simple canvas with a sine plot.""" def pkr(self, art, mouseevent): key = mouseevent.key button = mouseevent.button print key print button print art return False, dict() def compute_initial_figure(self): GR = [1.0, 2.0, 3.0, 4.0] self.axes.hlines(GR,0.0,4.0,picker=self.pkr) class ApplicationWindow(QMainWindow): """Example main window""" def __init__(self): QMainWindow.__init__(self) self.setWindowTitle("Matplotlib Figure in a Qt4 Window WithNavigationToolbar") self.main_widget = QWidget(self) vbl = QVBoxLayout(self.main_widget) self.data=AAA() self.data.nnn=0 qmc = MagnedMplCanvas(self.main_widget, self.data) ntb = NavigationToolbar(qmc, self.main_widget) vbl.addWidget(qmc) vbl.addWidget(ntb) self.main_widget.setFocus() self.setCentralWidget(self.main_widget) qApp = QApplication(sys.argv) aw = ApplicationWindow() aw.show() sys.exit(qApp.exec_()) [/code] -- View this message in context: http://old.nabble.com/matplotlib-picking-mouseevent.key%3DNone-tp33494747p33524689.html Sent from the matplotlib - users mailing list archive at Nabble.com. |