From: Igor on
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
"Yair Altman" <altmanyDEL(a)gmailDEL.comDEL> wrote in message <i1u35j$i81$1(a)fred.mathworks.com>...
>[&#8230;]
> 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&#8230; that&#8217;s why I needed to use findobj every update. Well&#8230; it&#8217;s OK now.
&#8216;nomenu&#8217; twice and all output args are just results of &#8216;routh draft&#8217; nature of those function&#8230; Yet &#8216;depth&#8217; parameter seemed to increase performance&#8230; Now, after tic-toc test (down here) I can see it gives nothing.

The only little trouble now is &#8216;initialisation&#8217; &#8211;where to perform those findobj &#8211; it returns nothing being used in &#8216;GUIopeningFunction&#8217;. There is no &#8216;post opening&#8217; callback provided in matlab. So, by now, &#8216;findobj&#8217; is performed just before first use of it&#8217;s result. May be this is not that bad, this way it won&#8217;t affect GUI loading time. Yet, is there any way to implement some &#8216;post-opening&#8217; 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
> The only little trouble now is &#8216;initialisation&#8217; &#8211;where to perform those findobj &#8211; it returns nothing being used in &#8216;GUIopeningFunction&#8217;. There is no &#8216;post opening&#8217; callback provided in matlab. So, by now, &#8216;findobj&#8217; is performed just before first use of it&#8217;s result. May be this is not that bad, this way it won&#8217;t affect GUI loading time. Yet, is there any way to implement some &#8216;post-opening&#8217; 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
"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&#8217;t affect GUI loading time now.
Thanks for your help.