Python-浏览后更改textField-MAYA [英] Python - Change the textField after browsing - MAYA
问题描述
我在Maya中的GUI导出器遇到了最烦人的问题.我已经使textField等工作了,但是在创建textField之后,我无法更改它的值,这是我需要做的.
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.
例如,我想做的是,假设文件路径从一开始就没有.现在,textField已打印出来:"None",但是在按浏览并选择目录后,我希望它将None更改为目录路径等.
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:
代码:
#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!>"
推荐答案
该错误表示您正在添加一个新控件,可能是在setupWindow函数末尾的行布局中,该控件包含两个按钮-Maya认为您正在添加三分之一
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
如果要在浏览功能中更新self.textfield的内容,则需要
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)
正尝试创建一个新的,如@julianMann指出的
is trying to create a new one, as @julianMann points out
这篇关于Python-浏览后更改textField-MAYA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!