On Wednesday 17 February 2010 15:28:24 John Hunter wrote:
> On Wed, Feb 17, 2010 at 8:08 AM, Matthias Michler
>
> <matthiasmich...@gmx.net> wrote:
> > Hi list, Hi Gökhan,
> >
> > I once more would like to say that I like the 2 new features introduced
> > by Gökhan (key 'k' for xscaling and the generalized handling of the
> > key-mapping, which allows the user to choose its prefered key for a
> > certain task) and I'd like to see this in matplotlib.
> >
> > I attached a patch (against todays svn) of my final version, which is a
> > slightly modified version of Gökhans patch.
> >
> > If anybody could test it and comments on this I'd be happy. Otherwise I
> > will place the patch on the patch tracker in (let's say) a week.
> >
> > Thanks in advance for any help in order to bring this into matplotlib.
>
> Hi -- these look like useful changes.  In most of matplotlib rc we
> have a namespace for the rc keys, so I prefer something like
>
>   keymap.fullscreen : f               # toggling
>   keymap.home : h, r, home            # home or reset mnemonic
>
> Also, could you include in your patch a diff against
>
>   mpl/doc/users/navigation_toolbar.rst
>
> documenting the changes.
>
> Also, I'm not sure you need
>
> +        # to get a common standard we move all keys for each action into a
> list +        for key in [fullscreen_keys, home_keys, back_keys,
> forward_keys, +                    pan_keys, zoom_keys, save_keys,
> grid_keys,
> +                    toggle_xscale_keys, toggle_yscale_keys, all]:
> +            if type(key) is not list:
> +                key = list(key)
> +
>
> If you setup your validate func properly in rcsetup, you can guarantee
> that each of these keymap.* entries will be a list of strings, even
> those changes interactively from the prompt.  So I suggest changing
> each of these key entries to have a validate_stringlist validator and
> then you won't need this check.

Hi John,

thanks a lot for taking the time to go through this patch. I tried to 
incorporate you remarks and attached a new patch. 
The most difficult task is about the 
documentation 'mpl/doc/users/navigation_toolbar.rst', because I'm not sure 
what is needed and I not familiar with the used programming language.

Kind regards,
Matthias 
Index: matplotlibrc.template
===================================================================
--- matplotlibrc.template	(revision 8139)
+++ matplotlibrc.template	(working copy)
@@ -360,3 +360,20 @@
 #   from matplotlib import verbose.
 #verbose.level  : silent      # one of silent, helpful, debug, debug-annoying
 #verbose.fileo  : sys.stdout  # a log filename, sys.stdout or sys.stderr
+
+# Event keys to interact with figures/plots via keyboard.
+# Customize these settings according to your needs. 
+# Leave the field(s) empty if you don't need a key-map. (i.e., fullscreen : '') 
+
+#keymap.fullscreen : f               # toggling    
+#keymap.home : h, r, home            # home or reset mnemonic
+#keymap.back : left, c, backspace    # forward / backward keys to enable 
+#keymap.forward : right, v           #   left handed quick navigation
+#keymap.pan : p                      # pan mnemonic
+#keymap.zoom : o                     # zoom mnemonic
+#keymap.save : s                     # saving current figure
+#keymap.grid : g                     # switching on/off a grid in current axes
+#keymap.yscale : l                   # toggle scaling of y-axes ('log'/'linear')
+#keymap.xscale : L, k                # toggle scaling of x-axes ('log'/'linear')
+#keymap.all_axes : a                 # enable all axes
+
Index: lib/matplotlib/backend_bases.py
===================================================================
--- lib/matplotlib/backend_bases.py	(revision 8139)
+++ lib/matplotlib/backend_bases.py	(working copy)
@@ -1888,50 +1888,85 @@
         #    self.destroy() # how cruel to have to destroy oneself!
         #    return
 
-        if event.key == 'f':
+        # Load key-mappings from your matplotlibrc file.
+        fullscreen_keys = rcParams['keymap.fullscreen']
+        home_keys = rcParams['keymap.home']
+        back_keys = rcParams['keymap.back']
+        forward_keys = rcParams['keymap.forward']
+        pan_keys = rcParams['keymap.pan']
+        zoom_keys = rcParams['keymap.zoom']
+        save_keys = rcParams['keymap.save']
+        grid_keys = rcParams['keymap.grid']
+        toggle_yscale_keys = rcParams['keymap.yscale']
+        toggle_xscale_keys = rcParams['keymap.xscale']
+        all = rcParams['keymap.all_axes']
+
+        # toggle fullscreen mode (default key 'f')
+        if event.key in fullscreen_keys:
             self.full_screen_toggle()
 
-        # *h*ome or *r*eset mnemonic
-        elif event.key == 'h' or event.key == 'r' or event.key == "home":
+        # home or reset mnemonic  (default key 'h', 'home' and 'r')
+        elif event.key in home_keys:
             self.canvas.toolbar.home()
-        # c and v to enable left handed quick navigation
-        elif event.key == 'left' or event.key == 'c' or event.key == 'backspace':
+        # forward / backward keys to enable left handed quick navigation
+        # (default key for backward: 'left', 'backspace' and 'c')
+        elif event.key in back_keys:
             self.canvas.toolbar.back()
-        elif event.key == 'right' or event.key == 'v':
+        # (default key for forward: 'right' and 'v')
+        elif event.key in forward_keys:
             self.canvas.toolbar.forward()
-        # *p*an mnemonic
-        elif event.key == 'p':
+        # pan mnemonic (default key 'p')
+        elif event.key in pan_keys:
             self.canvas.toolbar.pan()
-        # z*o*om mnemonic
-        elif event.key == 'o':
+        # zoom mnemonic (default key 'o')
+        elif event.key in zoom_keys:
             self.canvas.toolbar.zoom()
-        elif event.key == 's':
+        # saving current figure (default key 's')
+        elif event.key in save_keys:
             self.canvas.toolbar.save_figure(self.canvas.toolbar)
 
         if event.inaxes is None:
             return
 
         # the mouse has to be over an axes to trigger these
-        if event.key == 'g':
+        # switching on/off a grid in current axes (default key 'g')
+        if event.key in grid_keys:
             event.inaxes.grid()
             self.canvas.draw()
-        elif event.key == 'l':
+        # toggle scaling of y-axes between 'log and 'linear' (default key 'l')
+        elif event.key in toggle_yscale_keys:
             ax = event.inaxes
             scale = ax.get_yscale()
-            if scale=='log':
+            if scale == 'log':
                 ax.set_yscale('linear')
                 ax.figure.canvas.draw()
-            elif scale=='linear':
+            elif scale == 'linear':
                 ax.set_yscale('log')
                 ax.figure.canvas.draw()
+        # toggle scaling of x-axes between 'log and 'linear' (default key 'k')
+        elif event.key in toggle_xscale_keys:
+            ax = event.inaxes
+            scalex = ax.get_xscale()
+            if scalex == 'log':
+                ax.set_xscale('linear')
+                ax.figure.canvas.draw()
+            elif scalex == 'linear':
+                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=='a':
-            # 'a' enables all axes
-            if event.key!='a':
-                n=int(event.key)-1
+        elif event.key is not None and \
+                 (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
+            if not (event.key in all):
+                n = int(event.key)-1
             for i, a in enumerate(self.canvas.figure.get_axes()):
-                if event.x is not None and event.y is not None and a.in_axes(event):
-                    if event.key=='a':
+                # consider axes, in which the event was raised
+                # FIXME: Why only this axes?
+                if event.x is not None and event.y is not None \
+                       and a.in_axes(event):
+                    if event.key in all:
                         a.set_navigate(True)
                     else:
                         a.set_navigate(i==n)
Index: lib/matplotlib/rcsetup.py
===================================================================
--- lib/matplotlib/rcsetup.py	(revision 8139)
+++ lib/matplotlib/rcsetup.py	(working copy)
@@ -546,9 +546,22 @@
 
     'path.simplify' : [True, validate_bool],
     'path.simplify_threshold' : [1.0 / 9.0, ValidateInterval(0.0, 1.0)],
-    'agg.path.chunksize' : [0, validate_int]       # 0 to disable chunking;
-                                                   # recommend about 20000 to
-                                                   # enable. Experimental.
+    'agg.path.chunksize' : [0, validate_int],       # 0 to disable chunking;
+                                                    # recommend about 20000 to
+                                                    # enable. Experimental.
+    # key-mappings
+    'keymap.fullscreen' : ['f', validate_stringlist],   
+    'keymap.home' : [['h', 'r', 'home'], validate_stringlist],
+    'keymap.back' : [['left', 'c', 'backspace'], validate_stringlist],
+    'keymap.forward' : [['right', 'v'], validate_stringlist],
+    'keymap.pan' : ['p', validate_stringlist],
+    'keymap.zoom' : ['o', validate_stringlist],     
+    'keymap.save' : ['s', validate_stringlist],
+    'keymap.grid' : ['g', validate_stringlist],
+    'keymap.yscale' : ['l', validate_stringlist],
+    'keymap.xscale' : [['k', 'L'], validate_stringlist],
+    'keymap.all_axes' : ['a', validate_stringlist]
+
 }
 
 if __name__ == '__main__':
Index: doc/users/navigation_toolbar.rst
===================================================================
--- doc/users/navigation_toolbar.rst	(revision 8139)
+++ doc/users/navigation_toolbar.rst	(working copy)
@@ -79,6 +79,8 @@
 Navigation Keyboard Shortcuts
 -----------------------------
 
+The following table holds all the default keys, which can be overwritten by use of your matplotlibrc (#keymap.\*).
+
 ================================== ==============================================
 Command                            Keyboard Shortcut(s)
 ================================== ==============================================
@@ -93,6 +95,7 @@
 Constrain pan/zoom to y axis       hold **y**
 Preserve aspect ratio              hold **CONTROL**
 Toggle grid                        **g**
+Toggle x axis scale (log/linear)   **L** or **k**
 Toggle y axis scale (log/linear)   **l**
 ================================== ==============================================
 
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to