On Jun 1, 2010, at 8:59 AM, João Luís Silva wrote:

> Hi,
> 
> Pressing tab, the "Windows" key or the right click key (and maybe 
> others) on a plot with the GTKAgg or GTK backend causes the following 
> traceback:
> 
> Traceback (most recent call last):

[snip]

>   File "/usr/lib/python2.5/site-packages/matplotlib/backend_bases.py", 
> line 2079, in key_press
>     if event.key in fullscreen_keys:
> TypeError: 'in <string>' requires string as left operand
> 
> This happens because in these cases the key is None. The WXAgg backend 
> doesn't have this bug (I haven't tested qt nor tk backends).


This is similar to an issue I had. I posted a patch for my error, but it was 
specific to Qt4 and required all keys to be manually added to the class 
definition. I suggested a more robust solution: returning early in 
backend_bases when the key is None. That suggestion kind of died after Darren 
Dale solicited responses from other devs.

If it helps at all, I've attached a very simple patch. The early return at the 
top of the patch is the important part. The change near the bottom is added 
because we've already checked for None (i.e. purely cosmetic).

-Tony


Index: lib/matplotlib/backend_bases.py
===================================================================
--- lib/matplotlib/backend_bases.py     (revision 8366)
+++ lib/matplotlib/backend_bases.py     (working copy)
@@ -2062,6 +2062,8 @@
         #    self.destroy() # how cruel to have to destroy oneself!
         #    return
 
+        if event.key is None:
+            return
         # Load key-mappings from your matplotlibrc file.
         fullscreen_keys = rcParams['keymap.fullscreen']
         home_keys = rcParams['keymap.home']
@@ -2128,8 +2130,7 @@
                 ax.set_xscale('log')
                 ax.figure.canvas.draw()
 
-        elif event.key is not None and \
-                 (event.key.isdigit() and event.key!='0') or event.key in all:
+        elif (event.key.isdigit() and event.key!='0') or event.key in all:
             # keys in list 'all' enables all axes (default key 'a'),
             # otherwise if key is a number only enable this particular axes
             # if it was the axes, where the event was raised

------------------------------------------------------------------------------

_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to