Prev: xlswrite
Next: ginput clears 'WindowScrollWheelFcn'?
From: Sven on 31 May 2010 13:23 Hi all, I am often clicking the various plot exploration tools (rotate, pan, zoom), and I want to make things easier for myself by adding shortcut keys. Consider the following code: figure('KeyPressFcn','rotate3d') surf(peaks(30)); My (simplified) intent here is to toggle the rotate3d tool on my figure whenever a key is pressed. This works to turn *on* the rotate3d tool, but once I'm in rotate3d mode, any subsequent key presses get redirected to the MATLAB command line (instead of executing my 'KeyPressFcn' above. Can anyone point out what is going on here and how I can get my desired functionality? It seems that you can turn rotate3d *on* with a keypress, but not *off*. Thanks, Sven.
From: Walter Roberson on 31 May 2010 13:50 Sven wrote: > I am often clicking the various plot exploration tools (rotate, pan, > zoom), and I want to make things easier for myself by adding shortcut > keys. Consider the following code: > > figure('KeyPressFcn','rotate3d') > surf(peaks(30)); > > My (simplified) intent here is to toggle the rotate3d tool on my figure > whenever a key is pressed. This works to turn *on* the rotate3d tool, > but once I'm in rotate3d mode, any subsequent key presses get redirected > to the MATLAB command line (instead of executing my 'KeyPressFcn' above. > > Can anyone point out what is going on here and how I can get my desired > functionality? > It seems that you can turn rotate3d *on* with a keypress, but not *off*. I'm not certain about rotate3d but I am certain about zoom: it *does* deactivate your keypressfcn, and it does so in a way that tells Matlab not to allow you to install your own afterwards. I get around it this way. This code installs newCB as the new callback; I have code in my callback to remove itself and restore the old hook. oldkeyhook = get(zfigh, 'KeyPressFcn'); newkeyhook = oldkeyhook; newkeyhook{1} = newCB; h = zoom(zfigh); set(h, 'Enable', 'on'); hManager = uigetmodemanager(zfigh); set(hManager.WindowListenerHandles,'Enable','off'); % zap the listeners % with the listners turned off we can put in our own hook set(zfigh, 'KeyPressFcn', newkeyhook );
From: Sven on 31 May 2010 14:24 Walter Roberson <roberson(a)hushmail.com> wrote in message <pFSMn.37741$Ak3.3367(a)newsfe16.iad>... > Sven wrote: > > > I am often clicking the various plot exploration tools (rotate, pan, > > zoom), and I want to make things easier for myself by adding shortcut > > keys. Consider the following code: > > > > figure('KeyPressFcn','rotate3d') > > surf(peaks(30)); > > > > My (simplified) intent here is to toggle the rotate3d tool on my figure > > whenever a key is pressed. This works to turn *on* the rotate3d tool, > > but once I'm in rotate3d mode, any subsequent key presses get redirected > > to the MATLAB command line (instead of executing my 'KeyPressFcn' above. > > > > Can anyone point out what is going on here and how I can get my desired > > functionality? > > It seems that you can turn rotate3d *on* with a keypress, but not *off*. > > I'm not certain about rotate3d but I am certain about zoom: it *does* > deactivate your keypressfcn, and it does so in a way that tells Matlab > not to allow you to install your own afterwards. > > I get around it this way. This code installs newCB as the new callback; > I have code in my callback to remove itself and restore the old hook. > > > oldkeyhook = get(zfigh, 'KeyPressFcn'); > newkeyhook = oldkeyhook; > newkeyhook{1} = newCB; > > h = zoom(zfigh); > set(h, 'Enable', 'on'); > > hManager = uigetmodemanager(zfigh); > set(hManager.WindowListenerHandles,'Enable','off'); % zap the listeners > % with the listners turned off we can put in our own hook > set(zfigh, 'KeyPressFcn', newkeyhook ); Thanks, Walter. I think that it's a reasonably major flaw that doing something as simple as this requires resorting to undocumented MATLAB features. It makes me think that anything approaching a user-friendly 3D interface like those seen in various CAD programs (you know, the Ctrl+left-click for rotate, Ctrl+right-click for zoom, etc) is a long way off. I wish this weren't the case and hope it's high on the agenda for the next release to make it easier to create useful 3D exploration tools. Cheers, Sven.
From: Yair Altman on 1 Jun 2010 07:55 Walter Roberson <roberson(a)hushmail.com> wrote in message > I'm not certain about rotate3d but I am certain about zoom: it *does* > deactivate your keypressfcn, and it does so in a way that tells Matlab > not to allow you to install your own afterwards. This is correct. In Matlab GUI, a "mode" is a set of defined behaviors that may be set for any figure window and activated/deactivated via the figure's menu, toolbar or programmatically. Examples of predefined modes are plot edit, zoom, pan, rotate3d and data-cursor. Only one mode can be active in a figure at any one time – this is managed via a figure's ModeManager. Activating a figure mode automatically deactivates any other active mode, as can be seen when switching between plot edit, zoom, pan, rotate3d and data-cursor modes. During an active mode, the ModeManager disables user-configured mouse and keyboard callbacks, in order to prevent interference with the mode's functionality. For example, mouse clicking during zoom mode has a very specific meaning, and user-configured callbacks might interfere with it. Understanding this and taking the proper precautions (for example: chaining the default mode's callback at the beginning or end of our own callback), we can override this default behavior, as Walter has shown above. Yair Altman http://UndocumentedMatlab.com
|
Pages: 1 Prev: xlswrite Next: ginput clears 'WindowScrollWheelFcn'? |