matplotlib picking mouseevent.key=None

Say, on Windows, the mouseevent.key correctly comes in as control, shift, or
a letter...on Linux, it does not....I am always getting None.

is this a known problem with known solution?

thanks,

gsal

···

--
View this message in context: http://old.nabble.com/matplotlib-picking-mouseevent.key%3DNone-tp33494747p33494747.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Which backend are you using? Also, which mouse event are you using where you expect a key value? I would expect to use a key press event to process .key values.

Ben Root

···

On Tue, Mar 13, 2012 at 10:05 AM, gsal <salgerman@…287…> wrote:

Say, on Windows, the mouseevent.key correctly comes in as control, shift, or

a letter…on Linux, it does not…I am always getting None.

is this a known problem with known solution?

We need more information, what is your backend, what is you GUI toolkit version? If you post a minimal script that exposes the problem, and run it with --verbose-helpful and post the output, we can see if we can replicate the problem.

JDH

···

On Tue, Mar 13, 2012 at 10:05 AM, gsal <salgerman@…1003…7…> wrote:

Say, on Windows, the mouseevent.key correctly comes in as control, shift, or

a letter…on Linux, it does not…I am always getting None.

is this a known problem with known solution?

Here are some imports:

# PyQt4 modules
from PyQt4.QtCore import *
from PyQt4.QtGui import *

# matplotlib modules
import matplotlib.patches as mpathes
import matplotlib.text as mtext
import matplotlib.lines as mlines
from matplotlib.path import Path
from matplotlib.collections import LineCollection

from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as
NavigationToolbar

And this:
matplotlib.__version__ => 0.99.1.1

I am afraid I may not be able to run a rather minimal app right away since
this is somebody else's Qt app, pretty large, that I am trying to add some
plotting...I will see if I can get start another minimal Qt app...

For now, there isn't much of a problem with the application, it is just that
I inspect the mouseevent from within the picker function and I get this

None
1
<matplotlib.collections.LineCollection object at 0x132fa0d0>

where
None is the key
1 is the mouse button pressed
and the rest is the artist

···

--
View this message in context: http://old.nabble.com/matplotlib-picking-mouseevent.key%3DNone-tp33494747p33494825.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Here are some imports:

# PyQt4 modules
from PyQt4.QtCore import *
from PyQt4.QtGui import *

# matplotlib modules
import matplotlib.patches as mpathes
import matplotlib.text as mtext
import matplotlib.lines as mlines
from matplotlib.path import Path
from matplotlib.collections import LineCollection

from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as
NavigationToolbar

And this:
matplotlib.__version__ => 0.99.1.1

I am afraid I may not be able to run a rather minimal app right away since
this is somebody else's Qt app, pretty large, that I am trying to add some
plotting...I will see if I can get start another minimal Qt app...

For now, there isn't much of a problem with the application, it is just that
I inspect the mouseevent from within the picker function and I get this

None
1
<matplotlib.collections.LineCollection object at 0x132fa0d0>

where
None is the key
1 is the mouse button pressed
and the rest is the artist

···

--
View this message in context: http://old.nabble.com/matplotlib-picking-mouseevent.key%3DNone-tp33494747p33495268.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

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.