2015-09-09 26 views
0

我試圖從PySide進口* 從pymel進口選擇一個對象,並顯示行編輯Pymel類型錯誤:文件<瑪雅控制檯>

*
進口pymel.core爲PM 進口maya.cmds作爲CMDS 進口maya.mel如梅爾 進口maya.OpenMaya作爲OpenMaya

def select_obj(obj): 
    list = pm.poly 
print obj 

button = QPushButton("select") 
button.clicked.connect(select_obj) 
button.show() 

def desselect_obj(obj): 
    list = OpenMaya.MSelection() 
print obj 

button2 = QPushButton("disconnect") 
button2.clicked.connect(select_obj) 
button2.show() 


edit = QLineEdit(nome) 
QLineEdit.show(select_obj) 
label.show() 

app.exec_() 

# Error: line 1: TypeError: file <maya console> line 25: 'PySide.QtGui.QLineEdit' called with wrong argument types: 
    PySide.QtGui.QLineEdit(function) 
Supported signatures: 
    PySide.QtGui.QLineEdit(PySide.QtGui.QWidget = No`enter code here`ne) 
    PySide.QtGui.QLineEdit(unicode, PySide.QtGui.QWidget = None) # 
# TypeError: select_obj() takes exactly 1 argument (0 given) 
+0

此代碼真的沒有任何意義,你可以發佈更正的版本? – Achayan

回答

1

您的代碼有很多的問題。你不需要導入那麼多模塊(特別是那些未被使用的模塊)。通常,在使用PySide創建UI時,您可以環繞從QWidgetQMainWindow繼承的類。看看下面的代碼,這是一個帶有按鈕和lineEdit的窗口的簡單例子。當你按下按鈕時,它會將所選對象的名稱添加到lineEdit。

from PySide import QtGui, QtCore 
import maya.cmds as cmds 

class Window(QtGui.QWidget): 
    def __init__(self, parent = None): 
     super(Window, self).__init__(parent) # Inherit from QWidget 

     # Create button 
     self.button = QtGui.QPushButton("select") 
     self.button.clicked.connect(self.select_obj) 

     # Create line edit 
     self.edit = QtGui.QLineEdit() 

     # Create widget's layout 
     mainLayout = QtGui.QVBoxLayout() 
     mainLayout.addWidget(self.button) 
     mainLayout.addWidget(self.edit) 
     self.setLayout(mainLayout) 

     # Resize widget, and show it 
     self.resize(200, 200) 
     self.show() 

    # Function to add selected object to QLineEdit 
    def select_obj(self): 
     sel = cmds.ls(sl = True) # Get selection 
     if sel: 
      self.edit.setText(sel[0]) # Set object's name to the lineEdit 

win = Window() # Create instance of the class 
相關問題