Feedback

What's your question?

By: Asked

Add/Remove frameLayouts in a window using MEL

How would one go about adding/removing frameLayouts from a window in MEL?

I have a window with "add" and "remove" buttons at the top, and I want the user to be able to add/remove frameLayouts in the area below the buttons as needed.

Is this difficult to do or is there a better way of doing this?

Add comment viewed 455 times Latest activity 7 months ago

or Cancel

1 answer

  • 0

julian [ Admin ]

You can have have an add button to add frames, and then have each frame contain its own remove button.

// make a unique window containing a form that contains a button to add new frames,
// and a columnLayout to contain the frames.
// The columnLayout is contained in a scrollLayout to handle overflow.
// the button is declared after the columnLayout because it has to pass the 
// columnLayout name to the addAFrame procedure

global proc addRemoveFrames() {


    if (`window -q -exists addRemoveFramesWindow`) deleteUI addRemoveFramesWindow;
    string $win = `window   -wh 200 600 -t ("Add & Remove Frames") addRemoveFramesWindow `;
    string $form = `formLayout `; // whole form

    string $scroll = `scrollLayout -cr 1 ` ;
    string $columnLayout = `columnLayout -adj 1 -cat "both" 2`;
    setParent  $form;


    string  $addButton = `symbolButton 
        -image "setEdAddCmd.xpm" 
        -height 24 -width 24    
        -c  ("addAFrame "+ $columnLayout)`;

    setParent  $form;


    formLayout -edit
        -attachForm     $addButton "top"     5
        -attachForm     $addButton "left"  5
        -attachNone     $addButton "right"  
        -attachNone     $addButton "bottom"  

        -attachControl  $scroll  "top" 5    $addButton
        -attachForm     $scroll "right"     5
        -attachForm     $scroll "left"  5
        -attachForm     $scroll "bottom"  5 
    $form   ;


    showWindow $win;

}



// set the columnLayout as the parent and make a new frameLayout in it.
// set the label to the time it was created so we can see that
// the correct frame gets deleted when the remove button is pressed

global proc addAFrame(string $columnLayout) {
    setParent $columnLayout;
    string $timeNow = `about -currentTime`;
    string $frameLayout = `frameLayout -cll 1 -cl 0 -l $timeNow`;
    button -l "Remove Me" -c ("deleteUI " + $frameLayout);
}
NN comments
spamkill
-

Thanks Julian! This works way better than what I’ve beem messing with, which is hiding the frameLayouts with -enable 0, but I have to reset all the fields and checkboxes in the frameLayout or when you “add” (unhide) them the data is still there.

julian
-

Yeah, if you want clean frames best to delete and remake them. I have some code somewhere for reordering too – just little arrow buttons to shift the frames up and down y one slot. I wonder if its possible to implement drag and drop to reorder layouts… that could be cool.

julian
-

Yeah, if you want clean frames best to delete and remake them. I have some code somewhere for reordering too – just little arrow buttons to shift the frames up and down by one slot. I wonder if its possible to implement drag and drop to reorder layouts… that could be cool.

or Cancel