如何在我的PySide(Maya)脚本中解决“对非序列的迭代”问题

时间:2019-03-30 15:06:06

标签: python pyqt pyside maya

我正在尝试让Maya的PySide Ui查看不同的代码示例,但是我的代码不起作用, 问题是我正在

#Traceback (most recent call last):
#   File "maya console", line 69, in <module>
#   File "maya console", line 32, in create
#   File "maya console", line 61, in __init__
#   File "maya console", line 65, in set_items
# TypeError: iteration over non-sequence # 

我读到的有关该错误的主题很少,当人们尝试遍历实例时似乎是一个问题,但是由于我仍然缺乏对面向对象编程的了解,因此我很困惑为什么它会在脚本中发生。

from PySide2 import QtGui, QtCore, QtWidgets
from shiboken2 import wrapInstance

import maya.OpenMaya as om
import maya.OpenMayaUI as omui
import maya.cmds as cmds
import os, functools

def getMayaWindow():
    pointer = omui.MQtUtil.mainWindow()
    if pointer is not None:
        return wrapInstance(long(pointer), QtWidgets.QWidget)

class testUi():
    def __init__(self):
        self.window = 'vl_test'
        self.title = 'Test Remastered'
        self.size = (1000, 650)

    def create(self):
        if cmds.window(self.window, exists=True):
            cmds.deleteUI(self.window, window=True)

        self.parentWindow = getMayaWindow()
        self.mainWindow = QtWidgets.QMainWindow(self.parentWindow)
        self.mainWindow.setObjectName(self.window)
        self.mainWindow.setWindowTitle(self.title)

        self.mainWidget = QtWidgets.QWidget()
        self.mainWindow.setCentralWidget(self.mainWidget)
        self.mainLayout = QtWidgets.QFormLayout(self.mainWidget)
        testIk = test(self)
        self.mainLayout.addWidget(testIk)

        self.mainButton = QtWidgets.QPushButton()
        self.mainLayout.addWidget(self.mainButton)
        self.mainButton.clicked.connect(partial(self.load_selected))

        self.mainWindow.show()    



class test():
    def __init__(self, maya_transform_nodes=[]):
        qWid = QtWidgets.QWidget()
        self.setMinW = qWid.setMinimumWidth(300)
        self.setMinH = qWid.setMinimumHeight(300)
        self.sss = qWid.setStyleSheet("border:1px solid rgb(0, 255, 0);")
        self.items = []

        self.transform_move = QtGui.QTransform()
        self.transform_scale = QtGui.QTransform()

        self.prev_mouse_pos = QtCore.QPoint(0, 0)

        self.color = QtGui.QColor(0, 255, 50, 50)
        self.clicked_color = QtGui.QColor(0, 255, 50, 150)
        self.right_clicked_color = QtGui.QColor(255, 0, 0, 150)

        if maya_transform_nodes:
            self.set_items(maya_transform_nodes)


    def set_items(self, maya_transform_nodes):
        for path in maya_transform_nodes:
            print path

v = testUi()
v.create()

预期结果将是-我得到window,按钮不起作用,并且是在test()中编写的小部件。

1 个答案:

答案 0 :(得分:1)

testUi.create中,您拥有:

testIk = test(self)

但是self只是testUi的类实例。它是一个类,而不是列表。但是它正在maya_transform_nodes中以test的形式传递,这需要一个列表或其他可迭代对象。因此,可以将其传递给列表(或其他可迭代),或删除参数并将其默认设置为[]