Python - Change the textField after browsing - MAY

2019-06-14 14:30发布

I've got the most annoying problem with my GUI Exporter in Maya. I've made the textField etc. work, but I can't change the value of the textField after it's created, which is what I need to do.

What I want to do for example is, let's say the filepath is none from the beginning. The textField has now printed out: "None" in it, but after you press browse and select a directory, I want it to change None to the directory path etc.

That's the only problem I currently have and the error code received is this:

Error: RuntimeError: file C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\internal\pmcmds.py line 134: Too many children in layout: rowLayout3 #

Code:

#Setup the window using the returned window

def setupWindow(self, new_window):
    try:
        frame_layout = pm.frameLayout(labelVisible = False, marginWidth = 5, marginHeight = 5)
        pm.columnLayout(w = 350, h = 300)            

        pm.text(label = "Filepath: ")

        self.textField = pm.textField("FieldNorm", text = "%s" % self.filePath, editable = False, w = 350, h = 20)            

        pm.button(label = "Browse", w = 100, h = 20, command = self.browse)
        pm.rowLayout(numberOfColumns = 2, adjustableColumn = 1, w = 350, h = 25)
        pm.button(label = "Export", w = 200, h = 25, command = self.export)
        pm.button(label = "Close", w = 100, h = 25, command = pm.Callback(self.closeButton, new_window))
    except:
        print "<Setting up window failed>"

#Show the returned window        
def showWindow(self, new_window):
    if new_window is not None:
        pm.showWindow(new_window)
    else:
        print "<Window does not exist!>"

#Browse Directory and Paste into textField        
def browse(self, filePath):
    self.filePath = pm.fileDialog2(dialogStyle = 2, returnFilter = 1, fileFilter = "*.obj")

    if self.filePath is not None:
        self.textField = pm.textField("FieldNorm", text = "%s" % self.filePath, editable = False, w = 350, h = 20)
    else:
        print "<No changes has been made!>"

2条回答
smile是对你的礼貌
2楼-- · 2019-06-14 15:06

The error means you are adding a new control, probably to the rowlayout at the end of the setupWindow function which holds the two buttons - Maya thinks you're adding a third

If you want to update the contents of self.textfield in the browse functions, you want

   pm.textField(self.textField, e=True, text = "%s" % self.filePath, editable = False, w = 350, h = 20)

which will edit the already created field. The line in the example

    self.textField = pm.textField("FieldNorm", text = "%s" % self.filePath, editable = False, w = 350, h = 20)

is trying to create a new one, as @julianMann points out

查看更多
女痞
3楼-- · 2019-06-14 15:09

Looks like you need the edit flag in the pm.textField line in browse()

pm.textField("FieldNorm", edit=True, text = "%s" % self.filePath)
查看更多
登录 后发表回答