Simple UI erroring on the 3rd push button.

442 views
Skip to first unread message

jettam

unread,
Oct 23, 2017, 12:24:42 AM10/23/17
to Python Programming for Autodesk Maya
I am building a UI that has three pushButtons, each pushButton calls an external Module. In theory they should all be wired the same. But on the third button I get this error.  
BTW  That 3rd module has two arguments like this: def randomlyPlace(stairs=10,birds=10):  

# Error: PySide2.QtCore.QObject.connect(): not enough arguments
# Traceback (most recent call last):
#   File "<maya console>", line 5, in <module>
#   File "E:\ProfessionalDevelopment\python\Introduction to Python Scripting in Maya\cgcircuitPython\wk6\wk6_homeWorkUI.py", line 26, in run
#     win = GeometryGenerator(parent=getMayaWindow())
#   File "E:\ProfessionalDevelopment\python\Introduction to Python Scripting in Maya\cgcircuitPython\wk6\wk6_homeWorkUI.py", line 70, in __init__
#     self.makeConnections()
#   File "E:\ProfessionalDevelopment\python\Introduction to Python Scripting in Maya\cgcircuitPython\wk6\wk6_homeWorkUI.py", line 82, in makeConnections
#     self.Pbtn_randomlyDistribute.connect(self.randomlyPlaceA)
# TypeError: PySide2.QtCore.QObject.connect(): not enough arguments #

Here is the Code.
# Loading a Qt Designer UI file and editing the loaded widget

import os
import functools
from PySide2 import QtWidgets, QtCore, QtUiTools, QtGui
from shiboken2 import wrapInstance
import maya.cmds as mc
import maya.OpenMayaUI as omui
import makeRobotBug, makeSpiralStairs, randomlyPlace
'''
import thisModule
reload (thisModule)
thisModule.run()
'''
def getMayaWindow():
    ''' pointer to the maya main window '''
    ptr = omui.MQtUtil.mainWindow()
    if ptr:
        return wrapInstance(long(ptr), QtWidgets.QMainWindow)

def run():
    ''' builds our UI '''
    global win
    win = GeometryGenerator(parent=getMayaWindow())
    #win.show()

class GeometryGenerator(QtWidgets.QDialog):

    def __init__(self,parent=None):
        super(GeometryGenerator,self).__init__(parent)

        #self.resize(400, 300)

        ##  From Pysideuic compiled code goes here
        #############################################################
        self.gridLayout = QtWidgets.QGridLayout()

        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setContentsMargins(5, 5, 5, 5)

        self.verticalLayout_3 = QtWidgets.QVBoxLayout()
        self.verticalLayout_3.setContentsMargins(5, 5, 5, 5)
        self.Pbtn_makeRobot = QtWidgets.QPushButton("MAKE ROBOT")
        self.verticalLayout_3.addWidget(self.Pbtn_makeRobot)

        self.verticalLayout.addLayout(self.verticalLayout_3)

        self.verticalLayout_4 = QtWidgets.QVBoxLayout()
        self.verticalLayout_4.setContentsMargins(5, 5, 5, 5)
        self.Pbtn_makeStairs = QtWidgets.QPushButton("MAKE STAIRS")
        self.verticalLayout_4.addWidget(self.Pbtn_makeStairs)
        self.verticalLayout.addLayout(self.verticalLayout_4)
        self.verticalLayout_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout_2.setContentsMargins(5, 5, 5, 5)
        self.Pbtn_randomlyDistribute = QtWidgets.QPushButton("Randomly Place Robot and Spiral Staircase")
        self.verticalLayout_2.addWidget(self.Pbtn_randomlyDistribute)
       
        self.verticalLayout.addLayout(self.verticalLayout_2)

        self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
        ##############################################################

        self.setWindowTitle("WIN CONTROLLED IN PYTHON")
        self.setLayout(self.gridLayout)
        self.show()
        self.makeConnections()
        self.initialUiState()

    def initialUiState(self):
        self.Pbtn_makeRobot.toggle()
        self.Pbtn_makeStairs.toggle()
        self.Pbtn_randomlyDistribute.toggle()

    def makeConnections(self):
        ''' connect events in out UI '''
        self.Pbtn_makeRobot.clicked.connect( self.makeRobotBug )
        self.Pbtn_makeStairs.clicked.connect(self.makeSpiralStairs)
        self.Pbtn_randomlyDistribute.connect(self.randomlyPlaceA)

    def makeRobotBug(self):
        makeRobotBug.makeRobotBug()

    def makeSpiralStairs(self):
        makeSpiralStairs.makeSpiralStairs()

    def randomlyPlaceA(self):
        randomlyPlace.randomlyPlace()








            



Neil Roche

unread,
Oct 23, 2017, 9:15:48 AM10/23/17
to Python Programming for Autodesk Maya
You haven't added the signal clicked.

It should be:   

self.Pbtn_randomlyDistribute.clicked.connect(self.randomlyPlaceA)

Marcus Ottosson

unread,
Oct 23, 2017, 9:55:55 AM10/23/17
to python_in...@googlegroups.com

The way you can spot it, is by (1) looking at the error message..

# TypeError: PySide2.QtCore.QObject.connect(): not enough arguments #

..followed by (2) going to the docs for that object and method..

And you’ll find that indeed, it takes more than a single argument, and the first argument is of type QObject.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/711d1f24-94ce-472a-adb7-1e1944db51e9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

jettam

unread,
Oct 23, 2017, 11:59:06 AM10/23/17
to Python Programming for Autodesk Maya
Thanks Neil, it was a typo on my part, thanks for pointing it out. 

jettam

unread,
Oct 23, 2017, 12:18:23 PM10/23/17
to Python Programming for Autodesk Maya
I have since discovered that I had left out the signal .clicked 
I wish I could understand these docs better. But even now after I realize what the problem was, reading these docs again didn't bring me any closer to the answer.  Where is the line in the docs that should have alerted me to what I needed to do ?

Neil Roche

unread,
Oct 23, 2017, 12:37:44 PM10/23/17
to Python Programming for Autodesk Maya
I use this one as it is in Python whereas the other link is C++ so it's not so easy to read unless you are familiar with it.


Or this one which has a lot of examples:



Reply all
Reply to author
Forward
0 new messages