I’m trying to use optionMenus using formLayout’s attachPosition flag, but the display is incorrect.
Incorrect display:
Once you re-size the window manually, it then snaps to the correct display.
Correct display:
Does anybody knows a way to get the correct display when the window first opens?
Thanks in advance!
import maya.cmds as mc
class RunLayout(object):
WINDOW_NAME = "fsExampleUi"
def __init__(self):
self.deleteLayout()
self.title = 'Example Window'
self.win = mc.window(self.WINDOW_NAME, widthHeight=(400, 100), title=self.title, resizeToFitChildren=True)
formLayout_A = mc.formLayout()
#Divisions int fields
#U int fields
self.intField_U = {"A": mc.intField(minValue=1, maxValue=100, value=1),
"B": mc.intField(minValue=1, maxValue=100, value=1),
"C": mc.intField(minValue=1, maxValue=100, value=1),
"D": mc.intField(minValue=1, maxValue=100, value=1),
"E": mc.intField(minValue=1, maxValue=100, value=1),
"F": mc.intField(minValue=1, maxValue=100, value=1)}
#V int fields
self.intField_V = {"A": mc.intField(minValue=1, maxValue=100, value=1),
"B": mc.intField(minValue=1, maxValue=100, value=1),
"C": mc.intField(minValue=1, maxValue=100, value=1),
"D": mc.intField(minValue=1, maxValue=100, value=1),
"E": mc.intField(minValue=1, maxValue=100, value=1),
"F": mc.intField(minValue=1, maxValue=100, value=1)}
#Choose optionMenus
self.optionMenuSh = {"A": mc.optionMenu('OPTIONMENUA', w=51, parent=formLayout_A)}
mc.menuItem(label='Corner')
mc.menuItem(label='Cube')
mc.menuItem(label='Prism')
mc.menuItem(label='Locator')
self.optionMenuSh["B"] = mc.optionMenu('OPTIONMENUB', w=51, parent=formLayout_A)
mc.menuItem(label='Corner')
mc.menuItem(label='Cube')
mc.menuItem(label='Prism')
mc.menuItem(label='Locator')
self.optionMenuSh["C"] = mc.optionMenu('OPTIONMENUC', w=51, parent=formLayout_A)
mc.menuItem(label='Corner')
mc.menuItem(label='Cube')
mc.menuItem(label='Prism')
mc.menuItem(label='Locator')
self.optionMenuSh["D"] = mc.optionMenu('OPTIONMENUD', w=51, parent=formLayout_A)
mc.menuItem(label='Corner')
mc.menuItem(label='Cube')
mc.menuItem(label='Prism')
mc.menuItem(label='Locator')
self.optionMenuSh["E"] = mc.optionMenu('OPTIONMENUE', w=51, parent=formLayout_A)
mc.menuItem(label='Corner')
mc.menuItem(label='Cube')
mc.menuItem(label='Prism')
mc.menuItem(label='Locator')
self.optionMenuSh["F"] = mc.optionMenu('OPTIONMENUF', w=51, parent=formLayout_A)
mc.menuItem(label='Corner')
mc.menuItem(label='Cube')
mc.menuItem(label='Prism')
mc.menuItem(label='Locator')
#Apply button
button_A = mc.button(label='Apply', parent=formLayout_A)
#EDITS
#Attach to formLayout_A
mc.formLayout(formLayout_A, edit=True,
#Controls: intField_U_A, B, C, D, E, F - U&V
attachForm=
[
(self.intField_U["A"], 'left', 3), (self.intField_U["A"], 'top', 3),
(self.intField_U["B"], 'top', 5),
(self.intField_U["C"], 'top', 5),
(self.intField_U["D"], 'top', 5),
(self.intField_U["E"], 'top', 5),
(self.intField_U["F"], 'top', 5),
#v
(self.intField_V["A"], 'left', 3),
#enum
#(self.optionMenuSh["A"], 'left', 0)
],
#Controls: intField_V_A, B, C, D, E, F
attachControl=
[
(self.intField_V["A"], 'top', 14, self.intField_U["A"]),
(self.intField_V["B"], 'top', 14, self.intField_U["A"]),
(self.intField_V["C"], 'top', 14, self.intField_U["A"]),
(self.intField_V["D"], 'top', 14, self.intField_U["A"]),
(self.intField_V["E"], 'top', 14, self.intField_U["A"]),
(self.intField_V["F"], 'top', 14, self.intField_U["A"]),
#enum
(self.optionMenuSh["A"], 'top', 5, self.intField_V["A"]),
(self.optionMenuSh["B"], 'top', 5, self.intField_V["A"]),
(self.optionMenuSh["C"], 'top', 5, self.intField_V["A"]),
(self.optionMenuSh["D"], 'top', 5, self.intField_V["A"]),
(self.optionMenuSh["E"], 'top', 5, self.intField_V["A"]),
(self.optionMenuSh["F"], 'top', 5, self.intField_V["A"]),
(button_A, 'top', 45, self.optionMenuSh["F"])
],
#Controls: intField_U_A, B, C, D, E, F - U&V
attachPosition=
[
(self.intField_U["A"], 'right', 5, 16.667),
(self.intField_U["B"], 'left', 5, 16.667), (self.intField_U["B"], 'right', 5, 33.333),
(self.intField_U["C"], 'left', 5, 33.333), (self.intField_U["C"], 'right', 5, 50),
(self.intField_U["D"], 'left', 5, 50), (self.intField_U["D"], 'right', 5, 66.667),
(self.intField_U["E"], 'left', 5, 66.667), (self.intField_U["E"], 'right', 5, 83.333),
(self.intField_U["F"], 'left', 5, 83.333), (self.intField_U["F"], 'right', 5, 100),
#V
(self.intField_V["A"], 'right', 5, 16.667),
(self.intField_V["B"], 'left', 5, 16.667), (self.intField_V["B"], 'right', 5, 33.333),
(self.intField_V["C"], 'left', 5, 33.333), (self.intField_V["C"], 'right', 5, 50),
(self.intField_V["D"], 'left', 5, 50), (self.intField_V["D"], 'right', 5, 66.667),
(self.intField_V["E"], 'left', 5, 66.667), (self.intField_V["E"], 'right', 5, 83.333),
(self.intField_V["F"], 'left', 5, 83.333), (self.intField_V["F"], 'right', 5, 100),
#enum
(self.optionMenuSh["A"], 'left', 4, 0), (self.optionMenuSh["A"], 'right', 5, 16.667),
(self.optionMenuSh["B"], 'left', 4, 16.667), (self.optionMenuSh["B"], 'right', 5, 33.333),
(self.optionMenuSh["C"], 'left', 4, 33.333), (self.optionMenuSh["C"], 'right', 5, 50),
(self.optionMenuSh["D"], 'left', 4, 50), (self.optionMenuSh["D"], 'right', 5, 66.667),
(self.optionMenuSh["E"], 'left', 4, 66.667), (self.optionMenuSh["E"], 'right', 5, 83.333),
(self.optionMenuSh["F"], 'left', 4, 83.333), (self.optionMenuSh["F"], 'right', 5, 100),
(button_A, 'left', 5, 33.333), (button_A, 'right', 5, 66.667)
])
#Show window
mc.showWindow(self.win)
def deleteLayout(self):
if mc.window(self.WINDOW_NAME, exists=True):
mc.deleteUI(self.WINDOW_NAME, window=True)
def showLayout(self):
self.deleteLayout()
tmpInstance = RunLayout()