|
From: Jorge S. <jor...@ya...> - 2014-06-05 12:32:32
|
Hi,
I just mentioned this problem with Qt4Agg and python 3.4 in another thread
[1], but I decided to post it on a thread of its own, as I suspect it might
be a bug in the Qt4Agg backend.
I get a NameError exception (see backtrace below) when trying to use key
events in matplotlib (master branch rev:
e322d5f5bb024bbec44d3ba76da1bc16bf52af9c), python 3.4.1, and pyqt 4.10.
Is this a bug?
Regards,
Jorge
backtrace:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/home/jscandal/sw/matplotlib/matplotlib/lib/matplotlib/backends/backend_qt4.py
in
keyReleaseEvent(self=<matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
object>, event=<PyQt4.QtGui.QKeyEvent object>)
308
309 def keyReleaseEvent(self, event):
--> 310 key = self._get_key(event)
key = undefined
self._get_key = <bound method FigureCanvasQTAgg._get_key of
<matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg object at 0x7f0393412948>>
event = <PyQt4.QtGui.QKeyEvent object at 0x7f0393507a68>
311 if key is None:
312 return
/home/jscandal/sw/matplotlib/matplotlib/lib/matplotlib/backends/backend_qt4.py
in _get_key(self=<matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
object>, event=<PyQt4.QtGui.QKeyEvent object>)
363 return None
364
--> 365 key = unichr(event_key)
key = undefined
global unichr = undefined
global event_key = undefined
366 # qt delivers capitalized letters. fix capitalization
367 # note that capslock is ignored
NameError: name 'unichr' is not defined
[1] http://thread.gmane.org/gmane.comp.python.matplotlib.general/34361
|
|
From: Jorge S. <jor...@ya...> - 2014-06-05 13:12:06
|
Jorge Scandaliaris <jorgesmbox-ml@...> writes:
>
> Hi,
> I just mentioned this problem with Qt4Agg and python 3.4 in another thread
> [1], but I decided to post it on a thread of its own, as I suspect it might
> be a bug in the Qt4Agg backend.
>
> I get a NameError exception (see backtrace below) when trying to use key
> events in matplotlib (master branch rev:
> e322d5f5bb024bbec44d3ba76da1bc16bf52af9c), python 3.4.1, and pyqt 4.10.
> Is this a bug?
I can confirm that using chr() instead of unichr() fixes this problem. I
don't know how ones handle python2 vs python3 in these cases
diff --git a/lib/matplotlib/backends/backend_qt4.py
b/lib/matplotlib/backends/backend_qt4.py
index 70152aa..b0d8233 100644
--- a/lib/matplotlib/backends/backend_qt4.py
+++ b/lib/matplotlib/backends/backend_qt4.py
@@ -362,7 +362,7 @@ class FigureCanvasQT(QtGui.QWidget, FigureCanvasBase):
if event_key > MAX_UNICODE:
return None
- key = unichr(event_key)
+ key = chr(event_key)
# qt delivers capitalized letters. fix capitalization
# note that capslock is ignored
if 'shift' in mods:
jorge
|
|
From: Werner <wer...@gm...> - 2014-06-05 13:24:39
|
On 6/5/2014 15:10, Jorge Scandaliaris wrote: > Jorge Scandaliaris <jorgesmbox-ml@...> writes: > >> Hi, >> I just mentioned this problem with Qt4Agg and python 3.4 in another thread >> [1], but I decided to post it on a thread of its own, as I suspect it might >> be a bug in the Qt4Agg backend. >> >> I get a NameError exception (see backtrace below) when trying to use key >> events in matplotlib (master branch rev: >> e322d5f5bb024bbec44d3ba76da1bc16bf52af9c), python 3.4.1, and pyqt 4.10. >> Is this a bug? > I can confirm that using chr() instead of unichr() fixes this problem. I > don't know how ones handle python2 vs python3 in these cases > > diff --git a/lib/matplotlib/backends/backend_qt4.py > b/lib/matplotlib/backends/backend_qt4.py > index 70152aa..b0d8233 100644 > --- a/lib/matplotlib/backends/backend_qt4.py > +++ b/lib/matplotlib/backends/backend_qt4.py > @@ -362,7 +362,7 @@ class FigureCanvasQT(QtGui.QWidget, FigureCanvasBase): > if event_key > MAX_UNICODE: > return None > > - key = unichr(event_key) > + key = chr(event_key) > # qt delivers capitalized letters. fix capitalization > # note that capslock is ignored > if 'shift' in mods: You would use 'six' - https://pypi.python.org/pypi/six it is used by many packages including wxPython. import six if six.PY3: key = chr(event_key) else: key = unichr(event_key) Werner |
|
From: V. A. S. <so...@es...> - 2014-06-05 13:46:12
|
On 05/06/2014 15:24, Werner wrote: > On 6/5/2014 15:10, Jorge Scandaliaris wrote: >> Jorge Scandaliaris <jorgesmbox-ml@...> writes: >> >>> Hi, >>> I just mentioned this problem with Qt4Agg and python 3.4 in another thread >>> [1], but I decided to post it on a thread of its own, as I suspect it might >>> be a bug in the Qt4Agg backend. >>> >>> I get a NameError exception (see backtrace below) when trying to use key >>> events in matplotlib (master branch rev: >>> e322d5f5bb024bbec44d3ba76da1bc16bf52af9c), python 3.4.1, and pyqt 4.10. >>> Is this a bug? >> I can confirm that using chr() instead of unichr() fixes this problem. I >> don't know how ones handle python2 vs python3 in these cases >> >> diff --git a/lib/matplotlib/backends/backend_qt4.py >> b/lib/matplotlib/backends/backend_qt4.py >> index 70152aa..b0d8233 100644 >> --- a/lib/matplotlib/backends/backend_qt4.py >> +++ b/lib/matplotlib/backends/backend_qt4.py >> @@ -362,7 +362,7 @@ class FigureCanvasQT(QtGui.QWidget, FigureCanvasBase): >> if event_key > MAX_UNICODE: >> return None >> >> - key = unichr(event_key) >> + key = chr(event_key) >> # qt delivers capitalized letters. fix capitalization >> # note that capslock is ignored >> if 'shift' in mods: > You would use 'six' - https://pypi.python.org/pypi/six it is used by > many packages including wxPython. > > import six > > if six.PY3: > key = chr(event_key) > > else: > key = unichr(event_key) > Just for info. I had never heard about six. Is there anything wrong using sys???: import sys if sys.version < "3.0": key = unichr(event_key) else: key = chr(event_key) Thanks, Armando |
|
From: Werner <wer...@gm...> - 2014-06-05 14:01:47
|
On 6/5/2014 15:45, "V. Armando Solé" wrote: ... >> You would use 'six' - https://pypi.python.org/pypi/six it is used by >> many packages including wxPython. >> >> import six >> >> if six.PY3: >> key = chr(event_key) >> >> else: >> key = unichr(event_key) >> > Just for info. > > I had never heard about six. Is there anything wrong using sys???: > > import sys > if sys.version < "3.0": > key = unichr(event_key) > else: > key = chr(event_key) > > Thanks, Using 'six' for just the above case is definitely overkill, but it has many more goodies in it to make py2/py3 single source code easier. Werner |
|
From: Jorge S. <jor...@ya...> - 2014-06-05 22:02:09
|
Jorge Scandaliaris <jorgesmbox-ml@...> writes:
>
> Hi,
> I just mentioned this problem with Qt4Agg and python 3.4 in another thread
> [1], but I decided to post it on a thread of its own, as I suspect it might
> be a bug in the Qt4Agg backend.
>
> I get a NameError exception (see backtrace below) when trying to use key
> events in matplotlib (master branch rev:
> e322d5f5bb024bbec44d3ba76da1bc16bf52af9c), python 3.4.1, and pyqt 4.10.
> Is this a bug?
>
A trivial fix using six (credits to Werner for suggesting it), also
submitted as issue #3117 in the GH tracker:
diff --git a/lib/matplotlib/backends/backend_qt4.py
b/lib/matplotlib/backends/backend_qt4.py
index 70152aa..26486b4 100644
--- a/lib/matplotlib/backends/backend_qt4.py
+++ b/lib/matplotlib/backends/backend_qt4.py
@@ -362,7 +362,7 @@ class FigureCanvasQT(QtGui.QWidget, FigureCanvasBase):
if event_key > MAX_UNICODE:
return None
- key = unichr(event_key)
+ key = six.unichr(event_key)
# qt delivers capitalized letters. fix capitalization
# note that capslock is ignored
if 'shift' in mods:
|