MATLAB: Toolbar pushbutton not receiving updated strings from figure handles. -


i have gui edit box , push button on tool bar (well, more things that, things matter!) anyway, have when press push button tool variable set equal string in edit box. simple var = get(handles.edit1, 'string'). however, when go straight entering value in box clicking pushbutton (without clicking anywhere else or pressing return), var assigned previous value in edit box. why this? there way make sure push button tool pick out correct value?

the gui made using guide, if matters.

this happening because uipushtool callback executing before text box has time 'validate'. there surely more elegant way trick works:

you can use waitfor command tell uipushtool callback wait editable box validate input. unfortunately is not enough we'll have to:

1) pass focus dummy control (i created dummy pushbutton named pushbutton1 nothing. focus send other dummy control.

2) wait text box validate content.

3) when text box done, retrieve content traditional way.

this method requires:
- dummy control send focus (but can use real 1 too)
- dummy (or not) callback function editable box. (the waitfor instruction wait callback finish, if there no callback, error

function uipushtool1_clickedcallback(hobject, eventdata, handles)      uicontrol( handles.pushbutton1 ) ; %// pass focus dummy control     waitfor(handles.edit1,'string');   %// wait editable box validate content     var = get(handles.edit1, 'string') ; %// retrieve editable box content      set( handles.text1 , 'string' , var ) %// can deleted, verify method  % --------------------------------------------------------------------  function edit1_callback(hobject, eventdata, handles)     %// dummy callback function editable box     %// absolutely nothing here (or if want ... choice) 

edit

as feared, initial solution dirty robust enough. 2 (or more) textboxes, tried large number of things without success. dropped waitfor, noticed in case, when uipushtool pressed, callback of editbox fire uipushtool not execute @ ... tried managed things directly editbox callback => editbox keypressedfcn send each character type variable ... editbox callback doesn't know content of edit box @ time executed ?? (this link provide simple example reproduce that).

so great own disappointment, had resort 'external' solution. (if accept becomes simple though). trick retrieve handle of java editbox object. once have handle, getting "real time" content matter of converting java string matlab string.

to retrieve java object handles, need function findjobj matlab central.

put anywhere in matlab path, code pushbutton become :
to make sure there no interferences between text boxes , uipushtools made 2 separate uipushtools each controlling 1 editbox

function uipushtool1_clickedcallback(hobject, eventdata, handles)     jeditbox = findjobj(handles.edit1); %// handle of java editbox #1     var = char(jeditbox.gettext) ; %// retrieve java string , convert matlab string      disp(['uipushtool1_clickedcallback running. textbox1 content = ' var ]) %// debug line, can delete or comment  % -------------------------------------------------------------------- function uipushtool2_clickedcallback(hobject, eventdata, handles)     jeditbox = findjobj(handles.edit2); %// handle of java editbox #2     var = char(jeditbox.gettext) ; %// retrieve java string , convert matlab string      disp(['uipushtool2_clickedcallback running. textbox2 content = ' var ]) %// debug line, can delete or comment 

thanks yair altman findjobj function, and many other contributions matlab users.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -