Editing UI Layout

155 views
Skip to first unread message

John Pepper

unread,
May 24, 2014, 6:38:04 PM5/24/14
to python_in...@googlegroups.com
Hello, everyone

I'm kind of new here, and I'm learning scripting in Maya. I'm trying to create a UI with the Create Node Menu on the left and the Node Editor on the right. For the most part, I have the script done, but the problem is how it turns out - the menus are really small and I can't seem to fix them. Can anyone help me with this. Here's the script:

import maya.cmds as cmds
class TextureUploaderUI(object):
    def __init__(self):
        self.winName = "PSD_In"
       
        if cmds.window(self.winName, exists=True):
            cmds.deleteUI(self.winName, window=True)
        self.window = cmds.window(self.winName, title="Texture Upload", resizeToFitChildren=True)
        mainLayout = cmds.rowLayout(numberOfColumns=2, columnWidth = [(1, 100), (2, 500)] )
        col1Layout = cmds.columnLayout(adj=True, rowSpacing=10, columnWidth=250)
        cmds.scriptedPanel(type="createNodePanel", label="Select Material")
        cmds.setParent(mainLayout)
        col2Layout = cmds.columnLayout(adj=True)
        cmds.scriptedPanel(type="nodeEditorPanel", label="Texture Editor")
        cmds.setParent(mainLayout)
        #cmds.formLayout(form, e=True, af=[(p,s,0) for s in ("top","bottom","left","right")])
        #commandBTN = cmds.button(label="Create!", c=self.makeSpans)
           
        cmds.showWindow(self.window)
   
TextureUploaderUI()


Run it in Maya and see for yourself. Thanks.


Justin Israel

unread,
May 25, 2014, 7:00:21 AM5/25/14
to python_in...@googlegroups.com
Hey John,

As is common with writing native Maya UI code, the solution is a bit hard to spot. Your layout lacks an attachment definition for the widgets in the rowLayout. So it means that while your createNodePanel is being placed into the 1st horizontal cell, it is not having any constraints being applied to its height. You can add a rowLayout edit at the end of your definitions to configure how the specific widgets should be constrained. In my example I have removed the column layouts, since they didn't make much different here. And I have also included a commented-out alternative, using the paneLayout, which gives you a splitter control between the two widgets:

import maya.cmds as cmds
class TextureUploaderUI(object):
    def __init__(self):
        self.winName = "PSD_In"

        if cmds.window(self.winName, exists=True):
            cmds.deleteUI(self.winName, window=True
)

        self.window = cmds.window(self.winName, title="Texture Upload")

        mainLayout = cmds.rowLayout(numberOfColumns=2, columnWidth=[(1, 200), (2, 500)])
        # mainLayout = cmds.paneLayout(configuration='vertical2')


        cmds.scriptedPanel(type="createNodePanel", label="Select Material"
)
        cmds.setParent(mainLayout)

        cmds.scriptedPanel(type="nodeEditorPanel", label="Texture Editor")
        cmds.setParent(mainLayout)

        cmds.rowLayout(mainLayout, e=True, rowAttach=(1, "both", 0))
        # cmds.paneLayout(mainLayout, e=True, paneSize=(1, 15, 100))

        cmds.showWindow(self.window)

TextureUploaderUI()
-- justin
Reply all
Reply to author
Forward
0 new messages