Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt4 backend using unichr() in python3 #3117

Closed
jorgesca opened this issue Jun 5, 2014 · 4 comments · Fixed by #3131
Closed

Qt4 backend using unichr() in python3 #3117

jorgesca opened this issue Jun 5, 2014 · 4 comments · Fixed by #3131
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug
Milestone

Comments

@jorgesca
Copy link

jorgesca commented Jun 5, 2014

I get a NameError exception (see backtrace below) when trying to use key
events in matplotlib (master branch rev:
e322d5f), python 3.4.1, and pyqt 4.10.
This has been posted to the matplotlib-users ml: http://thread.gmane.org/gmane.comp.python.matplotlib.general/34364

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
@jorgesca
Copy link
Author

jorgesca commented Jun 5, 2014

A trivial fix using six:

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:

@tacaswell
Copy link
Member

I actually have a patch with these fixes (there is at least one other instance of unichr iirc) on my computer and just never got to pushing them up...

@tacaswell tacaswell added this to the v1.4.0 milestone Jun 5, 2014
@efiring
Copy link
Member

efiring commented Jun 5, 2014

Good--I thought this sounded very familiar.

@tacaswell
Copy link
Member

Now I remember why I didn't push it up, it's mixed up with the qt5 work.

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jun 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants