Thread Subject: Passing handles between GUIs via a loaded file

Subject: Passing handles between GUIs via a loaded file

From: William

Date: 6 Oct, 2008 06:46:01

Message: 1 of 3

Hi,

I have a GUI with pulldown menus and editable text boxes. I am trying to save the configuration of all the editable text boxes and pulldown menus to a file that can be loaded the next time the user wants to use the GUI.

I can run the GUI properly if I start from scratch(All of the handles operate normally). The problem is, when I rerun the GUI and load in the configuration file, I get an 'Invalid handle object' error. Does anyone know a way to do this?

Currently, I am saving the handles structure from the previously open GUI into the configuration file. I then reopen the GUI and load in the saved configuration file. When the file is loaded, I am copying over the handles structure from the previously opened GUI. I noticed that some of the numbers change slightly between the two handles (i.e. checkbox3 goes from 320.0040 to 320.0039). Could this be causing the problem?

Please let me know if you know a way to save the configuration and data of a GUI into a config file that can be loaded back into the GUI so the user can pick up where he/she left off.

Thanks!!

Bill King

Subject: Passing handles between GUIs via a loaded file

From: Steven Lord

Date: 6 Oct, 2008 13:33:59

Message: 2 of 3


"William " <w_king10@yahoo.com> wrote in message
news:gccc79$d4l$1@fred.mathworks.com...
> Hi,
>
> I have a GUI with pulldown menus and editable text boxes. I am trying to
> save the configuration of all the editable text boxes and pulldown menus
> to a file that can be loaded the next time the user wants to use the GUI.
>
> I can run the GUI properly if I start from scratch(All of the handles
> operate normally). The problem is, when I rerun the GUI and load in the
> configuration file, I get an 'Invalid handle object' error. Does anyone
> know a way to do this?
>
> Currently, I am saving the handles structure from the previously open GUI
> into the configuration file. I then reopen the GUI and load in the saved
> configuration file. When the file is loaded, I am copying over the
> handles structure from the previously opened GUI. I noticed that some of
> the numbers change slightly between the two handles (i.e. checkbox3 goes
> from 320.0040 to 320.0039). Could this be causing the problem?

I don't believe we state anywhere in the documentation that when a Handle
Graphics object is saved to a FIG-file and reloaded its handle will remain
the same. Therefore I don't think you should make that assumption.
Instead, I'd key off the Tag property of the objects -- save the appropriate
data in a struct, then store those structs as fields of a main struct, with
the Tag of the object being the fieldname in the main struct.

For instance, if the main struct is saveddata, then saveddata.Pushbutton1
would be a struct containing the saved data for the object whose Tag is
Pushbutton1.

To restore the state, take advantage of the fact that this two-input form of
SET works:

    SET(H,a) where a is a structure whose field names are object
    property names, sets the properties named in each field name
    with the values contained in the structure.

set(handles.Pushbutton1, saveddata.Pushbutton1)

--
Steve Lord
slord@mathworks.com

Subject: Passing handles between GUIs via a loaded file

From: William

Date: 7 Oct, 2008 03:32:01

Message: 3 of 3

Hi Steve,

Thanks for the quick reply! Am I correct in thinking that the way to save the entire handles structure of a pop-up menu is with:

myStruct.popupmenu1 = get(handles.popupmenu1);

I have now saved each handles structure for all of the components of my GUI. The problem I am seeing now, is that when I use the command:

set(handles.popupmenu1,myStruct.popupmenu1);

I get the following error:

Error using ==> set
Attempt to modify read-only uicontrol property: 'BeingDeleted'.

Is there something I need to disable to be able to copy the entire handles structure for each GUI component?

I also want to add that during the opening function of my main GUI, I copy the entire handles structure into a new structure called hFig_main (hFig_main = handles;). I have two other GUIs which work along this one and they use the handles structures hFig_plot and hFig_output. In my main GUI, the code above is actually:

myStruct.popupmenu1 = get(hFig_main.popupmenu1); and
set(hFig_main.popupmenu1,myStruct.popupmenu1);

Will this cause additional issues with copying the handles from each component. My initial assumption is that it shouldn't cause issues. I have been wrong many times before, however!

Thanks again for your help!!

Respectfully,
Bill King

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
struct William 6 Oct, 2008 23:35:05
get William 6 Oct, 2008 23:35:05
set William 6 Oct, 2008 23:35:05
configuration William 6 Oct, 2008 02:50:19
handles William 6 Oct, 2008 02:50:19
gui William 6 Oct, 2008 02:50:19
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com