From: Igor on 17 Jul 2010 18:47 I'd like to know edit's value while edit is in progress(still has focus). At first I've tried simple get(handle,'String') in @KeyPressFcn. Yet, result contains the value edit had before it was edited....This value only 'refreshes' after focus was lost. There was a tiny hope of 'Action' event (as with slider continuous callback)- this event never occurs. So, this lead us to java… I’m a complete newbie about it… The only way I managed to do this somehow is using findjobj: http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects try [handles, levels, parentIds, listing] = findjobj(handle,'nomenu',... 'class','edit',... 'nomenu',... 'depth',15); for i=1:length(handles) Uhandle=get(handles(i)); jColor=Uhandle.Foreground; R=get(jColor,'Red'); G=get(jColor,'Green'); B=get(jColor,'Blue'); if all([R G B]==uniq_color*256) Jobj=Uhandle; break; end end catch Jobj=[]; end here, str=obj.Jobj.Text; is the string we want. But all this doesn’t look like best way to access that property.. also -“pure” findjobj(…) sometimes return numerous handles. Is there any thing we can be sure to be uniq for this object. Where is ‘tag’ stored? Also, findobj is slow, it takes about half a second every time. And we need to update every KeyPress, Jobj.Text is not changing either…
From: Igor on 18 Jul 2010 09:41 "Yair Altman" <altmanyDEL(a)gmailDEL.comDEL> wrote in message <i1u35j$i81$1(a)fred.mathworks.com>... >[…] > FindJObj does not need to be called every time - you can use it to get the Java handle in your *_OutputFcn function, store this handle somewhere persistent (for example, in the handles struct) and then directly use this handle from that point onward. > > Also, there is no need to pass the 'nomenu' argument twice to FindJObj and I also see no reason for using the 'depth' parameter. There is also no reason for all the output args - only the first (handles) is really needed in your case. > > Yair Altman > http://UndocumentedMatlab.com Thanks for your answer, Seems like my main dumb mistake was to store result of get(handles(i)) , instead of handles(i) itself, in my persistent class… that’s why I needed to use findobj every update. Well… it’s OK now. ‘nomenu’ twice and all output args are just results of ‘routh draft’ nature of those function… Yet ‘depth’ parameter seemed to increase performance… Now, after tic-toc test (down here) I can see it gives nothing. The only little trouble now is ‘initialisation’ –where to perform those findobj – it returns nothing being used in ‘GUIopeningFunction’. There is no ‘post opening’ callback provided in matlab. So, by now, ‘findobj’ is performed just before first use of it’s result. May be this is not that bad, this way it won’t affect GUI loading time. Yet, is there any way to implement some ‘post-opening’ callback? I was not able to find something like that in handles output. global GUI_handles a=tic(); handles= findjobj(GUI_handles.UM_edit1,... 'class','edit','nomenu','depth',20); disp(['Single exec:' num2str(toc(a))] ); a=tic(); for i=1:10 handles = findjobj(GUI_handles.UM_edit1,... 'class','edit','nomenu','depth',20); end disp(['10times exec:' num2str(toc(a))] ); a=tic(); for i=1:10 [handles, levels, parentIds, listing] = findjobj(GUI_handles.UM_edit1,... 'class','edit','nomenu','depth',20); end disp(['10times-4 outputs exec:' num2str(toc(a))] ); a=tic(); for i=1:10 handles = findjobj(GUI_handles.UM_edit1,... 'class','edit','nomenu','depth',100); end disp(['10times-depth=100 exec:' num2str(toc(a))] ); a=tic(); for i=1:10 handles = findjobj(GUI_handles.UM_edit1,... 'class','edit','nomenu'); end disp(['10times-depth=Inf exec:' num2str(toc(a))] ); output: list_handles Single exec:1.3854 10times exec:13.6792 10times-4 outputs exec:13.8726 10times-depth=100 exec:14.1215 10times-depth=Inf exec:13.8045
From: Yair Altman on 18 Jul 2010 11:17 > The only little trouble now is ‘initialisation’ –where to perform those findobj – it returns nothing being used in ‘GUIopeningFunction’. There is no ‘post opening’ callback provided in matlab. So, by now, ‘findobj’ is performed just before first use of it’s result. May be this is not that bad, this way it won’t affect GUI loading time. Yet, is there any way to implement some ‘post-opening’ callback? I was not able to find something like that in handles output. Java objects are only created when the GUI is actually displayed. In your GUI's _OpeningFcn, they are not yet created so FindJObj obviously cannot find them. Instead, place FindJObj in your _OutputFcn as I already mentioned above. You don't need to keep the handle - simply set its KeyReleasedCallback or KeyTypedCallback to your Matlab callback function. From that point onward, you don't need to use findjobj ever again. Yair Altman http://UndocumentedMatlab.com
From: Igor on 18 Jul 2010 14:48 "Yair Altman" <altmanyDEL(a)gmailDEL.comDEL> wrote in message <i1v5tg$5f9$1(a)fred.mathworks.com>... > Java objects are only created when the GUI is actually displayed. In your GUI's _OpeningFcn, they are not yet created so FindJObj obviously cannot find them. Instead, place FindJObj in your _OutputFcn as I already mentioned above. > > You don't need to keep the handle - simply set its KeyReleasedCallback or KeyTypedCallback to your Matlab callback function. From that point onward, you don't need to use findjobj ever again. > > Yair Altman > http://UndocumentedMatlab.com Eventually, I did it this way. My previous idea was to initialize it along with over GUI elements, within class constructor placed in Opening Function. Well, the good thing is this doesn’t affect GUI loading time now. Thanks for your help.
|
Pages: 1 Prev: Using objects on two picture layers to determine a direction Next: full car model loadings |