From: jon D on 11 Jan 2010 07:22 Dear All, I have used guide till now (to write a GUI) but now, want to write my gui on my own. my question is: I want to create an object and define a handle to an object in a callback and be able to use it in other callbacks. so till now (with Guide) i did: " function Load_Callback(hObject, eventdata, handles) import mmcorej.*; handles.mmc=CMMCore; guidata(hObject, handles); " then I could use handles.mmc in other functions and callbacks. so I have tried doing it like this: % define the pushbutton and callback: handles.Load_Button = uicontrol( 'Parent', handles.figure1, ... 'Tag', 'Load_Button', ... 'UserData', zeros(1,0), ... 'Style', 'pushbutton', ... 'Units', 'characters', ... 'CData', zeros(1,0)); set (handles.Load_Button,'callback',{@Load_Button_Callback ,handles}); .... % the callback function: function Load_Button_Callback(hObject , eventdata, handles) import mmcorej.*; handles.mmc=CMMCore; guidata(hObject, handles); end But the handles structure is not updated once the function ends. ( I think that the command guidata(hObject,handles) is wrong) also another short question (probably related): what is this for (from guide generated m file): handles.output = hObject; and do i need to do something like this in a GUI I write? Many thanks, Jon Donner
From: Andy on 11 Jan 2010 09:13 You should probably read these: http://www.mathworks.com/matlabcentral/fileexchange/24861-35-complete-gui-examples They are all simple GUIs with short, easy-to-understand code written without GUIDE.
From: jon D on 13 Jan 2010 09:58 Thanks Andy, I have gone over the relevant examples but still can't find an answer Thanks again, JD "Andy " <theorigamist(a)gmail.com> wrote in message <hifblh$6iv$1(a)fred.mathworks.com>... > You should probably read these: > > http://www.mathworks.com/matlabcentral/fileexchange/24861-35-complete-gui-examples > > They are all simple GUIs with short, easy-to-understand code written without GUIDE.
From: Andy on 13 Jan 2010 10:59 % Here is a small sample: function GUI_sample S.fh = figure('units','pixels',... 'position',[200 200 200 500],... 'menubar','none',... 'numbertitle','off',... 'name','GUI_sample',... 'userdata',1,... % stores the number of push buttons 'resize','off'); S.pb = uicontrol('style','pushbutton',... 'units','pix',... 'position',[10 470 180 20],... 'string','Push For New Button',... 'callback',{@pb_call}); function pb_call(src,evnt) numbuttons=get(S.fh,'userdata'); lastpos=get(S.pb(end),'position'); S.pb(numbuttons+1)=uicontrol('style','pushbutton',... 'units','pix',... 'position',lastpos-[0 30 0 0],... 'string','Push For New Button',... 'callback',{@pb_call}); set(S.fh,'userdata',numbuttons+1); % don't forget to update the userdata end end
|
Pages: 1 Prev: Finding n largest values in a matrix Next: 64bits and memory problem |