0

I'm trying to select an object and display the line edit

from PySide import * from pymel import *
import pymel.core as pm import maya.cmds as cmds import maya.mel as mel import maya.OpenMaya as 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)

1 Answers1

1

Your code has a lot of issues. You don't need to import that many modules (especially ones that are being unused). Typically when creating a ui with PySide, you wrap around a class that inherits from a QWidget or QMainWindow. Have a look at the following code, it's a simple example of a window with a button and lineEdit. When you push the button it will add the selected object's name to the 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
Green Cell
  • 4,677
  • 2
  • 18
  • 49