From: Dan on 19 Jan 2006 10:42 hey have you actually successfully used the gui output fcn? I tried to use uiwait but i still got the same error. I've been fiddling with it for the last 30 minutes and I'm very happy to say I actually figured out the solution. you're solution is very close. I suspended the program using uiwait in the output fcn. Then in my code when I wanted to close the program I typed uiresume. This resumes the output fcn execution except the problem is that the handles revert back to the default handles. to get your handles back you have to use the two lines. handles = guihandles; handles = guidata(handles.figure1); this will give you back your handles. and then after that set your varargout to the outputs you want to output and then close the window if you want. The problem i was having before is that uiwait would resume when i closed my window and when i tried to get my handles back i couldn't cuz the figure was closed already. alright so for anyone trying this themselves. what I did was. 1. the first line of code in the out fcn is uiwait; 2. when i pushed the last button to say OK in my callback i wrote all my output variables to my handles. and saved the handles. then typed uiresume. You can probably do some of this part in the output fcn and save some lines of code. varargout{1}.source = handles.source; varargout{1}.product = handles.product; varargout{1}.y_product = handles.y_product; varargout{1}.datapath = handles.datapath; varargout{1}.filename = handles.filename; varargout{1}.host = handles.host; varargout{1}.user = handles.user; varargout{1}.password = handles.password; varargout{1}.port = handles.port; varargout{1}.version = handles.version; varargout{1}.grid = handles.grid; handles.output1 = varargout; guidata(handles.figure1,handles); uiresume; 3. The program now goes through the remaining lines of text in the output fnc. Except the handles revert back to default handles. after getting the original handles back I set my varargout to what i wanted and closed the GUI. handles = guihandles; handles = guidata(handles.figure1); varargout = handles.output1; closereq; the program will now output the variables you placed into varargout. enjoy! -Dan
From: Ramesh Narasimhan on 19 Jan 2006 23:07
Nice work. I have actually gotten it to work with the uiwait in theooutput function by using uiwait(fig#), and closing the figure. uiresume should work just as well (as you have shown). one difference between our methods is that i am not using the handles to hold the data. i am just setting the varargout{#} directly equal to the variable I want to pass back. I can set my varargout in the function that my desired variable to pass gets created, and then when uiwait is released (either by destroying the figure, or probably as well by using uiresume), it knows to pass varargout, where it contains my desired output variables. i am not quite sure why they go through the using of the handles structure, though there may be a good reason i have not realizd yet. but passing the variables directly into varargout may avoid the problem of the handles resetting. the handles probably are not "resetting", but rather outputFcn is being called as soon as the gui is opened, so that at time the handles it is getting in its original call are the original handles. maybe varargout is more dynamic. |