[Maya / Python] FormLayout AttachControl - Can someone clarify how to use it?

The documentation is lacking and I need some clarification.

AttachControl - [string, string, int, string]
Arguments are: control, edge, offset, control Valid edge values are: “top” | “bottom” | “left” | “right”. Attach a control to another control.

This is an example, please tell me why it is wrong. I have button_top that goes on top, button_mid that goes underneath button_top, and button_bottom that goes underneath button_mid.

If I wanted to have them resize vertically with the layout while residing on the right side, it should look something like…


cmds.formLayout(layout, e = 1, attachForm = [
					(btn_top, "right", 0), (btn_top, "top", 0),
					(btn_mid, "right", 0),
					(btn_bottom, "right", 0), (btn_bottom, "bottom", 0)],
				attachControl = [
					(btn_top, "bottom", 0, btn_mid),
					(btn_mid, "top", 0, btn_top), (btn_mid, "bottom", 0, btn_bottom)
					])

Am I confusing the order for the parameters, parent control A to control B, so (controlA, “bottom”, 0, controlB) should parent the bottom of… controlA or B to the other? I don’t understand.

So when attaching two controls to each other, you only want to attach them once.


cmds.formLayout(layout, e = 1, attachForm = [
					(btn_top, "right", 0), (btn_top, "top", 0),
					(btn_mid, "right", 0),
					(btn_bottom, "right", 0), (btn_bottom, "bottom", 0)],
				attachControl = [
					(btn_top, "bottom", 0, btn_mid),
					(btn_mid, "bottom", 0, btn_bottom)
					])

So if you notice, btn_top is attached to btn_mid, and then btn_mid is attaching to btn_bottom.
Before you basically had an attach cycle where btn_top was hooked to btn_mid, but then btn_mid was also hooked to btn_top.

Hopefully that makes sense.

ah formlayout… the most powerful and least accessible of them all…

[QUOTE=R.White;29408]So when attaching two controls to each other, you only want to attach them once.


cmds.formLayout(layout, e = 1, attachForm = [
					(btn_top, "right", 0), (btn_top, "top", 0),
					(btn_mid, "right", 0),
					(btn_bottom, "right", 0), (btn_bottom, "bottom", 0)],
				attachControl = [
					(btn_top, "bottom", 0, btn_mid),
					(btn_mid, "bottom", 0, btn_bottom)
					])

So if you notice, btn_top is attached to btn_mid, and then btn_mid is attaching to btn_bottom.
Before you basically had an attach cycle where btn_top was hooked to btn_mid, but then btn_mid was also hooked to btn_top.

Hopefully that makes sense.[/QUOTE]

Thanks, that helps but I might be asking the wrong question then.

Basically I have a pane layout, and in the first pane there is a formlayout containing a scroll list attached to the top and bottom and left of the formlayout, then on the right there is 4 buttons, I’m trying to make it so that these buttons resize with the form layout, however currently only a single button will while the three others keep their size.

cmds.formLayout(layout_sets, e = 1, attachForm = [
					(sets_sl, "left", 0), (sets_sl, "bottom", 0), (sets_sl, "top", 0),
					(sets_btn_add, "right", 0), (sets_btn_add, "top", 0),
					(sets_btn_del, "right", 0),
					(sets_btn_up, "right", 0),
					(sets_btn_dn, "right", 0), (sets_btn_dn, "bottom", 0)],
				attachControl = [
					(sets_sl, "right", 0, sets_btn_add),
					(sets_btn_add, "bottom", 0, sets_btn_del),
					(sets_btn_del, "bottom", 0, sets_btn_up),
					(sets_btn_up, "bottom", 0, sets_btn_dn)])

This is how it looks at the moment, you can see the + button is huge but the others don’t resize. (click to enlarge)


It seems incredibly unintuitive, I’ve used qt with c++ a bit and it’s incredibly powerful, this doesn’t feel like qt at all… darn it AD.

I think in this case you want to put the buttons into a layout of their own and then resize that. Something like:


OuterForm
  Data  <- attach to form left, top, bottom
  Buttons <- attach to form right, top, bottom and left to Data
      Button1 < Buttons (left, top, bottom)
      Button2 < Buttons(top, bottom),  Button1 (Left)
      Button3 < Buttons(top, bottom),  Button2 (Left)
      Button4 < Buttons(top, bottom, right),  Button3 (Left)

… or, with MGui


import mGui.gui as gui 
import mGui.forms as forms

with gui.Window('test') as w:
    with forms.HorizontalStretchForm('main_split'):
        gui.TextScrollList(None, width=256)
        with forms.VerticalStretchForm('buttons', width=72) :
            gui.Button("button_1")
            gui.Button("button_2")
            gui.Button("button_3")
            gui.Button("button_4")

w.show()


The code for the forms.Form class is her: https://github.com/theodox/mGui/blob/master/mGui/forms.py the different named forms just use different mixes of of the methods in there

[QUOTE=Theodox;29413]I think in this case you want to put the buttons into a layout of their own and then resize that. Something like:


OuterForm
  Data  <- attach to form left, top, bottom
  Buttons <- attach to form right, top, bottom and left to Data
      Button1 < Buttons (left, top, bottom)
      Button2 < Buttons(top, bottom),  Button1 (Left)
      Button3 < Buttons(top, bottom),  Button2 (Left)
      Button4 < Buttons(top, bottom, right),  Button3 (Left)

[/QUOTE]

Just to confirm that example is for a horizontal layout?

I gave it a go but it doesn’t work, only one button ever resizes. It appears that if I attach button A’s bottom to the top of button B, button A’s bottom will resize if button B moves, however button B’s top wont resize if button A moves.

Getting a bit frustrated at this, it can’t be that uncommon to have your buttons fit into their layout.

I did it as a horizontal, yes, just swap top/bottom for left/right. Sorry i did it without looking at the graphic.

For this application you can also use attachPosition for the buttons, that will pin them to a % of the way across the inner form.

[QUOTE=Theodox;29416]I did it as a horizontal, yes, just swap top/bottom for left/right. Sorry i did it without looking at the graphic.

For this application you can also use attachPosition for the buttons, that will pin them to a % of the way across the inner form.[/QUOTE]

Ah thank you so much! /solved

attachPosition = [
	(sets_btn_add, "top", 0, 0), (sets_btn_add, "bottom", 0, 25),
	(sets_btn_del, "top", 0, 25), (sets_btn_del, "bottom", 0, 50),
	(sets_btn_up, "top", 0, 50), (sets_btn_up, "bottom", 0, 75),
	(sets_btn_dn, "top", 0, 75), (sets_btn_dn, "bottom", 0, 100)]