Comments on: Enabling user callbacks during zoom/pan https://undocumentedmatlab.com/blog_old/enabling-user-callbacks-during-zoom-pan Charting Matlab's unsupported hidden underbelly Sun, 03 Jul 2022 14:46:57 +0000 hourly 1 https://wordpress.org/?v=4.4.1 By: Thommyhttps://undocumentedmatlab.com/blog_old/enabling-user-callbacks-during-zoom-pan#comment-415223 Fri, 20 Oct 2017 07:15:09 +0000 https://undocumentedmatlab.com/?p=6043#comment-415223 Thank you mate, I’ve passed quite some time on that issue. You made my day !

]]>
By: Davidhttps://undocumentedmatlab.com/blog_old/enabling-user-callbacks-during-zoom-pan#comment-385887 Wed, 17 Aug 2016 15:11:39 +0000 https://undocumentedmatlab.com/?p=6043#comment-385887 I explored this a bit more and the problem is specific to the key input ctrl-z. Any other keystroke is passed to my callback, but ctrl-z is trapped and interpreted by the zoom’s own callback. The question remains how do I override this behavior?

]]>
By: Davidhttps://undocumentedmatlab.com/blog_old/enabling-user-callbacks-during-zoom-pan#comment-385877 Wed, 17 Aug 2016 13:34:05 +0000 https://undocumentedmatlab.com/?p=6043#comment-385877 I’m trying to apply this approach in the zoomIn toolbar callback:

function zoomIn_OnCallback(hObject, eventdata, handles)
  [handles.mode_manager.WindowListenerHandles.Enabled] = deal(false);
  handles.theGui.WindowKeyPressFcn =  [];
  handles.theGui.KeyPressFcn = @theGui_KeyPressFcn;
end

where handles.mode_manager was set to uigetmodemanager in the GUIDE generated OpeningFcn. I can verify in the debugger that the call is executed and the callback is being assigned to theGui handle. The callback theGui_KeyPressFcn has the desired behavior when not in zoom mode, but in zoom mode it is not being called in spite of the above code.

Obviously I’ve missed something here, but I can’t see what it is.
(I’m not concerned about backwards compatibility, so I skipped the try/catch)

]]>
By: i3vhttps://undocumentedmatlab.com/blog_old/enabling-user-callbacks-during-zoom-pan#comment-379143 Sat, 04 Jun 2016 15:25:18 +0000 https://undocumentedmatlab.com/?p=6043#comment-379143 Yair,
Thanks for the code!
Still, it looks like these few lines is not the only thing to keep in mind.
I was unable to find a complete, fully working example, so I’ve decided to write my own. Hope it would be helpful for those who would try to to re-define these callbacks as well.
http://www.mathworks.com/matlabcentral/fileexchange/57496-i3v-figkeys

]]>
By: Mauriziohttps://undocumentedmatlab.com/blog_old/enabling-user-callbacks-during-zoom-pan#comment-369879 Sun, 14 Feb 2016 15:19:29 +0000 https://undocumentedmatlab.com/?p=6043#comment-369879 Oh, I see what you mean. I’ll give that a try, thanks.
Meanwhile I fixed the problem with this line of code.

set(handles.figure1, 'KeyPressFcn', ...
           @(hObject,eventdata)myGui('figure1_KeyPressFcn', hObject,eventdata,guidata(hObject)));

I simply copied the anonymous function from the Property Inspector of figure1 in GUIDE.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/enabling-user-callbacks-during-zoom-pan#comment-369832 Sat, 13 Feb 2016 16:56:04 +0000 https://undocumentedmatlab.com/?p=6043#comment-369832 @Maurizio – you are wrong: the figure handle is the first input arg passed to your figure1_KeyPressFcn() callback function. Simply call handles=guidata(hObject) at the beginning of your callback and guidata(hObject,handles) after you modify handles and all should be ok.

In other words, if you keep passing handles as a static struct input arg, then of course it will always have the same values (the values that existed when you called the set(...) command).

]]>
By: Mauriziohttps://undocumentedmatlab.com/blog_old/enabling-user-callbacks-during-zoom-pan#comment-369782 Fri, 12 Feb 2016 21:14:38 +0000 https://undocumentedmatlab.com/?p=6043#comment-369782 Hi Yair, can you mix this approach with the way GUIDE sets callbacks?

This is part of the code I’m currently using, based on your post:

set(handles.figure1, 'KeyPressFcn', {@figure1_KeyPressFcn, handles});

One of the actions defined in figure1_KeyPressFcn increases a variable stored in handles (handles.index) when the right arrow key is pressed. However after running your bit of code the updated value of index is lost every time (i.e. I keep incrementing the same old value). I reckon that depends on hObject not being passed to figure1_KeyPressFcn in the previous snippet of code, which makes guidata(hObject, handles) kind of useless. Unfortunately the following code returns an error (too many input arguments):

set(handles.figure1, 'KeyPressFcn', {@figure1_KeyPressFcn, hObject, eventdata, handles});

Any idea?

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/enabling-user-callbacks-during-zoom-pan#comment-360026 Wed, 28 Oct 2015 15:22:25 +0000 https://undocumentedmatlab.com/?p=6043#comment-360026 @Walter – hManager.WindowListenerHandles is indeed an array of objects (not a single object), so we must enclose it with [] and use deal() in order to set all its elements’ Enabled values to false. Of course, we could also use a simple loop, but using deal is simpler and easier.

]]>
By: Walter Robersonhttps://undocumentedmatlab.com/blog_old/enabling-user-callbacks-during-zoom-pan#comment-360024 Wed, 28 Oct 2015 14:57:50 +0000 https://undocumentedmatlab.com/?p=6043#comment-360024 Thanks for the fix, Yair.

I notice that you use

[hManager.WindowListenerHandles.Enabled] = deal(false);

Is there a benefit to doing that compared to just

 hManager.WindowListenerHandles.Enabled = false;

I could see if it was a structure array where multiple destination might be set, but it is a property ?

]]>